-
Notifications
You must be signed in to change notification settings - Fork 247
/
args.ts
141 lines (131 loc) · 3.71 KB
/
args.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
import meow from 'meow';
import { Package, UpdateNotifier } from 'update-notifier';
import { Runner, TypescriptStarterArgsOptions, validateName } from './utils';
export async function checkArgs(): Promise<TypescriptStarterArgsOptions> {
const cli = meow(
`
Usage
$ npx typescript-starter
Non-Interactive Usage
$ npx typescript-starter <project-name> [options]
Options
--appveyor include Appveyor for Windows CI
--description, -d package.json description
--dom include DOM type definitions
--node include node.js type definitions
--strict enable stricter type-checking
--travis include Travis CI configuration
--yarn use yarn (default: npm)
--no-circleci don't include CircleCI
--no-cspell don't include cspell
--no-editorconfig don't include .editorconfig
--no-functional don't enable eslint-plugin-functional
--no-install skip yarn/npm install
--no-vscode don't include VS Code debugging config
Non-Interactive Example
$ npx typescript-starter my-library -d 'do something, better'
`,
{
flags: {
appveyor: {
default: false,
type: 'boolean',
},
circleci: {
default: true,
type: 'boolean',
},
cspell: {
default: true,
type: 'boolean',
},
description: {
alias: 'd',
default: 'a typescript-starter project',
type: 'string',
},
dom: {
default: false,
type: 'boolean',
},
editorconfig: {
default: true,
type: 'boolean',
},
functional: {
default: true,
type: 'boolean',
},
install: {
default: true,
type: 'boolean',
},
node: {
default: false,
type: 'boolean',
},
strict: {
default: false,
type: 'boolean',
},
travis: {
default: false,
type: 'boolean',
},
vscode: {
default: true,
type: 'boolean',
},
yarn: {
default: false,
type: 'boolean',
},
},
}
);
const info = await new UpdateNotifier({
pkg: cli.pkg as Package,
}).fetchInfo();
if (info.type !== 'latest') {
// eslint-disable-next-line functional/no-throw-statement
throw new Error(`
Your version of typescript-starter is outdated.
Consider using 'npx typescript-starter' to always get the latest version.
`);
}
const version = cli.pkg.version as string;
const input = cli.input[0];
if (!input) {
/**
* No project-name provided, return to collect options in interactive mode.
* Note: we always return `install`, so --no-install always works
* (important for test performance).
*/
return {
install: cli.flags.install,
starterVersion: version,
};
}
const validOrMsg = validateName(input);
if (typeof validOrMsg === 'string') {
// eslint-disable-next-line functional/no-throw-statement
throw new Error(validOrMsg);
}
return {
appveyor: cli.flags.appveyor,
circleci: cli.flags.circleci,
cspell: cli.flags.cspell,
description: cli.flags.description,
domDefinitions: cli.flags.dom,
editorconfig: cli.flags.editorconfig,
functional: cli.flags.functional,
install: cli.flags.install,
nodeDefinitions: cli.flags.node,
projectName: input,
runner: cli.flags.yarn ? Runner.Yarn : Runner.Npm,
starterVersion: version,
strict: cli.flags.strict,
travis: cli.flags.travis,
vscode: cli.flags.vscode,
};
}