-
Notifications
You must be signed in to change notification settings - Fork 67
/
cli.ts
66 lines (59 loc) · 1.52 KB
/
cli.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
#!/usr/bin/env node
import { program } from 'commander';
import * as fs from 'fs-extra';
import type { JSONSchemaForNPMPackageJsonFiles as PackageJson } from '@schemastore/package';
import createModularApp from './';
// this is a bit gross - but there's no better way of doing this.
const verbose = process.argv.includes('--verbose');
interface Options {
repo: string;
preferOffline: string;
verbose: boolean;
empty: boolean;
}
program.version(
(
fs.readJsonSync(
require.resolve('create-modular-react-app/package.json'),
) as PackageJson
).version as string,
);
program.arguments('<name>');
program.option('--repo [value]', 'Should a repository be initialized', 'true');
program.option('--prefer-offline [value]', 'Yarn --prefer-offline', 'true');
program.option(
'--empty',
"Don't setup a modular app after creating the repository",
);
program.option('--verbose', 'Run yarn commands with --verbose set', 'false');
program.action(async (name: string, options: Options) => {
await createModularApp({
name,
preferOffline: options.preferOffline !== 'false',
repo: options.repo !== 'false',
verbose,
empty: options.empty,
}).catch((err) => {
if (verbose) {
console.error(err);
}
});
});
try {
void program
.parseAsync(process.argv)
.then(() => {
process.exit(0);
})
.catch((err) => {
if (verbose) {
console.error(err);
}
process.exit(1);
});
} catch (err) {
if (verbose) {
console.error(err);
}
process.exit(1);
}