-
Notifications
You must be signed in to change notification settings - Fork 0
/
resolveArgs.js
57 lines (50 loc) 路 1.36 KB
/
resolveArgs.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
const { program } = require("commander");
/**
* Converts string to Array.
*
* @param {string} value
* @returns {Array}
*/
function string2Arr(value) {
return value.split(",");
}
/**
* Extracts string to suit plugins entries
* {@link https://www.npmjs.com/package/@rollup/plugin-alias}
*
* @param {string[]} alias - batman=../../../batman
* @returns {Object[]} - {find, replacement}
*/
function extractAlias(aliasStr) {
const alias = string2Arr(aliasStr).map(str => {
const [key, value] = str.split("=");
return { find: key, replacement: value };
});
return alias;
}
function resolveArgs(argv) {
program
.option("-s, --silent <boolean>", "Silent mode, mutes build massages")
.option("-f, --formats <list>", "Specific build format", string2Arr)
.option(
"-m, --minify <boolean>",
"Minify bundle works only if format is provided"
)
.option("-b, --build-name <string>", "Specific build name")
.option(
"-w, --pkg-paths <list>",
"Provide custom paths not in the root/src",
string2Arr
)
.option(
"-n, --pkg-names <list>",
"Building specific package[s], in workspace",
string2Arr
)
.option("-a, --alias <list>", "Package Alias", extractAlias, "");
if (argv) {
program.allowUnknownOption();
}
return program.parse(argv || process.argv);
}
export default resolveArgs;