From d801bc23c3b24502f77cc94c0b0359948fd786a3 Mon Sep 17 00:00:00 2001 From: Orta Therox Date: Mon, 21 Dec 2020 18:18:02 +0000 Subject: [PATCH] Adds a quick migration script --- README.md | 8 ++++++++ package.json | 3 ++- src/migrate-to-tsc.ts | 21 +++++++++++++++++++++ 3 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 src/migrate-to-tsc.ts diff --git a/README.md b/README.md index 7777562e5..22b71aaf7 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,14 @@ To test: npm run test ``` +To deploy: + +```sh +npm run migrate +``` + +The script will look in for a clone of the TypeScript repo in "../TypeScript", or "./TypeScript" to move the generated files in. + ## Contribution Guidelines The `dom.generated.d.ts`, `webworker.generated.d.ts` and `dom.iterable.generated.d.ts` files from the TypeScript repo are used as baselines. diff --git a/package.json b/package.json index e23118bd8..1a309116d 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,8 @@ "fetch-mdn": "npm run build && node ./lib/mdnfetcher.js", "fetch": "echo This could take a few minutes... && npm run fetch-idl && npm run fetch-mdn", "baseline-accept": "cpx \"generated\\*\" baselines\\", - "test": "tsc -p ./tsconfig.json && node ./lib/index.js && node ./lib/test.js" + "test": "tsc -p ./tsconfig.json && node ./lib/index.js && node ./lib/test.js", + "migrate": "node ./lib/migrate-to-tsc.js" }, "dependencies": { "@types/jsdom": "^16.2.4", diff --git a/src/migrate-to-tsc.ts b/src/migrate-to-tsc.ts new file mode 100644 index 000000000..826f40473 --- /dev/null +++ b/src/migrate-to-tsc.ts @@ -0,0 +1,21 @@ +// Mainly a quick script to migrate the generated files into the +// lib folder of a TypeScript clone. +// +// node ./lib/migrate-to-tsc.js [optional/file/path/to/tsc] + +import { existsSync, readdirSync, readFileSync, writeFileSync } from "fs" +import { join } from "path" + +const maybeTSWorkingDir = [process.argv[2], "../TypeScript", "TypeScript"] +const tscWD = maybeTSWorkingDir.find(wd => existsSync(wd)) + +if (!tscWD) throw new Error("Could not find a TypeScript clone to put the generated files in.") + +const generatedFiles = readdirSync("generated") +generatedFiles.forEach(file => { + const contents = readFileSync(join("generated", file) , "utf8") + const newFilePath = join(tscWD, "lib", file.replace(".generated", "")) + writeFileSync(newFilePath, contents) +}) + +console.log(`Moved ${generatedFiles.map(f => f.replace(".generated", "")).join(", ")} to '${tscWD}'.`)