@@ -2,16 +2,16 @@ const path = require('path');
2
2
const chalk = require ( 'chalk' ) ;
3
3
const fs = require ( 'fs-extra' ) ;
4
4
const _ = require ( 'underscore' ) ;
5
+ const run = require ( 'gulp-run' ) ;
5
6
const moment = require ( 'moment' ) ;
6
7
const op = require ( 'object-path' ) ;
7
- const { spawn } = require ( 'child_process' ) ;
8
8
const prettier = require ( 'prettier' ) . format ;
9
9
const handlebars = require ( 'handlebars' ) . compile ;
10
10
11
11
const timestamp = ( ) => `[${ chalk . magenta ( moment ( ) . format ( 'HH:mm:ss' ) ) } ]` ;
12
-
13
12
const msg = ( ...msg ) => console . log ( timestamp ( ) , ...msg ) ;
14
- const override = `
13
+
14
+ const gulpOverride = `
15
15
module.${ chalk . cyan ( 'exports' ) } = ${ chalk . magenta ( 'config' ) } => {
16
16
config.${ chalk . cyan ( 'dest' ) } .${ chalk . cyan ( 'electron' ) } = ${ chalk . magenta (
17
17
"'build-electron'" ,
@@ -35,8 +35,22 @@ module.${chalk.cyan('exports')} = ${chalk.magenta('config')} => {
35
35
};
36
36
` ;
37
37
38
+ const manifestOverride = `
39
+ module.${ chalk . cyan ( 'exports' ) } = ${ chalk . magenta ( 'config' ) } => {
40
+ config.${ chalk . cyan ( 'contexts.components.mode' ) } = ${ chalk . magenta (
41
+ "'sync'" ,
42
+ ) } ;
43
+ config.${ chalk . cyan ( 'contexts.common.mode' ) } = ${ chalk . magenta ( "'sync'" ) } ;
44
+ config.${ chalk . cyan ( 'contexts.toolkit.mode' ) } = ${ chalk . magenta ( "'sync'" ) } ;
45
+ config.${ chalk . cyan ( 'contexts.core.mode' ) } = ${ chalk . magenta ( "'sync'" ) } ;
46
+
47
+ return ${ chalk . magenta ( 'config' ) } ;
48
+ };
49
+ ` ;
50
+
38
51
let cwd ;
39
52
let gulpConfig ;
53
+ let manifestConfig ;
40
54
let reactiumConfig ;
41
55
42
56
module . exports = ( ) => {
@@ -49,23 +63,44 @@ module.exports = () => {
49
63
'.core' ,
50
64
'reactium-config.js' ,
51
65
) ) ;
66
+
52
67
gulpConfig = reactiumConfig . build ;
68
+ manifestConfig = reactiumConfig . manifest ;
53
69
54
70
if ( ! op . has ( gulpConfig , 'dest.electron' ) ) {
55
- console . log ( '\n' ) ;
56
71
msg (
57
72
`The following ${ chalk . cyan (
58
73
'gulp.config.override.js' ,
59
- ) } values need to be added:`,
74
+ ) } values need to be set:`,
75
+ ) ;
76
+ console . log ( '\n' ) ;
77
+ console . log ( gulpOverride ) ;
78
+ console . log ( `${ chalk . magenta ( 'Action cancelled' ) } !` ) ;
79
+ console . log ( '\n' ) ;
80
+
81
+ process . exit ( 0 ) ;
82
+ }
83
+
84
+ if (
85
+ op . get ( manifestConfig , 'contexts.components.mode' ) !==
86
+ 'sync'
87
+ ) {
88
+ msg (
89
+ `The following ${ chalk . cyan (
90
+ 'manifest.config.override.js' ,
91
+ ) } values need to be set:`,
60
92
) ;
61
93
console . log ( '\n' ) ;
62
- console . log ( override ) ;
94
+ console . log ( manifestOverride ) ;
95
+ console . log ( `${ chalk . magenta ( 'Action cancelled' ) } !` ) ;
63
96
console . log ( '\n' ) ;
97
+
64
98
process . exit ( 0 ) ;
65
99
}
66
100
67
101
resolve ( { action, status : 200 } ) ;
68
102
} ) ,
103
+
69
104
config : ( { action, props } ) =>
70
105
new Promise ( resolve => {
71
106
const configFile = path . join (
@@ -108,124 +143,78 @@ module.exports = () => {
108
143
109
144
build : ( { action, props } ) =>
110
145
new Promise ( resolve => {
111
- const exec = spawn ( 'gulp' , [ '--color' ] , {
112
- env : {
113
- ...process . env ,
114
- cwd,
115
- NODE_ENV : 'production' ,
116
- } ,
117
- } ) ;
118
-
119
- exec . on ( 'exit' , ( ) => resolve ( { action, status : 200 } ) ) ;
120
- exec . stderr . pipe ( process . stderr ) ;
121
- exec . stdout . pipe ( process . stdout ) ;
122
- } ) ,
123
-
124
- babelConfig : ( { action, props } ) =>
125
- new Promise ( resolve => {
126
- msg ( 'Generating' , chalk . cyan ( 'babel.config.js' ) + '...' ) ;
127
-
128
- const babelBuildFile = path . join (
129
- cwd ,
130
- op . get ( reactiumConfig , 'dest.electron' , 'build-electron' ) ,
131
- 'babel.config.js' ,
146
+ msg ( 'Building' , chalk . cyan ( 'app' ) + '...' ) ;
147
+ const cmd = new run . Command (
148
+ `cross-env NODE_ENV=production gulp --color` ,
149
+ { verbosity : 0 } ,
132
150
) ;
133
- const babelConfigFile = path . join ( cwd , 'babel.config.js' ) ;
134
-
135
- fs . ensureFileSync ( babelBuildFile ) ;
136
- fs . copySync ( babelConfigFile , babelBuildFile ) ;
137
-
138
- resolve ( { action, status : 200 } ) ;
139
- } ) ,
140
-
141
- babelConfigUpdate : ( { action, props } ) =>
142
- new Promise ( resolve => {
143
- msg ( 'Updating' , chalk . cyan ( 'babel.config.js paths' ) + '...' ) ;
144
- const babelBuildFile = path . normalize (
145
- path . join (
146
- cwd ,
147
- op . get (
148
- reactiumConfig ,
149
- 'dest.electron' ,
150
- 'build-electron' ,
151
- ) ,
152
- 'babel.config.js' ,
153
- ) ,
151
+ setTimeout (
152
+ ( ) =>
153
+ cmd . exec ( null , ( ) => resolve ( { action, status : 200 } ) ) ,
154
+ 1 ,
154
155
) ;
155
- const cont = String (
156
- fs . readFileSync ( babelBuildFile , 'utf-8' ) ,
157
- ) . replace ( / \' \. \/ \. c o r e / gi, "'../.core" ) ;
158
-
159
- fs . writeFileSync ( babelBuildFile , cont ) ;
160
-
161
- resolve ( { action, status : 200 } ) ;
162
156
} ) ,
163
157
164
158
compileCore : ( { action, props } ) =>
165
159
new Promise ( resolve => {
166
- msg ( 'Compiling' , chalk . cyan ( '.core' ) + '...' ) ;
160
+ msg ( 'Compiling' , chalk . cyan ( 'core' ) + '...' ) ;
161
+ const srcDir = path . join ( cwd , '.core' ) ;
167
162
const outDir = path . join (
168
163
cwd ,
169
164
op . get ( gulpConfig , 'dest.build' , 'build/.core' ) ,
170
165
) ;
171
- const srcDir = path . join ( cwd , '.core' ) ;
172
-
173
- const exec = spawn (
174
- 'babel' ,
175
- [ srcDir , '--out-dir' , outDir , '--color' ] ,
176
- {
177
- env : {
178
- ...process . env ,
179
- cwd,
180
- NODE_ENV : 'production' ,
181
- } ,
182
- } ,
166
+ const cmd = new run . Command (
167
+ `cross-env NODE_ENV=production babel "${ srcDir } " --out-dir "${ outDir } "` ,
168
+ { verbosity : 0 } ,
169
+ ) ;
170
+ setTimeout (
171
+ ( ) =>
172
+ cmd . exec ( null , ( ) => resolve ( { action, status : 200 } ) ) ,
173
+ 1 ,
183
174
) ;
184
-
185
- exec . on ( 'exit' , ( ) => resolve ( { action, status : 200 } ) ) ;
186
- //exec.stderr.pipe(process.stderr);
187
- exec . stdout . pipe ( process . stdout ) ;
188
175
} ) ,
189
176
190
177
compileSrc : ( { action, props } ) =>
191
178
new Promise ( resolve => {
192
179
msg ( 'Compiling' , chalk . cyan ( 'src' ) + '...' ) ;
180
+ const srcDir = path . join ( cwd , 'src' ) ;
193
181
const outDir = path . join (
194
182
cwd ,
195
183
op . get ( gulpConfig , 'dest.buildSrc' , 'build/src' ) ,
196
184
) ;
197
- const srcDir = path . join ( cwd , 'src' ) ;
198
-
199
- const exec = spawn (
200
- 'babel' ,
201
- [ srcDir , '--out-dir' , outDir , '--color' ] ,
202
- {
203
- env : {
204
- ...process . env ,
205
- cwd,
206
- NODE_ENV : 'production' ,
207
- } ,
208
- } ,
185
+ const cmd = new run . Command (
186
+ `cross-env NODE_ENV=production babel "${ srcDir } " --out-dir "${ outDir } "` ,
187
+ { verbosity : 0 } ,
188
+ ) ;
189
+ setTimeout (
190
+ ( ) =>
191
+ cmd . exec ( null , ( ) => resolve ( { action, status : 200 } ) ) ,
192
+ 1 ,
209
193
) ;
210
-
211
- exec . on ( 'exit' , ( ) => resolve ( { action, status : 200 } ) ) ;
212
- //exec.stderr.pipe(process.stderr);
213
- exec . stdout . pipe ( process . stdout ) ;
214
194
} ) ,
195
+
215
196
static : ( { action, props } ) =>
216
197
new Promise ( resolve => {
217
- msg ( 'Copying' , chalk . cyan ( 'static assets' ) + '...' ) ;
218
- const exec = spawn ( 'gulp' , [ 'static' , '--color' ] , {
219
- env : {
220
- ...process . env ,
198
+ // Clear output directory
199
+ fs . removeSync (
200
+ path . join (
221
201
cwd ,
222
- NODE_ENV : 'production' ,
223
- } ,
224
- } ) ;
202
+ op . get (
203
+ gulpConfig ,
204
+ 'dest.static' ,
205
+ 'build-electron/app/public' ,
206
+ ) ,
207
+ ) ,
208
+ ) ;
225
209
226
- exec . on ( 'exit' , ( ) => resolve ( { action, status : 200 } ) ) ;
227
- exec . stderr . pipe ( process . stderr ) ;
228
- exec . stdout . pipe ( process . stdout ) ;
210
+ const cmd = new run . Command ( `gulp static --color` , {
211
+ verbosity : 0 ,
212
+ } ) ;
213
+ setTimeout (
214
+ ( ) =>
215
+ cmd . exec ( null , ( ) => resolve ( { action, status : 200 } ) ) ,
216
+ 1 ,
217
+ ) ;
229
218
} ) ,
230
219
231
220
main : ( { action, props } ) =>
@@ -261,14 +250,15 @@ module.exports = () => {
261
250
) ;
262
251
263
252
if ( ! fs . existsSync ( destDir ) ) {
253
+ msg ( `Copying ${ chalk . cyan ( 'resources' ) } ...` ) ;
264
254
const templateDir = path . join (
265
255
__dirname ,
266
256
'template' ,
267
257
'resources' ,
268
258
) ;
269
259
270
260
fs . ensureDirSync ( destDir ) ;
271
- fs . copySync ( templateDir , destdir ) ;
261
+ fs . copySync ( templateDir , destDir ) ;
272
262
}
273
263
274
264
resolve ( { action, status : 200 } ) ;
@@ -283,6 +273,8 @@ module.exports = () => {
283
273
) ;
284
274
285
275
if ( ! fs . existsSync ( destFile ) ) {
276
+ msg ( `Generating ${ chalk . cyan ( 'package.json' ) } ...` ) ;
277
+
286
278
const templateFile = path . join (
287
279
__dirname ,
288
280
'template' ,
@@ -296,11 +288,58 @@ module.exports = () => {
296
288
resolve ( { action, status : 200 } ) ;
297
289
} ) ,
298
290
299
- complete : ( { action } ) => {
300
- console . log ( '' ) ;
301
- msg ( 'Build' , chalk . cyan ( 'Complete' ) + '!' ) ;
302
- console . log ( '' ) ;
303
- return Promise . resolve ( { action, status : 200 } ) ;
304
- } ,
291
+ icon : ( { action, props } ) =>
292
+ new Promise ( resolve => {
293
+ msg ( `Generating ${ chalk . cyan ( 'icons' ) } ...` ) ;
294
+
295
+ const shFile = path . join (
296
+ cwd ,
297
+ gulpConfig . dest . electron ,
298
+ 'resources' ,
299
+ 'icon_gen.sh' ,
300
+ ) ;
301
+
302
+ const icon = path . join (
303
+ cwd ,
304
+ gulpConfig . dest . electron ,
305
+ 'resources' ,
306
+ 'icon.png' ,
307
+ ) ;
308
+
309
+ const output = path . join (
310
+ cwd ,
311
+ gulpConfig . dest . electron ,
312
+ 'resources' ,
313
+ ) ;
314
+
315
+ const cmd = new run . Command (
316
+ `sh "${ shFile } " "${ icon } " "${ output } "` ,
317
+ { verbosity : 0 } ,
318
+ ) ;
319
+ cmd . exec ( null , ( ) => resolve ( { action, status : 200 } ) ) ;
320
+ } ) ,
321
+
322
+ install : ( { action, props } ) =>
323
+ new Promise ( resolve => {
324
+ msg ( `Installing ${ chalk . cyan ( 'dependencies' ) } ...` ) ;
325
+ const cmd = new run . Command (
326
+ `cd ${ gulpConfig . dest . electron } && npm install` ,
327
+ { verbosity : 0 } ,
328
+ ) ;
329
+ setTimeout (
330
+ ( ) =>
331
+ cmd . exec ( null , ( ) => resolve ( { action, status : 200 } ) ) ,
332
+ 1 ,
333
+ ) ;
334
+ } ) ,
335
+
336
+ complete : ( { action } ) =>
337
+ new Promise ( resolve => {
338
+ setTimeout ( ( ) => {
339
+ msg ( 'Build' , chalk . cyan ( 'Complete' ) + '!' ) ;
340
+ console . log ( '\n' ) ;
341
+ resolve ( { action, status : 200 } ) ;
342
+ } , 3000 ) ;
343
+ } ) ,
305
344
} ;
306
345
} ;
0 commit comments