-
Notifications
You must be signed in to change notification settings - Fork 165
/
args.js
98 lines (89 loc) · 3 KB
/
args.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
'use strict'
const argv = require('yargs-parser')
const dotenv = require('dotenv')
const { requireModule } = require('./util')
const DEFAULT_IGNORE = 'node_modules build dist .git bower_components logs .swp .nyc_output'
const DEFAULT_ARGUMENTS = {
logLevel: 'fatal',
prettyLogs: false,
watch: false,
verboseWatch: false,
debug: false,
debugPort: 9320,
options: false,
pluginTimeout: 10 * 1000, // everything should load in 10 seconds
closeGraceDelay: 500,
lang: 'js',
standardlint: false,
commonPrefix: false
}
module.exports = function parseArgs (args) {
dotenv.config()
const commandLineArguments = argv(args, {
configuration: {
'populate--': true
},
number: ['port', 'inspect-port', 'body-limit', 'plugin-timeout', 'close-grace-delay'],
string: ['log-level', 'address', 'socket', 'prefix', 'ignore-watch', 'logging-module', 'debug-host', 'lang', 'require', 'import', 'config', 'method'],
boolean: ['pretty-logs', 'options', 'watch', 'verbose-watch', 'debug', 'standardlint', 'common-prefix', 'include-hooks'],
envPrefix: 'FASTIFY_',
alias: {
port: ['p'],
socket: ['s'],
help: ['h'],
config: ['c'],
options: ['o'],
address: ['a'],
watch: ['w'],
prefix: ['x'],
require: ['r'],
import: ['i'],
debug: ['d'],
'debug-port': ['I'],
'log-level': ['l'],
'pretty-logs': ['P'],
'plugin-timeout': ['T'],
'close-grace-delay': ['g'],
'logging-module': ['L'],
'verbose-watch': ['V']
}
})
const configFileOptions = commandLineArguments.config ? requireModule(commandLineArguments.config) : undefined
const additionalArgs = commandLineArguments['--'] || []
const { _, ...pluginOptions } = argv(additionalArgs)
const ignoreWatchArg = commandLineArguments.ignoreWatch || configFileOptions?.ignoreWatch || ''
let ignoreWatch = `${DEFAULT_IGNORE} ${ignoreWatchArg}`.trim()
if (ignoreWatchArg.includes('.ts$')) {
ignoreWatch = ignoreWatch.replace('dist', '')
}
// Merge objects from lower to higher priority
const parsedArgs = { ...DEFAULT_ARGUMENTS, ...configFileOptions, ...commandLineArguments }
return {
_: parsedArgs._,
'--': additionalArgs,
port: parsedArgs.port,
bodyLimit: parsedArgs.bodyLimit,
pluginTimeout: parsedArgs.pluginTimeout,
closeGraceDelay: parsedArgs.closeGraceDelay,
pluginOptions,
prettyLogs: parsedArgs.prettyLogs,
options: parsedArgs.options,
watch: parsedArgs.watch,
debug: parsedArgs.debug,
debugPort: parsedArgs.debugPort,
debugHost: parsedArgs.debugHost,
ignoreWatch,
verboseWatch: parsedArgs.verboseWatch,
logLevel: parsedArgs.logLevel,
address: parsedArgs.address,
socket: parsedArgs.socket,
require: parsedArgs.require,
import: parsedArgs.import,
prefix: parsedArgs.prefix,
loggingModule: parsedArgs.loggingModule,
lang: parsedArgs.lang,
method: parsedArgs.method,
commonPrefix: parsedArgs.commonPrefix,
includeHooks: parsedArgs.includeHooks
}
}