1 | const fs = require('fs')
|
2 | const bytes = require('bytes')
|
3 | const glob = require('glob')
|
4 | const gzip = require('gzip-size')
|
5 | const { error } = require('prettycli')
|
6 | const config = require('./config')
|
7 | const debug = require('./debug')
|
8 |
|
9 | const files = []
|
10 |
|
11 | config.map(file => {
|
12 | const paths = glob.sync(file.path)
|
13 | if (!paths.length) {
|
14 | error('There is no matching file for ' + file.path, { silent: true })
|
15 | } else {
|
16 | paths.map(path => {
|
17 | const size = gzip.sync(fs.readFileSync(path, 'utf8'))
|
18 | const maxSize = bytes(file.threshold || file.maxSize)
|
19 | files.push({ maxSize, path, size })
|
20 | })
|
21 | }
|
22 | })
|
23 |
|
24 | debug('files', files)
|
25 |
|
26 | module.exports = files
|