2021-06-23 22:32:21 +00:00
|
|
|
// @ts-check
|
|
|
|
|
|
|
|
/*
|
2021-06-25 10:28:52 +00:00
|
|
|
This script will generate TypeScript content for the code editor. It inlines
|
|
|
|
the content of several files into one large string which can be passed to the
|
|
|
|
Monaco editor as an extraLib.
|
2021-06-23 22:32:21 +00:00
|
|
|
|
2021-06-25 10:28:52 +00:00
|
|
|
Important notes:
|
|
|
|
|
|
|
|
- Files must include the "Start Copy Here" comment indicated below.
|
|
|
|
|
|
|
|
- This comment must be placed BELOW any import statements.
|
|
|
|
|
|
|
|
Run the script with `yarn scripts`.
|
2021-06-23 22:32:21 +00:00
|
|
|
*/
|
|
|
|
|
2021-06-23 22:33:36 +00:00
|
|
|
const fs = require('fs/promises')
|
2021-06-25 10:28:52 +00:00
|
|
|
const root = process.cwd()
|
|
|
|
|
|
|
|
async function inlineFileContents(path) {
|
|
|
|
console.log(`📄 Inlining contents of ${path}`)
|
|
|
|
const text = await fs.readFile(`${root}${path}`, 'utf-8')
|
|
|
|
return text
|
|
|
|
.match(
|
|
|
|
/\/\* ----------------- Start Copy Here ---------------- \*\/(.|\n)*$/g
|
|
|
|
)[0]
|
|
|
|
.replaceAll('/* ----------------- Start Copy Here ---------------- */', '')
|
2021-06-27 11:58:08 +00:00
|
|
|
.replaceAll('```', '\\`\\`\\`')
|
2021-06-25 10:28:52 +00:00
|
|
|
.replaceAll('export default', '')
|
|
|
|
.replaceAll('export ', '')
|
2021-06-25 12:09:53 +00:00
|
|
|
.replaceAll('vec.', 'Vec.')
|
2021-06-25 10:28:52 +00:00
|
|
|
}
|
2021-06-23 22:32:21 +00:00
|
|
|
|
|
|
|
async function copyTypesToFile() {
|
2021-06-25 10:28:52 +00:00
|
|
|
console.log('⚙️ Generating types-import.ts')
|
2021-06-23 22:33:36 +00:00
|
|
|
|
|
|
|
const content =
|
|
|
|
`
|
2021-06-25 12:09:53 +00:00
|
|
|
/* eslint-disable */
|
2021-06-23 22:32:21 +00:00
|
|
|
|
2021-06-25 12:09:53 +00:00
|
|
|
// HEY! DO NOT MODIFY THIS FILE. THE CONTENTS OF THIS FILE
|
|
|
|
// ARE AUTO-GENERATED BY A SCRIPT AT: /scripts/type-gen.js
|
|
|
|
// ANY CHANGES WILL BE LOST WHEN THE SCRIPT RUNS AGAIN!
|
|
|
|
|
|
|
|
export default {` +
|
2021-06-23 22:33:36 +00:00
|
|
|
`
|
2021-06-25 12:09:53 +00:00
|
|
|
name: "types.ts",
|
|
|
|
content: \`
|
|
|
|
|
|
|
|
type DeepPartial<T> = {
|
|
|
|
[P in keyof T]?: DeepPartial<T[P]>;
|
|
|
|
};
|
2021-06-25 10:28:52 +00:00
|
|
|
|
|
|
|
${await inlineFileContents('/types.ts')}
|
|
|
|
|
2021-06-27 11:58:08 +00:00
|
|
|
${await inlineFileContents('/types.ts')}
|
|
|
|
|
2021-06-25 10:28:52 +00:00
|
|
|
${await inlineFileContents('/utils/vec.ts')}
|
|
|
|
|
|
|
|
${await inlineFileContents('/state/code/utils.ts')}
|
|
|
|
|
|
|
|
${await inlineFileContents('/state/code/index.ts')}
|
|
|
|
|
|
|
|
${await inlineFileContents('/state/code/dot.ts')}
|
|
|
|
|
|
|
|
${await inlineFileContents('/state/code/ellipse.ts')}
|
|
|
|
|
|
|
|
${await inlineFileContents('/state/code/line.ts')}
|
|
|
|
|
|
|
|
${await inlineFileContents('/state/code/polyline.ts')}
|
|
|
|
|
|
|
|
${await inlineFileContents('/state/code/ray.ts')}
|
|
|
|
|
|
|
|
${await inlineFileContents('/state/code/arrow.ts')}
|
|
|
|
|
|
|
|
${await inlineFileContents('/state/code/draw.ts')}
|
|
|
|
|
2021-06-25 11:24:08 +00:00
|
|
|
${await inlineFileContents('/state/code/text.ts')}
|
|
|
|
|
2021-06-25 10:28:52 +00:00
|
|
|
${await inlineFileContents('/state/code/rectangle.ts')}
|
|
|
|
|
|
|
|
${await inlineFileContents('/state/code/control.ts')}
|
|
|
|
|
2021-06-25 12:09:53 +00:00
|
|
|
const codeShapes = new Set<CodeShape<any>>()
|
|
|
|
const controls: Record<string, any> = {}
|
|
|
|
const defaultStyle: ShapeStyles = {
|
|
|
|
color: ColorStyle.Black,
|
|
|
|
size: SizeStyle.Medium,
|
|
|
|
isFilled: false,
|
|
|
|
dash: DashStyle.Solid,
|
|
|
|
}
|
|
|
|
const uniqueId = () => ''
|
|
|
|
const codeControls = new Set([])
|
|
|
|
|
|
|
|
declare function createShape(type: ShapeType, shape: Shape): any
|
|
|
|
declare function getShapeUtils<T>(shape: T): any
|
|
|
|
declare function getOrderedShapes(): CodeShape<any>[]
|
|
|
|
|
2021-06-25 10:28:52 +00:00
|
|
|
\`}`
|
2021-06-23 22:32:21 +00:00
|
|
|
|
2021-06-23 22:33:36 +00:00
|
|
|
await fs.writeFile(
|
|
|
|
__dirname + '/../components/code-panel/types-import.ts',
|
|
|
|
content
|
|
|
|
)
|
2021-06-25 10:28:52 +00:00
|
|
|
|
|
|
|
console.log('✅ Process complete')
|
2021-06-23 22:32:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Kickoff
|
2021-06-23 22:33:36 +00:00
|
|
|
copyTypesToFile()
|