1
1
const { series } = require ( 'gulp' ) ;
2
- const { exec } = require ( 'child_process' ) ;
2
+ const { exec, spawn , spawnSync } = require ( 'child_process' ) ;
3
3
const { readdirSync, rmSync, copyFileSync } = require ( 'fs' ) ;
4
+ const path = require ( 'path' ) ;
4
5
const chalk = require ( 'chalk' ) ;
6
+ const tsc = mocha = path . resolve ( __dirname , './node_modules/typescript/bin/tsc' ) ;
7
+ const wp = mocha = path . resolve ( __dirname , './node_modules/webpack/bin/webpack' ) ;
5
8
6
9
const paths = {
7
10
out : './dist' ,
@@ -10,7 +13,25 @@ const paths = {
10
13
webpackName : 'ts-react-json-table.js'
11
14
} ;
12
15
13
- function run ( cmd , onClose ) {
16
+ function run ( cmd , args , cb ) {
17
+ console . log ( ) ;
18
+
19
+ const status = spawnSync ( cmd , args , {
20
+ cwd : process . cwd ( ) ,
21
+ env : process . env ,
22
+ stdio : [ process . stdin , process . stdout , process . stderr ] ,
23
+ encoding : 'utf-8'
24
+ } ) . status ;
25
+
26
+ if ( status !== 0 ) {
27
+ throw Error ( `Failed to execute command '${ args . join ( ) } '` ) ;
28
+ }
29
+ else {
30
+ cb ( ) ;
31
+ }
32
+ }
33
+
34
+ function execute ( cmd , cb ) {
14
35
15
36
exec ( cmd , function ( err , stdout , stderr ) {
16
37
if ( err ) {
@@ -19,12 +40,12 @@ function run(cmd, onClose){
19
40
throw err ;
20
41
}
21
42
console . log ( stdout ) ;
22
- onClose ( ) ;
43
+ cb ( ) ;
23
44
} ) ;
24
45
}
25
46
26
47
function build ( cb ) {
27
- run ( 'tsc ' , cb )
48
+ run ( 'node ' , [ tsc ] , cb ) ;
28
49
}
29
50
30
51
function clean ( cb ) {
@@ -34,7 +55,7 @@ function clean(cb) {
34
55
}
35
56
36
57
function webpack ( cb ) {
37
- run ( 'webpack --config ./webpack.config.js' , cb ) ;
58
+ run ( 'node' , [ wp , ' --config' , ' ./webpack.config.js'] , cb ) ;
38
59
}
39
60
40
61
function copy ( cb ) {
@@ -43,7 +64,7 @@ function copy(cb) {
43
64
}
44
65
45
66
function pack ( cb ) {
46
- run ( 'npm pack' , cb ) ;
67
+ execute ( 'npm pack' , cb ) ;
47
68
}
48
69
49
70
exports . build = build ;
0 commit comments