1
1
const gulp = require ( "gulp" ) ;
2
- const eslint = require ( ' gulp-eslint' ) ;
2
+ const eslint = require ( " gulp-eslint" ) ;
3
3
const tslint = require ( "gulp-tslint" ) ;
4
- const PluginError = require ( ' plugin-error' ) ;
5
- const log = require ( ' fancy-log' ) ;
4
+ const PluginError = require ( " plugin-error" ) ;
5
+ const log = require ( " fancy-log" ) ;
6
6
const ts = require ( "gulp-typescript" ) ;
7
7
const sourcemaps = require ( "gulp-sourcemaps" ) ;
8
8
const webpack = require ( "webpack" ) ;
9
- const del = require ( 'del' ) ;
9
+ const del = require ( "del" ) ;
10
+ const download = require ( "download" ) ;
11
+ const extract = require ( "extract-zip" ) ;
10
12
const fs = require ( "fs" ) ;
11
13
const path = require ( "path" ) ;
12
14
const childProcess = require ( "child_process" ) ;
13
- const argv = require ( ' minimist' ) ( process . argv . slice ( 2 ) ) ;
15
+ const argv = require ( " minimist" ) ( process . argv . slice ( 2 ) ) ;
14
16
15
17
gulp . task ( "tslint" , ( ) => {
16
18
return gulp . src ( [ "**/*.ts" , "**/*.tsx" , "!**/*.d.ts" , "!./vendor/**" , "!node_modules/**" , "!./src/views/node_modules/**" , "!out/**" ] )
@@ -28,39 +30,61 @@ gulp.task("eslint", () => {
28
30
gulp . task ( "html-webpack" , ( done ) => {
29
31
const config = require ( "./src/views/webpack.config.js" ) ;
30
32
config . context = `${ __dirname } /src/views` ;
31
- config . mode = argv . mode ? argv . mode : ' production' ;
33
+ config . mode = argv . mode ? argv . mode : " production" ;
32
34
return webpack ( config , ( err , stats ) => {
33
35
const statsJson = stats . toJson ( ) ;
34
36
if ( err || ( statsJson . errors && statsJson . errors . length ) ) {
35
37
statsJson . errors . forEach ( webpackError => {
36
38
log . error ( `Error (webpack): ${ webpackError } ` ) ;
37
39
} ) ;
38
40
39
- throw new PluginError ( ' webpack' , JSON . stringify ( err || statsJson . errors ) ) ;
41
+ throw new PluginError ( " webpack" , JSON . stringify ( err || statsJson . errors ) ) ;
40
42
}
41
- log ( ' [webpack]' , stats . toString ( ) ) ;
43
+ log ( " [webpack]" , stats . toString ( ) ) ;
42
44
done ( ) ;
43
45
} ) ;
44
46
} ) ;
45
47
46
48
gulp . task ( "node_modules-webpack" , ( done ) => {
47
49
const config = require ( "./webpack.config.js" ) ;
48
50
config . context = `${ __dirname } ` ;
49
- config . mode = argv . mode ? argv . mode : ' production' ;
51
+ config . mode = argv . mode ? argv . mode : " production" ;
50
52
return webpack ( config , ( err , stats ) => {
51
53
const statsJson = stats . toJson ( ) ;
52
54
if ( err || ( statsJson . errors && statsJson . errors . length ) ) {
53
55
statsJson . errors . forEach ( webpackError => {
54
56
log . error ( `Error (webpack): ${ webpackError } ` ) ;
55
57
} ) ;
56
58
57
- throw new PluginError ( ' webpack' , JSON . stringify ( err || statsJson . errors ) ) ;
59
+ throw new PluginError ( " webpack" , JSON . stringify ( err || statsJson . errors ) ) ;
58
60
}
59
- log ( ' [webpack]' , stats . toString ( ) ) ;
61
+ log ( " [webpack]" , stats . toString ( ) ) ;
60
62
done ( ) ;
61
63
} ) ;
62
64
} ) ;
63
65
66
+ gulp . task ( "insert-serial-monitor-cli" , async ( done ) => {
67
+ const platforms = [
68
+ "linux" ,
69
+ "darwin" ,
70
+ "win32" ,
71
+ ] ;
72
+ const release = "latest" ;
73
+ const destDir = path . resolve ( "out" , "serial-monitor-cli" ) ;
74
+
75
+ async function downloadAndUnzip ( platform ) {
76
+ const fileName = `${ platform } .zip` ;
77
+ const zipPath = path . join ( destDir , fileName ) ;
78
+ await download ( `https://github.com/microsoft/serial-monitor-cli/releases/${ release } /download/${ fileName } ` ,
79
+ destDir ,
80
+ ) ;
81
+ await extract ( zipPath , { dir : path . join ( destDir , platform ) } ) ;
82
+ fs . rmSync ( zipPath ) ;
83
+ }
84
+
85
+ Promise . all ( platforms . map ( downloadAndUnzip ) ) . then ( done ) ;
86
+ } ) ;
87
+
64
88
gulp . task ( "ts-compile" , ( ) => {
65
89
const tsProject = ts . createProject ( "./tsconfig.json" ) ;
66
90
return tsProject . src ( )
@@ -71,13 +95,13 @@ gulp.task("ts-compile", () => {
71
95
// Correct source map path.
72
96
const relativeSourcePath = path . relative ( path . dirname ( file . path ) , path . join ( file . base , sourcePath ) ) ;
73
97
return relativeSourcePath ;
74
- }
98
+ } ,
75
99
} ) )
76
100
. pipe ( gulp . dest ( "out" ) ) ;
77
101
} ) ;
78
102
79
103
gulp . task ( "clean" , ( done ) => {
80
- return del ( ' out' , done ) ;
104
+ return del ( " out" , done ) ;
81
105
} ) ;
82
106
83
107
gulp . task ( "genAikey" , ( done ) => {
@@ -100,8 +124,8 @@ gulp.task("test", (done) => {
100
124
}
101
125
102
126
// When using cli command "npm test" to exec test, the depended extensions (cpptools) are not available so that
103
- // the extension cannot be activated. As a workaround, remove extensionDependencies from package.json before running test
104
- // and restore extensionDependencies after test exited.
127
+ // the extension cannot be activated. As a workaround, remove extensionDependencies from package.json before
128
+ // running test and restore extensionDependencies after test exited.
105
129
removeExtensionDependencies ( ) ;
106
130
107
131
const child = childProcess . spawn ( "node" , [ "./out/test/runTest" ] , {
@@ -132,11 +156,11 @@ gulp.task("test", (done) => {
132
156
} ) ;
133
157
} ) ;
134
158
135
- gulp . task ( "build" , gulp . series ( "clean" , "ts-compile" , "html-webpack" , "node_modules-webpack" ) ) ;
159
+ gulp . task ( "build" , gulp . series ( "clean" , "ts-compile" , "html-webpack" , "node_modules-webpack" , "insert-serial-monitor-cli" ) ) ;
136
160
137
161
gulp . task ( "build_without_view" , gulp . series ( "clean" , "ts-compile" ) ) ;
138
162
139
163
gulp . task ( "watch" , ( ) => {
140
164
gulp . watch ( [ "./src/**/*" , "./test/**/*" , "!./src/views/**/*" ] , [ "ts-compile" ] ) ;
141
165
gulp . watch ( [ "./src/views/**/*" , "!./src/views/node_modules/**" ] , [ "html-webpack" ] ) ;
142
- } ) ;
166
+ } ) ;
0 commit comments