-
Notifications
You must be signed in to change notification settings - Fork 46
Expand file tree
/
Copy pathindex.js
More file actions
executable file
·132 lines (110 loc) · 3.49 KB
/
Copy pathindex.js
File metadata and controls
executable file
·132 lines (110 loc) · 3.49 KB
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
#!/usr/bin/env node
import program from 'commander'
import chalk from 'chalk'
import determineConfig from './determineConfig'
import logger from '../logger'
import bundlewatchApi, { STATUSES } from '../app'
const prettyPrintResults = (fullResults) => {
logger.log('')
fullResults.forEach((result) => {
const filePath = chalk.italic(result.filePath) + ':'
if (result.error) {
logger.log(`${chalk.red('ERROR')} ${filePath} ${result.error}`)
return
}
if (result.status === STATUSES.FAIL) {
logger.log(
`${chalk.redBright('FAIL')} ${filePath} ${result.message}`,
)
return
}
if (result.status === STATUSES.WARN) {
logger.log(
`${chalk.yellowBright('WARN')} ${filePath} ${result.message}`,
)
return
}
logger.log(`${chalk.greenBright('PASS')} ${filePath} ${result.message}`)
})
logger.log('')
}
const main = async () => {
const config = determineConfig(program)
if (config.files && config.files.length > 0) {
const results = await bundlewatchApi(config)
if (results.url) {
logger.log('')
logger.log(
`${chalk.cyanBright('Result breakdown at:')} ${results.url}`,
)
}
prettyPrintResults(results.fullResults)
if (results.status === STATUSES.FAIL) {
logger.log(chalk.redBright(`bundlewatch FAIL`))
logger.log(results.summary)
logger.log('')
return 1
}
if (results.status === STATUSES.WARN) {
logger.log(chalk.redBright(`bundlewatch WARN`))
logger.log(results.summary)
logger.log('')
return 0
}
logger.log(chalk.greenBright(`bundlewatch PASS`))
logger.log(results.summary)
logger.log('')
return 0
}
logger.error(`Configuration missing:
Run ${chalk.italic('bundlewatch --help')} for examples and options
Documentation available at: http://bundlewatch.io/`)
return 1
}
const mainSafe = async () => {
try {
const errorCode = await main()
return errorCode
} catch (error) {
if (error.type === 'ValidationError') {
logger.fatal(error.message)
return 1
}
logger.fatal(`Uncaught exception`, error)
return 1
}
}
program
.usage('[options] <filePathGlobs ...>')
.option(
'--config [configFilePath]',
'file to read configuration from, if used all options are blown away',
)
.option('--max-size [maxSize]', 'maximum size threshold (e.g. 3kb)')
.option(
'--compression [compression]',
'specify which compression algorithm to use',
)
.option(
'--normalize [regex]',
'normalize filenames via regex, any match will be removed',
)
program.on('--help', () => {
logger.log('')
logger.log(' Examples:')
logger.log('')
logger.log(' Read configuration from package.json')
logger.log(' $ bundlewatch ')
logger.log('')
logger.log(' Read configuration from file')
logger.log(' $ bundlewatch --config internals/bundlewatch.config.js')
logger.log('')
logger.log(' Use command line')
logger.log(' $ bundlewatch --max-size 100KB ./src/*.js /lib/*.js')
logger.log('')
logger.log('')
})
program.parse(process.argv)
mainSafe().then((errorCode) => {
process.exitCode = errorCode
})