Skip to content

Commit d801bc2

Browse files
committed
Adds a quick migration script
1 parent 374a335 commit d801bc2

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

README.md

+8
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,14 @@ To test:
2525
npm run test
2626
```
2727

28+
To deploy:
29+
30+
```sh
31+
npm run migrate
32+
```
33+
34+
The script will look in for a clone of the TypeScript repo in "../TypeScript", or "./TypeScript" to move the generated files in.
35+
2836
## Contribution Guidelines
2937

3038
The `dom.generated.d.ts`, `webworker.generated.d.ts` and `dom.iterable.generated.d.ts` files from the TypeScript repo are used as baselines.

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
"fetch-mdn": "npm run build && node ./lib/mdnfetcher.js",
88
"fetch": "echo This could take a few minutes... && npm run fetch-idl && npm run fetch-mdn",
99
"baseline-accept": "cpx \"generated\\*\" baselines\\",
10-
"test": "tsc -p ./tsconfig.json && node ./lib/index.js && node ./lib/test.js"
10+
"test": "tsc -p ./tsconfig.json && node ./lib/index.js && node ./lib/test.js",
11+
"migrate": "node ./lib/migrate-to-tsc.js"
1112
},
1213
"dependencies": {
1314
"@types/jsdom": "^16.2.4",

src/migrate-to-tsc.ts

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Mainly a quick script to migrate the generated files into the
2+
// lib folder of a TypeScript clone.
3+
//
4+
// node ./lib/migrate-to-tsc.js [optional/file/path/to/tsc]
5+
6+
import { existsSync, readdirSync, readFileSync, writeFileSync } from "fs"
7+
import { join } from "path"
8+
9+
const maybeTSWorkingDir = [process.argv[2], "../TypeScript", "TypeScript"]
10+
const tscWD = maybeTSWorkingDir.find(wd => existsSync(wd))
11+
12+
if (!tscWD) throw new Error("Could not find a TypeScript clone to put the generated files in.")
13+
14+
const generatedFiles = readdirSync("generated")
15+
generatedFiles.forEach(file => {
16+
const contents = readFileSync(join("generated", file) , "utf8")
17+
const newFilePath = join(tscWD, "lib", file.replace(".generated", ""))
18+
writeFileSync(newFilePath, contents)
19+
})
20+
21+
console.log(`Moved ${generatedFiles.map(f => f.replace(".generated", "")).join(", ")} to '${tscWD}'.`)

0 commit comments

Comments
 (0)