Skip to content

Commit

Permalink
Adds a quick migration script
Browse files Browse the repository at this point in the history
  • Loading branch information
orta committed Dec 21, 2020
1 parent 374a335 commit d801bc2
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
21 changes: 21 additions & 0 deletions src/migrate-to-tsc.ts
Original file line number Diff line number Diff line change
@@ -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}'.`)

0 comments on commit d801bc2

Please sign in to comment.