-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
executable file
·69 lines (64 loc) · 1.42 KB
/
index.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
#!/usr/bin/env node
const fs = require('fs');
const glob = require('glob');
const lib = require('./lib');
const core = require('./core');
/**
* The exposed run function that client call.
* @param parsedArgs
*/
function run(parsedArgs) {
if (!parsedArgs) {
return false;
}
core.run(lib.validateArgs(parsedArgs, [{
option: 'webpack-config',
validate: (val) => {
if (val) {
return fs.existsSync(val);
}
return true;
},
error: 'The specified webpack config does not exist.',
}, {
option: 'spec',
validate: (val) => {
if (val) {
return glob.sync(val).length > 0;
}
return true;
},
error: 'No spec files were found.',
}, {
option: 'watch',
validate: (val) => {
if (!val) return true;
if (val.length > 0) {
return val.split(',').every((dir) => fs.existsSync(dir));
}
return true;
},
error: 'Please specify valid directories to watch.',
}, {
option: 'require',
validate: (val) => {
if (val) {
return fs.existsSync(val);
}
return true;
},
error: 'The specified required file does not exist.',
}]));
}
// If running via command line..
if (require.main === module) {
run(lib.parseInput(lib.getArgs()));
}
// Programmatic API
module.exports = {
run(conf) {
const parsedInput = lib.parseInput(conf);
run(parsedInput);
return parsedInput;
},
};