|
| 1 | +/** |
| 2 | + * NODE_OPTIONS= node tsc.ignore.ts "tsc.ignore" tsconfig.json tsc.ignore.tsconfig.json |
| 3 | + */ |
| 4 | + |
| 5 | +import fs from "fs"; |
| 6 | + |
| 7 | +import ts from "typescript"; |
| 8 | + |
| 9 | +const th = (msg: string) => new Error(`tsc.ignore.ts error: ${msg}`); |
| 10 | + |
| 11 | +const args = process.argv.slice(2); |
| 12 | + |
| 13 | +const ignorefile = args[0]; |
| 14 | +const tsconfigfile = args[1]; |
| 15 | +const outputfile = args[2]; |
| 16 | + |
| 17 | +if (!fs.existsSync(ignorefile)) { |
| 18 | + throw th(`${ignorefile} doesn't exist`); |
| 19 | +} |
| 20 | + |
| 21 | +if (!fs.existsSync(tsconfigfile)) { |
| 22 | + throw th(`${tsconfigfile} doesn't exist`); |
| 23 | +} |
| 24 | + |
| 25 | +const fileContent = fs.readFileSync(ignorefile, "utf-8"); |
| 26 | + |
| 27 | +const exclude = fileContent |
| 28 | + .split("\n") |
| 29 | + .map((l) => l.trim()) |
| 30 | + .filter(Boolean) |
| 31 | + .filter((l) => !l.startsWith("#")); |
| 32 | + |
| 33 | +console.log(exclude); |
| 34 | + |
| 35 | +const tsconfigContent = fs.readFileSync(tsconfigfile, "utf-8"); |
| 36 | + |
| 37 | +const { config: tsconfigObj, error } = ts.parseConfigFileTextToJson(tsconfigfile, tsconfigContent); |
| 38 | + |
| 39 | +if (error) { |
| 40 | + throw th(`Error parsing ${tsconfigfile}: ${ts.flattenDiagnosticMessageText(error.messageText, "\n")}`); |
| 41 | +} |
| 42 | + |
| 43 | +tsconfigObj.exclude = exclude; |
| 44 | + |
| 45 | +fs.writeFileSync(outputfile, JSON.stringify(tsconfigObj, null, 2)); |
| 46 | + |
| 47 | +console.log(` |
| 48 | +
|
| 49 | +tsc.ignore.ts config generated at: ${outputfile}: |
| 50 | +${JSON.stringify(tsconfigObj, null, 2)} |
| 51 | +
|
| 52 | +`); |
0 commit comments