-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli.js
executable file
·186 lines (179 loc) · 6.14 KB
/
cli.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
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
#!/usr/bin/env node --max-old-space-size=6144
import console from "console-ansi";
import yargs from "yargs";
import { hideBin } from "yargs/helpers";
import { cosmiconfig } from "cosmiconfig";
import { commands, run } from "./index.js";
import { NAME, VERSION } from "./utils.js";
export const getConfig = async () => {
let cosmiconfigOptions = {};
try {
const result =
(await cosmiconfig(NAME, { searchStrategy: "global" }).search()) || {};
cosmiconfigOptions = result.config || {};
} catch (error) {
console.error(error);
process.exit(0);
}
return cosmiconfigOptions;
};
// CLI
const parser = yargs(hideBin(process.argv));
parser
.demandCommand(1)
.options({
cwd: {
group: "Input/meta options:",
type: "string",
describe: `Specify the current working directory for all commands.`,
defaultDescription: `process.cwd()`,
},
username: {
group: "Input/meta options:",
type: "string",
describe: `Specify a user name for the init command.`,
defaultDescription: `$ npm profile get name`,
},
gitHubUsername: {
group: "Input/meta options:",
type: "string",
describe: `Specify a GitHub user name for the init command. Default from current npm profile or scraped from profile page.`,
defaultDescription: `options.username`,
},
authorName: {
group: "Input/meta options:",
type: "string",
describe: `Specify an author name for the init command. Default from current npm profile or scraped from profile page.`,
defaultDescription: `$ npm profile get fullname`,
},
name: {
group: "Input/meta options:",
type: "string",
describe: `Specify an package name for the init command. Default to cwd directory name.`,
defaultDescription: `basename(options.cwd)`,
},
files: {
group: "Input/meta options:",
type: "string",
describe: `A glob pattern for files to be processed by build command. All JS and TS files in root or "src/" folder.`,
defaultDescription: `"{*.+(t|j||mj)s,src/**/*.+(t|j||mj)s}"`,
},
ignore: {
group: "Input/meta options:",
type: "array",
describe: `Files to be ignored by build command.`,
defaultDescription: `["**/node_modules/**", "**/web_modules/**"]`,
},
dependencies: {
group: "Input/meta options:",
type: "string",
choices: ["all", "dev", "prod"],
describe: `Install all dependencies from package.json, only devDependencies ("dev"), only dependencies ("prod") or an array of dependency as ES module into web_modules.`,
defaultDescription: `all`,
},
updateVersions: {
group: "Input/meta options:",
type: "boolean",
describe: `Update package.json engines with current Node.js/npm version from template, and currently used snowdev version.`,
defaultDescription: `true`,
},
npmPath: {
group: "Input/meta options:",
type: "string",
describe: `Specify a path for the "npm" package. If null, commands will use "npm" from shell.`,
defaultDescription: `null`,
},
NODE_ENV: {
group: "Commands options:",
type: "string",
describe: `Define "process.env.NODE_ENV" and minify dependencies if set to "production".`,
defaultDescription: `development`,
},
ts: {
group: "Commands options:",
type: "boolean",
describe: `Use TypeScript for init, dev and build commands (create index.ts, watch files or build files). Auto-detected if a "tsconfig.json" is detected with a "compilerOptions.outDir" set.`,
defaultDescription: `undefined`,
},
serve: {
group: "Commands options:",
type: "boolean",
describe: `Start Browsersync on dev command.`,
defaultDescription: `true`,
},
lint: {
group: "Commands options:",
type: "boolean",
describe: `Lint on build command.`,
defaultDescription: `true`,
},
format: {
group: "Commands options:",
type: "boolean",
describe: `Format on build command.`,
defaultDescription: `true`,
},
types: {
group: "Commands options:",
type: "boolean",
describe: `Run TypeScript (generate types or compile) on build command or watch on dev command.`,
defaultDescription: `true`,
},
docs: {
group: "Commands options:",
type: "string",
describe: `Generate documentation (using "JSDoc" or "typedoc") in file (between "options.docsStart" and "options.docsEnd") or directory. Default to "README.md" but "docs" if "options.ts".`,
defaultDescription: `undefined`,
},
docsFormat: {
group: "Commands options:",
type: "string",
choices: ["md", "html"],
describe: `Default to "md" but "html" if "options.ts".`,
defaultDescription: `undefined`,
},
commitAndTagVersion: {
group: "Commands options:",
type: "boolean|Object",
describe: `Bump the version, generate changelog release, create a new commit with git tag on release command.`,
defaultDescription: `true`,
},
pkgFix: {
group: "Commands options:",
type: "boolean",
describe: `Run "npm pkg fix" on release command.`,
defaultDescription: `true`,
},
crossOriginIsolation: {
group: "Commands options:",
type: "boolean",
describe: `Add Cross-Origin-Opener-Policy (COOP) and Cross-Origin-Embedder-Policy (COEP) headers to browsersync. Required for the use of SharedArrayBuffer.`,
defaultDescription: `false`,
},
http2: {
group: "Commands options:",
type: "boolean",
describe: `Serve with "node:http2".`,
defaultDescription: `true`,
},
hmr: {
group: "Commands options:",
type: "boolean",
describe: `Add Hot Module Replacement to browsersync. Requires "es-module-shims" with "shimMode".`,
defaultDescription: `true`,
},
})
.wrap(parser.terminalWidth())
.version(VERSION)
.help();
Object.values(commands).forEach((fn) => {
parser.command(
fn.name === "dev" ? [fn.name, "$0"] : fn.name,
fn.description,
() => {},
async (argv) => {
await run(fn, { caller: "cli", ...(await getConfig()), ...argv, argv });
},
);
});
parser.parse();