dts.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. `/// <reference path="../node_modules/monaco-editor-core/monaco.d.ts" />`,
  21. ``,
  22. `declare namespace monaco.languages.typescript {`
  23. ];
  24. for (let line of lines) {
  25. if (/^import/.test(line)) {
  26. continue;
  27. }
  28. if (line === 'export {};') {
  29. continue;
  30. }
  31. line = line.replace(/ /g, '\t');
  32. line = line.replace(/declare /g, '');
  33. if (line.length > 0) {
  34. line = `\t${line}`;
  35. result.push(line);
  36. }
  37. }
  38. result.push(`}`);
  39. result.push(``);
  40. fs.writeFileSync(DST_PATH, result.join('\n'));