1 | const readPkgUp = require('read-pkg-up')
|
2 | const pkg = readPkgUp.sync().pkg
|
3 | const program = require('commander')
|
4 | const { info, error } = require('prettycli')
|
5 | const debug = require('./debug')
|
6 |
|
7 |
|
8 | const packageJSONconfig = pkg.bundlesize
|
9 |
|
10 |
|
11 |
|
12 | program
|
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 |
|
18 | let cliConfig
|
19 |
|
20 | if (program.files && program.maxSize) {
|
21 | cliConfig = [
|
22 | {
|
23 | path: program.files,
|
24 | maxSize: program.maxSize
|
25 | }
|
26 | ]
|
27 | }
|
28 |
|
29 |
|
30 |
|
31 | if (!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 |
|
42 | const config = cliConfig || packageJSONconfig
|
43 |
|
44 | debug('cli config', cliConfig)
|
45 | debug('package json config', packageJSONconfig)
|
46 | debug('selected config', config)
|
47 |
|
48 | module.exports = config
|