-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
83 lines (75 loc) · 2 KB
/
main.js
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
/* Ensure that promises which reject and are not caught cause errors. */
import './catchUnhandledRejections';
import {
error,
} from 'colorful-logging';
import {
create,
} from './create';
import {
getDirectory,
} from './functions/getDirectory';
import {
getInputNouns,
} from './functions/getInputNouns';
import program from 'commander';
import * as path from 'path';
import {
newAsset,
} from './new';
const pkg = require('./package.json');
program.version(pkg.version, '-v, -V, --version');
program
.command('create <name> [directory]')
.description('Create a new Accelerator story.')
.action(async (name, dirArg) =>
{
const dirPath = path.join(getDirectory(dirArg), name);
try {
await create(name, dirPath);
} catch (err) {
error(err);
process.exit(1);
}
});
program
.command('new <type> <name> [directory]')
.description('Create a new asset in an existing Accelerator story. ' +
`Available subcommands are: ${getInputNouns().join(', ')}.`)
.option(
'-j, --javascript',
'Generate JavaScript code files instead of TypeScript files for the new ' +
'asset.',
).option(
'-c, --css',
'Generate CSS style files instead of Sass files.',
).option(
'--no-css-modules',
'Do not use CSS Modules with the generated style files.',
).option(
'--no-tests',
'Do not generate tests for this asset.',
).action(async (type, name, dirArg, cmd) =>
{
try {
await newAsset({
name,
type,
directory: getDirectory(dirArg),
forceCss: Boolean(cmd.css),
forceJavaScript: Boolean(cmd.javascript),
noCssModules: Boolean(cmd.noCssModules),
noTests: Boolean(cmd.noTests),
});
} catch (err) {
error(err);
process.exit(1);
}
});
program
.option('-h')
.action(program.outputHelp)
program.parse(process.argv);
if (!program.args.length) {
program.outputHelp();
}