forked from microsoft/TypeScript-DOM-lib-generator
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmigrate.js
More file actions
42 lines (34 loc) · 1.22 KB
/
Copy pathmigrate.js
File metadata and controls
42 lines (34 loc) · 1.22 KB
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
32
33
34
35
36
37
38
39
40
41
42
// @ts-check
// Mainly a quick script to migrate the generated files into the
// lib folder of a TypeScript clone.
//
// node ./deploy/migrate.js [optional/file/path/to/tsc]
import { existsSync, readdirSync, readFileSync, writeFileSync } from "fs";
import { join } from "path";
import { postProcessDTSFiles } from "./createTypesPackages.js";
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.")
);
const generatedDir = new URL("../generated/", import.meta.url);
postProcessDTSFiles(
/** @type {any} */
({ files: filesToSend.map((f) => ({ to: f })) }),
generatedDir
);
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'.`
);