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

type-gen.js 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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('```', '\\`\\`\\`')
  22. .replaceAll('export default', '')
  23. .replaceAll('export ', '')
  24. .replaceAll('vec.', 'Vec.')
  25. }
  26. async function copyTypesToFile() {
  27. console.log('⚙️ Generating types-import.ts')
  28. const content =
  29. `
  30. /* eslint-disable */
  31. // HEY! DO NOT MODIFY THIS FILE. THE CONTENTS OF THIS FILE
  32. // ARE AUTO-GENERATED BY A SCRIPT AT: /scripts/type-gen.js
  33. // ANY CHANGES WILL BE LOST WHEN THE SCRIPT RUNS AGAIN!
  34. export default {` +
  35. `
  36. name: "types.ts",
  37. content: \`
  38. type DeepPartial<T> = {
  39. [P in keyof T]?: DeepPartial<T[P]>;
  40. };
  41. ${await inlineFileContents('/types.ts')}
  42. ${await inlineFileContents('/types.ts')}
  43. ${await inlineFileContents('/utils/vec.ts')}
  44. ${await inlineFileContents('/state/code/utils.ts')}
  45. ${await inlineFileContents('/state/code/index.ts')}
  46. ${await inlineFileContents('/state/code/dot.ts')}
  47. ${await inlineFileContents('/state/code/ellipse.ts')}
  48. ${await inlineFileContents('/state/code/line.ts')}
  49. ${await inlineFileContents('/state/code/polyline.ts')}
  50. ${await inlineFileContents('/state/code/ray.ts')}
  51. ${await inlineFileContents('/state/code/arrow.ts')}
  52. ${await inlineFileContents('/state/code/draw.ts')}
  53. ${await inlineFileContents('/state/code/text.ts')}
  54. ${await inlineFileContents('/state/code/rectangle.ts')}
  55. ${await inlineFileContents('/state/code/control.ts')}
  56. const codeShapes = new Set<CodeShape<any>>()
  57. const controls: Record<string, any> = {}
  58. const defaultStyle: ShapeStyles = {
  59. color: ColorStyle.Black,
  60. size: SizeStyle.Medium,
  61. isFilled: false,
  62. dash: DashStyle.Solid,
  63. }
  64. const uniqueId = () => ''
  65. const codeControls = new Set([])
  66. declare function createShape(type: ShapeType, shape: Shape): any
  67. declare function getShapeUtils<T>(shape: T): any
  68. declare function getOrderedShapes(): CodeShape<any>[]
  69. \`}`
  70. await fs.writeFile(
  71. __dirname + '/../components/code-panel/types-import.ts',
  72. content
  73. )
  74. console.log('✅ Process complete')
  75. }
  76. // Kickoff
  77. copyTypesToFile()