Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

type-gen.js 2.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. // @ts-check
  2. /*
  3. This script will generate TypeScript content for the code editor. It inlines
  4. the content of several files into one large string which can be passed to the
  5. Monaco editor as an extraLib.
  6. Important notes:
  7. - Files must include the "Start Copy Here" comment indicated below.
  8. - This comment must be placed BELOW any import statements.
  9. Run the script with `yarn scripts`.
  10. */
  11. const fs = require('fs/promises')
  12. const root = process.cwd()
  13. async function inlineFileContents(path) {
  14. console.log(`📄 Inlining contents of ${path}`)
  15. const text = await fs.readFile(`${root}${path}`, 'utf-8')
  16. return text
  17. .match(
  18. /\/\* ----------------- Start Copy Here ---------------- \*\/(.|\n)*$/g
  19. )[0]
  20. .replaceAll('/* ----------------- Start Copy Here ---------------- */', '')
  21. .replaceAll('export default', '')
  22. .replaceAll('export ', '')
  23. }
  24. async function copyTypesToFile() {
  25. console.log('⚙️ Generating types-import.ts')
  26. const content =
  27. `
  28. // HEY! DO NOT MODIFY THIS FILE. THE CONTENTS OF THIS FILE
  29. // ARE AUTO-GENERATED BY A SCRIPT AT: /scripts/type-gen.js
  30. // ANY CHANGES WILL BE LOST WHEN THE SCRIPT RUNS AGAIN!
  31. export default {` +
  32. `
  33. name: "types.ts",
  34. content: \`
  35. ${await inlineFileContents('/types.ts')}
  36. ${await inlineFileContents('/utils/vec.ts')}
  37. ${await inlineFileContents('/state/code/utils.ts')}
  38. ${await inlineFileContents('/state/code/index.ts')}
  39. ${await inlineFileContents('/state/code/dot.ts')}
  40. ${await inlineFileContents('/state/code/ellipse.ts')}
  41. ${await inlineFileContents('/state/code/line.ts')}
  42. ${await inlineFileContents('/state/code/polyline.ts')}
  43. ${await inlineFileContents('/state/code/ray.ts')}
  44. ${await inlineFileContents('/state/code/arrow.ts')}
  45. ${await inlineFileContents('/state/code/draw.ts')}
  46. ${await inlineFileContents('/state/code/rectangle.ts')}
  47. ${await inlineFileContents('/state/code/control.ts')}
  48. declare const controls: {[key:string]: any} = {}
  49. \`}`
  50. await fs.writeFile(
  51. __dirname + '/../components/code-panel/types-import.ts',
  52. content
  53. )
  54. console.log('✅ Process complete')
  55. }
  56. // Kickoff
  57. copyTypesToFile()