UNPKG

1.11 kBJavaScriptView Raw
1const readPkgUp = require('read-pkg-up')
2const pkg = readPkgUp.sync().pkg
3const program = require('commander')
4const { info, error } = require('prettycli')
5const debug = require('./debug')
6
7/* Config from package.json */
8const packageJSONconfig = pkg.bundlesize
9
10/* Config from CLI */
11
12program
13 .option('-f, --files [files]', 'files to test against (dist/*.js)')
14 .option('-s, --max-size [maxSize]', 'maximum size threshold (3Kb)')
15 .option('--debug', 'run in debug mode')
16 .parse(process.argv)
17
18let cliConfig
19
20if (program.files && program.maxSize) {
21 cliConfig = [
22 {
23 path: program.files,
24 maxSize: program.maxSize
25 }
26 ]
27}
28
29/* Send to readme if no configuration is provided */
30
31if (!packageJSONconfig && !cliConfig) {
32 error(
33 `Config not found.
34
35 You can read about the configuration options here:
36 https://github.com/siddharthkp/bundlesize#configuration
37 `,
38 { silent: true }
39 )
40}
41
42const config = cliConfig || packageJSONconfig
43
44debug('cli config', cliConfig)
45debug('package json config', packageJSONconfig)
46debug('selected config', config)
47
48module.exports = config