1 | const chalk = require("chalk");
|
2 | const { error } = require("simple-output");
|
3 | const log = require("./utils/log");
|
4 | const { promisify } = require("util");
|
5 | const { resolve } = require("path");
|
6 | const { readFileSync, writeFile } = require("fs");
|
7 | const execAsync = promisify(require("child_process").exec);
|
8 | const execSync = require("child_process").execSync;
|
9 | const writeFileAsync = promisify(writeFile);
|
10 |
|
11 | (async function main() {
|
12 | try {
|
13 | await Promise.all([
|
14 | log(() =>
|
15 | execAsync(
|
16 | `${resolve("node_modules/typescript/bin/tsc")} --project tsconfig.types.json`
|
17 | ).then(() => "Typescript definitions created")
|
18 | ),
|
19 | log(() =>
|
20 | writeFileAsync(
|
21 | resolve("dist/common.d.ts"),
|
22 | readFileSync(resolve("src/common.d.ts"))
|
23 | .toString()
|
24 | .split("\n")
|
25 | .filter(s => s && !s.includes('types="react-scripts"'))
|
26 | .join("\n")
|
27 | ).then(() => "Common definitions created")
|
28 | )
|
29 | ]);
|
30 |
|
31 | const indexdtsPath = resolve("dist/index.d.ts");
|
32 | log(() =>
|
33 | writeFileAsync(
|
34 | indexdtsPath,
|
35 | `/// <reference path="common.d.ts" />\n\n${readFileSync(indexdtsPath).toString()}`
|
36 | ).then(() => `Overwritten ${chalk.cyan(indexdtsPath)}`)
|
37 | );
|
38 |
|
39 | log(() =>
|
40 | writeFileAsync(
|
41 | resolve("dist/tsconfig.json"),
|
42 | JSON.stringify(
|
43 | {
|
44 | extends: "../tsconfig.json",
|
45 | include: ["*.d.ts"],
|
46 | compilerOptions: {
|
47 | typeRoots: [
|
48 | "node_modules/@types",
|
49 | "../node_modules/@types",
|
50 | "../../@types",
|
51 | "../../../@types",
|
52 | "node_modules/@h74-types",
|
53 | "../node_modules/@h74-types",
|
54 | "../../@h74-types",
|
55 | "../../../@h74-types",
|
56 | "../typings"
|
57 | ]
|
58 | }
|
59 | },
|
60 | null,
|
61 | 2
|
62 | )
|
63 | ).then(() => `Generated ${chalk.cyan("tsconfig.json")}`)
|
64 | );
|
65 | } catch (e) {
|
66 | error(e.stdout ? e.stdout.toString() : e);
|
67 | process.exit(1);
|
68 | }
|
69 | })();
|