|
1 | | -import fs from "fs-extra"; |
2 | | -import path from "path"; |
3 | | -import glob from "glob"; |
4 | | -import url from "url"; |
5 | | - |
6 | | -const __filename = url.fileURLToPath(new URL(import.meta.url)); |
7 | | -const __dirname = path.dirname(__filename); |
8 | | - |
9 | | -const root = path.join(__dirname, ".."); |
10 | | -const source = path.join(root, "built/local"); |
11 | | -const dest = path.join(root, "lib"); |
12 | | - |
13 | | -async function produceLKG() { |
14 | | - console.log(`Building LKG from ${source} to ${dest}`); |
15 | | - await copyLibFiles(); |
16 | | - await copyLocalizedDiagnostics(); |
17 | | - await copyTypesMap(); |
18 | | - await copyScriptOutputs(); |
19 | | - await copyDeclarationOutputs(); |
20 | | - await writeGitAttributes(); |
21 | | -} |
22 | | - |
23 | | -async function copyLibFiles() { |
24 | | - await copyFilesWithGlob("lib?(.*).d.ts"); |
25 | | -} |
26 | | - |
27 | | -async function copyLocalizedDiagnostics() { |
28 | | - const dir = await fs.readdir(source); |
29 | | - const ignoredFolders = ["enu"]; |
30 | | - |
31 | | - // TODO(jakebailey): Instead of ignoring folders, we should keep a list of |
32 | | - // the localizationTargets somewhere that can be used by multiple modules. |
33 | | - ignoredFolders.push( |
34 | | - "compiler", |
35 | | - "deprecatedCompat", |
36 | | - "executeCommandLine", |
37 | | - "harness", |
38 | | - "jsTyping", |
39 | | - "loggedIO", |
40 | | - "server", |
41 | | - "services", |
42 | | - "testRunner", |
43 | | - "tsc", |
44 | | - "tsserver", |
45 | | - "tsserverlibrary", |
46 | | - "typescript", |
47 | | - "typingsInstaller", |
48 | | - "typingsInstallerCore", |
49 | | - "webServer", |
50 | | - ); |
51 | | - |
52 | | - for (const d of dir) { |
53 | | - const fileName = path.join(source, d); |
54 | | - if ( |
55 | | - fs.statSync(fileName).isDirectory() && |
56 | | - ignoredFolders.indexOf(d) < 0 |
57 | | - ) { |
58 | | - await fs.copy(fileName, path.join(dest, d)); |
59 | | - } |
60 | | - } |
61 | | -} |
62 | | - |
63 | | -async function copyTypesMap() { |
64 | | - await copyFromBuiltLocal("typesMap.json"); // Cannot accommodate copyright header |
65 | | -} |
66 | | - |
67 | | -async function copyScriptOutputs() { |
68 | | - await copyFromBuiltLocal("cancellationToken.js"); |
69 | | - await copyFromBuiltLocal("tsc.js"); |
70 | | - await copyFromBuiltLocal("tsserver.js"); |
71 | | - await copyFromBuiltLocal("tsserverlibrary.js"); |
72 | | - await copyFromBuiltLocal("typescript.js"); |
73 | | - await copyFromBuiltLocal("typingsInstaller.js"); |
74 | | - await copyFromBuiltLocal("watchGuard.js"); |
75 | | -} |
76 | | - |
77 | | -async function copyDeclarationOutputs() { |
78 | | - await copyFromBuiltLocal("tsserverlibrary.d.ts"); |
79 | | - await copyFromBuiltLocal("typescript.d.ts"); |
80 | | -} |
81 | | - |
82 | | -async function writeGitAttributes() { |
83 | | - await fs.writeFile(path.join(dest, ".gitattributes"), `* text eol=lf`, "utf-8"); |
84 | | -} |
85 | | - |
86 | | -/** |
87 | | - * @param {string} fileName |
88 | | - */ |
89 | | -async function copyFromBuiltLocal(fileName) { |
90 | | - await fs.copy(path.join(source, fileName), path.join(dest, fileName)); |
91 | | -} |
92 | | - |
93 | | -/** |
94 | | - * @param {string} pattern |
95 | | - */ |
96 | | -async function copyFilesWithGlob(pattern) { |
97 | | - const files = glob.sync(pattern, { cwd: source }).map(f => path.basename(f)); |
98 | | - for (const f of files) { |
99 | | - await copyFromBuiltLocal(f); |
100 | | - } |
101 | | - console.log(`Copied ${files.length} files matching pattern ${pattern}`); |
102 | | -} |
103 | | - |
104 | | -process.on("unhandledRejection", err => { |
105 | | - throw err; |
106 | | -}); |
107 | | -produceLKG().then(() => console.log("Done"), err => { |
108 | | - throw err; |
109 | | -}); |
| 1 | +import fs from "fs-extra"; |
| 2 | +import path from "path"; |
| 3 | +import glob from "glob"; |
| 4 | +import url from "url"; |
| 5 | +import del from "del"; |
| 6 | + |
| 7 | +const __filename = url.fileURLToPath(new URL(import.meta.url)); |
| 8 | +const __dirname = path.dirname(__filename); |
| 9 | + |
| 10 | +const root = path.join(__dirname, ".."); |
| 11 | +const source = path.join(root, "built/local"); |
| 12 | +const dest = path.join(root, "lib"); |
| 13 | + |
| 14 | +async function produceLKG() { |
| 15 | + console.log(`Building LKG from ${source} to ${dest}`); |
| 16 | + await del(`${dest.replace(/\\/g, "/")}/**`, { ignore: ["**/README.md"] }); |
| 17 | + await fs.mkdirp(dest); |
| 18 | + await copyLibFiles(); |
| 19 | + await copyLocalizedDiagnostics(); |
| 20 | + await copyTypesMap(); |
| 21 | + await copyScriptOutputs(); |
| 22 | + await copyDeclarationOutputs(); |
| 23 | + await writeGitAttributes(); |
| 24 | +} |
| 25 | + |
| 26 | +async function copyLibFiles() { |
| 27 | + await copyFilesWithGlob("lib?(.*).d.ts"); |
| 28 | +} |
| 29 | + |
| 30 | +async function copyLocalizedDiagnostics() { |
| 31 | + const dir = await fs.readdir(source); |
| 32 | + const ignoredFolders = ["enu"]; |
| 33 | + |
| 34 | + // TODO(jakebailey): Instead of ignoring folders, we should keep a list of |
| 35 | + // the localizationTargets somewhere that can be used by multiple modules. |
| 36 | + ignoredFolders.push( |
| 37 | + "compiler", |
| 38 | + "deprecatedCompat", |
| 39 | + "executeCommandLine", |
| 40 | + "harness", |
| 41 | + "jsTyping", |
| 42 | + "loggedIO", |
| 43 | + "server", |
| 44 | + "services", |
| 45 | + "testRunner", |
| 46 | + "tsc", |
| 47 | + "tsserver", |
| 48 | + "tsserverlibrary", |
| 49 | + "typescript", |
| 50 | + "typingsInstaller", |
| 51 | + "typingsInstallerCore", |
| 52 | + "webServer", |
| 53 | + ); |
| 54 | + |
| 55 | + for (const d of dir) { |
| 56 | + const fileName = path.join(source, d); |
| 57 | + if ( |
| 58 | + fs.statSync(fileName).isDirectory() && |
| 59 | + ignoredFolders.indexOf(d) < 0 |
| 60 | + ) { |
| 61 | + await fs.copy(fileName, path.join(dest, d)); |
| 62 | + } |
| 63 | + } |
| 64 | +} |
| 65 | + |
| 66 | +async function copyTypesMap() { |
| 67 | + await copyFromBuiltLocal("typesMap.json"); // Cannot accommodate copyright header |
| 68 | +} |
| 69 | + |
| 70 | +async function copyScriptOutputs() { |
| 71 | + await copyFromBuiltLocal("cancellationToken.js"); |
| 72 | + await copyFromBuiltLocal("tsc.js"); |
| 73 | + await copyFromBuiltLocal("tsserver.js"); |
| 74 | + await copyFromBuiltLocal("tsserverlibrary.js"); |
| 75 | + await copyFromBuiltLocal("typescript.js"); |
| 76 | + await copyFromBuiltLocal("typingsInstaller.js"); |
| 77 | + await copyFromBuiltLocal("watchGuard.js"); |
| 78 | +} |
| 79 | + |
| 80 | +async function copyDeclarationOutputs() { |
| 81 | + await copyFromBuiltLocal("tsserverlibrary.d.ts"); |
| 82 | + await copyFromBuiltLocal("typescript.d.ts"); |
| 83 | +} |
| 84 | + |
| 85 | +async function writeGitAttributes() { |
| 86 | + await fs.writeFile(path.join(dest, ".gitattributes"), `* text eol=lf`, "utf-8"); |
| 87 | +} |
| 88 | + |
| 89 | +/** |
| 90 | + * @param {string} fileName |
| 91 | + */ |
| 92 | +async function copyFromBuiltLocal(fileName) { |
| 93 | + await fs.copy(path.join(source, fileName), path.join(dest, fileName)); |
| 94 | +} |
| 95 | + |
| 96 | +/** |
| 97 | + * @param {string} pattern |
| 98 | + */ |
| 99 | +async function copyFilesWithGlob(pattern) { |
| 100 | + const files = glob.sync(pattern, { cwd: source }).map(f => path.basename(f)); |
| 101 | + for (const f of files) { |
| 102 | + await copyFromBuiltLocal(f); |
| 103 | + } |
| 104 | + console.log(`Copied ${files.length} files matching pattern ${pattern}`); |
| 105 | +} |
| 106 | + |
| 107 | +process.on("unhandledRejection", err => { |
| 108 | + throw err; |
| 109 | +}); |
| 110 | +produceLKG().then(() => console.log("Done"), err => { |
| 111 | + throw err; |
| 112 | +}); |
0 commit comments