-
Notifications
You must be signed in to change notification settings - Fork 69
/
Copy pathindex.ts
101 lines (91 loc) · 2.42 KB
/
index.ts
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import fs from "fs-extra";
import cluster from "cluster";
import chalk from "chalk";
import {
FixCommandCliArgs,
ConvertCommandCliArgs,
SetupCommandCliArgs,
} from "./cli/arguments";
import { parseCommands } from "./cli/yargs";
import { logger } from "./runner/logger";
import { runPrimaryAsync } from "./runner/run-primary-async";
import { runWorkerAsync } from "./runner/run-worker-async";
import { runSetupCommand } from "./runner/run-setup-command";
import { componentPropChecks } from "./fix/component-prop-checks";
import { autoSuppressErrors } from "./fix/suppressions/auto-suppress";
import { removeUnusedErrors } from "./fix/suppressions/remove-unused";
import { generateReport } from "./fix/generate-report";
import { autoImport } from "./fix/auto-import";
import { fixTypeExports } from "./fix/fix-type-exports";
import { getFixState } from "./fix/state";
if (cluster.isMaster) {
logger.log();
logger.log(chalk.underline.bgBlue("Stripe Flow to TypeScript Codemod"));
logger.log();
}
/**
* Run the setup command
* Different flags enable different setup scripts
*/
const setup = async (argv: SetupCommandCliArgs) => {
if (argv.silent) {
logger.disable();
}
await runSetupCommand(argv);
};
/**
* Run the Flow -> TS conversion
* Files are converted in batches in parallel processes
*/
const convert = async (argv: ConvertCommandCliArgs) => {
if (argv.silent) {
logger.disable();
}
for (const p of argv.path) {
if (!fs.existsSync(p)) {
logger.error(`Provided path ${p} does not exist.`);
process.exit(1);
}
}
if (cluster.isMaster) {
runPrimaryAsync(argv).catch((error) => {
logger.error(error);
process.exit(1);
});
} else {
runWorkerAsync(argv).catch((error) => {
logger.error(error);
process.exit(1);
});
}
};
/**
* Fix and report TS errors after conversion
*/
const fix = async (argv: FixCommandCliArgs) => {
if (argv.silent) {
logger.disable();
}
const state = getFixState(argv);
// Read only
if (argv.tsProps) {
await componentPropChecks(state);
}
if (argv.generateReport) {
generateReport(state);
}
// Modifies files
if (argv.removeUnused) {
await removeUnusedErrors(state);
}
if (argv.autoSuppressErrors) {
await autoSuppressErrors(state);
}
if (argv.autoImport) {
await autoImport(state);
}
if (argv.fixTypeExports) {
await fixTypeExports(state);
}
};
parseCommands(convert, fix, setup);