-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathgulpfile.js
74 lines (61 loc) · 1.81 KB
/
gulpfile.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
71
72
73
74
const { series } = require('gulp');
const { exec, spawn, spawnSync } = require('child_process');
const { readdirSync, rmSync, copyFileSync } = require('fs');
const path = require('path');
const chalk = require('chalk');
const tsc = mocha = path.resolve(__dirname, './node_modules/typescript/bin/tsc');
const wp = mocha = path.resolve(__dirname, './node_modules/webpack/bin/webpack');
const paths = {
out: './dist',
webpack: './build/',
webpackEntry: './dist/grid.js',
webpackName: 'ts-react-json-table.js'
};
function run(cmd, args, cb){
console.log();
const status = spawnSync(cmd, args, {
cwd: process.cwd(),
env: process.env,
stdio: [process.stdin, process.stdout, process.stderr],
encoding: 'utf-8'
}).status;
if(status !== 0){
throw Error(`Failed to execute command '${args.join()}'`);
}
else{
cb();
}
}
function execute(cmd, cb){
exec(cmd, function (err, stdout, stderr) {
if(err){
console.log();
console.log(chalk.red(stdout));
throw err;
}
console.log(stdout);
cb();
});
}
function build(cb) {
run('node', [tsc], cb);
}
function clean(cb) {
readdirSync(paths.out).forEach(f => rmSync(`${paths.out}/${f}`, {recursive: true}));
readdirSync(paths.webpack).forEach(f => rmSync(`${paths.webpack}/${f}`, {recursive: true}));
cb();
}
function webpack(cb){
run('node', [wp, '--config', './webpack.config.js'], cb);
}
function copy(cb) {
copyFileSync('./src/ts-react-json-table.css', paths.webpack + 'ts-react-json-table.css');
cb();
}
function pack(cb){
execute('npm pack', cb);
}
exports.build = build;
exports.clean = clean;
exports.webpack = series(clean, build, webpack);
exports.pack = series(clean, build, webpack, copy, pack);