dts.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. /*---------------------------------------------------------------------------------------------
  2. * Copyright (c) Microsoft Corporation. All rights reserved.
  3. * Licensed under the MIT License. See License.txt in the project root for license information.
  4. *--------------------------------------------------------------------------------------------*/
  5. const path = require('path');
  6. const fs = require('fs');
  7. const REPO_ROOT = path.join(__dirname, '../');
  8. const SRC_PATH = path.join(REPO_ROOT, 'out/amd/monaco.contribution.d.ts');
  9. const DST_PATH = path.join(REPO_ROOT, 'monaco.d.ts');
  10. const lines = fs.readFileSync(SRC_PATH).toString().split(/\r\n|\r|\n/);
  11. let result = [
  12. `/*---------------------------------------------------------------------------------------------`,
  13. ` * Copyright (c) Microsoft Corporation. All rights reserved.`,
  14. ` * Licensed under the MIT License. See License.txt in the project root for license information.`,
  15. ` *--------------------------------------------------------------------------------------------*/`,
  16. ``,
  17. `declare namespace monaco.languages.json {`,
  18. ``
  19. ];
  20. for (let line of lines) {
  21. if (/^import/.test(line)) {
  22. continue;
  23. }
  24. line = line.replace(/ /g, '\t');
  25. line = line.replace(/export declare/g, 'export');
  26. if (line.length > 0) {
  27. line = `\t${line}`;
  28. }
  29. result.push(line);
  30. }
  31. result.push(`}`);
  32. result.push(``);
  33. fs.writeFileSync(DST_PATH, result.join('\n'));