dts.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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. for (let line of lines) {
  23. if (/^import/.test(line)) {
  24. continue;
  25. }
  26. line = line.replace(/ /g, '\t');
  27. line = line.replace(/export declare/g, 'export');
  28. if (line.length > 0) {
  29. line = `\t${line}`;
  30. result.push(line);
  31. }
  32. }
  33. result.push(`}`);
  34. result.push(``);
  35. fs.writeFileSync(DST_PATH, result.join('\n'));