-
Notifications
You must be signed in to change notification settings - Fork 0
/
buildTests.js
70 lines (56 loc) · 1.47 KB
/
buildTests.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
#!/usr/bin/env node
'use strict'
const Getopt = require('node-getopt')
const fs = require('fs')
const path = require('path')
const rimraf = require('rimraf')
const mkdirp = require('mkdirp')
let getopt = new Getopt([])
.parseSystem()
getopt.setHelp(
'Usage: node buildTests.js folder [folder+] [OPTION]\n' +
'build all tests in the specified folders.\n' +
'\n' +
'[[OPTIONS]]'
)
if (getopt.argv.length < 1) {
getopt.showHelp()
process.exit(1)
}
const webpack = require('webpack')
const webpackMerge = require('webpack-merge')
const baseDir = process.cwd()
const inputDirs = getopt.argv.map(p => path.join(baseDir, p))
const outputDir = path.join(baseDir, 'build/tests')
const mask = /.*_spec\.js$/
rimraf.sync(outputDir)
mkdirp.sync(outputDir)
let baseWConf = require('./webpack.test')
let wConf = webpackMerge.smart(baseWConf, {
entry: inputDirs
.reduce((p, dir) => p.concat(fs.readdirSync(dir)
.filter(f => f.match(mask))
.map(f => path.join(dir, f))), [])
.reduce((p, f) => {
p[path.basename(f)] = f
return p
}, {}),
output: {
path: outputDir
}
})
webpack(wConf, function (err, stats) {
if (err) {
console.log('Error : ' + err.message)
} else if (stats) {
let jsonStats = stats.toJson()
if (jsonStats.warnings.length > 0) {
console.log('warnings:')
console.log(jsonStats.warnings)
}
if (jsonStats.errors.length > 0) {
console.log('errors:')
console.log(jsonStats.errors)
}
}
})