forked from microsoft/TypeScript-DOM-lib-generator
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmigrate.js
More file actions
31 lines (26 loc) · 994 Bytes
/
migrate.js
File metadata and controls
31 lines (26 loc) · 994 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// Mainly a quick script to migrate the generated files into the
// lib folder of a TypeScript clone.
//
// node ./lib/migrate.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");
const filesToSend = generatedFiles.filter(
(file) => file.includes("dom.") || file.includes("webworker.")
);
filesToSend.forEach((file) => {
const contents = readFileSync(join("generated", file), "utf8");
const newFilePath = join(tscWD, "src", "lib", file);
writeFileSync(newFilePath, contents);
});
console.log(
`Moved ${filesToSend
.map((f) => f.replace(".generated", ""))
.join(", ")} to '${tscWD}/src/lib'.`
);