dts.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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
  11. .readFileSync(SRC_PATH)
  12. .toString()
  13. .split(/\r\n|\r|\n/);
  14. let result = [
  15. `/*---------------------------------------------------------------------------------------------`,
  16. ` * Copyright (c) Microsoft Corporation. All rights reserved.`,
  17. ` * Licensed under the MIT License. See License.txt in the project root for license information.`,
  18. ` *--------------------------------------------------------------------------------------------*/`,
  19. ``,
  20. `declare namespace monaco.languages.json {`,
  21. ``
  22. ];
  23. for (let line of lines) {
  24. if (/^import/.test(line)) {
  25. continue;
  26. }
  27. line = line.replace(/ /g, '\t');
  28. line = line.replace(/export declare/g, 'export');
  29. if (line.length > 0) {
  30. line = `\t${line}`;
  31. }
  32. result.push(line);
  33. }
  34. result.push(`}`);
  35. result.push(``);
  36. fs.writeFileSync(DST_PATH, result.join('\n'));