@@ -14,6 +14,7 @@ const del = require('del');
14
14
const cpy = require ( 'cpy' ) ;
15
15
const mkdirp = require ( 'mkdirp' ) ;
16
16
const webpack = require ( 'webpack' ) ;
17
+ const cp = require ( 'child_process' ) ;
17
18
const browserSync = require ( 'browser-sync' ) ;
18
19
const webpackDevMiddleware = require ( 'webpack-dev-middleware' ) ;
19
20
const webpackHotMiddleware = require ( 'webpack-hot-middleware' ) ;
@@ -22,24 +23,31 @@ const tasks = new Map();
22
23
const config = require ( './webpack.config' ) ;
23
24
const routes = require ( './routes.json' ) ;
24
25
25
- // Execute a task
26
+ /* eslint-disable no-console, global-require */
27
+
26
28
function run ( task ) {
27
29
const start = new Date ( ) ;
28
- console . log ( `Starting '${ task } '...` ) ; // eslint-disable-line no-console
30
+ console . log ( `Starting '${ task } '...` ) ;
29
31
return Promise . resolve ( ) . then ( ( ) => tasks . get ( task ) ( ) ) . then ( ( ) => {
30
32
const end = new Date ( ) ;
31
33
const time = end . getTime ( ) - start . getTime ( ) ;
32
- console . log ( `Finished '${ task } ' after ${ time } ms` ) ; // eslint-disable-line no-console
33
- } , err => console . error ( err . stack ) ) ; // eslint-disable-line no-console
34
+ console . log ( `Finished '${ task } ' after ${ time } ms` ) ;
35
+ } , err => console . error ( err . stack ) ) ;
34
36
}
35
37
38
+ //
36
39
// Clean up the output directory
40
+ // -----------------------------------------------------------------------------
37
41
tasks . set ( 'clean' , ( ) => del ( [ 'build/*' , '!build/.git' ] , { dot : true } ) ) ;
38
42
43
+ //
39
44
// Copy static files into the output directory
45
+ // -----------------------------------------------------------------------------
40
46
tasks . set ( 'copy' , ( ) => cpy ( [ 'static/**/*.*' ] , 'build' ) ) ;
41
47
48
+ //
42
49
// Generate static HTML pages based on routes.json
50
+ // -----------------------------------------------------------------------------
43
51
tasks . set ( 'pages' , ( ) => {
44
52
const assets = JSON . parse ( fs . readFileSync ( './build/assets.json' , 'utf8' ) ) ;
45
53
const html = fs . readFileSync ( './static/index.html' , 'utf8' )
@@ -63,34 +71,39 @@ tasks.set('bundle', () =>
63
71
if ( err ) {
64
72
reject ( err ) ;
65
73
} else {
66
- console . log ( stats . toString ( config . stats ) ) ; // eslint-disable-line no-console
74
+ console . log ( stats . toString ( config . stats ) ) ;
67
75
resolve ( ) ;
68
76
}
69
77
} ) ;
70
78
} )
71
79
) ;
72
80
81
+ //
73
82
// Build website into a distributable format
83
+ // -----------------------------------------------------------------------------
74
84
tasks . set ( 'build' , ( ) => Promise . resolve ( )
75
85
. then ( ( ) => run ( 'clean' ) )
76
86
. then ( ( ) => run ( 'copy' ) )
77
87
. then ( ( ) => run ( 'bundle' ) )
78
88
. then ( ( ) => run ( 'pages' ) )
79
89
) ;
80
90
91
+ //
81
92
// Build and publish the website
93
+ // -----------------------------------------------------------------------------
82
94
tasks . set ( 'publish' , ( ) => run ( 'publish:gh' ) ) ;
83
95
96
+ //
84
97
// Build and publish the website to GitHub Pages
98
+ // -----------------------------------------------------------------------------
85
99
tasks . set ( 'publish:gh' , ( ) => {
86
100
const remote = {
87
101
url : 'https://github.com/<owner>/<repo>.git' , // TODO: Update deployment URL
88
102
branch : 'gh-pages' ,
89
103
} ;
90
- const { spawn } = require ( 'child_process' ) ; // eslint-disable-line global-require
91
104
const opts = { cwd : path . resolve ( __dirname , './build' ) , stdio : [ 'ignore' , 'inherit' , 'inherit' ] } ;
92
105
const git = ( ...args ) => new Promise ( ( resolve , reject ) => {
93
- spawn ( 'git' , args , opts ) . on ( 'close' , code => {
106
+ cp . spawn ( 'git' , args , opts ) . on ( 'close' , code => {
94
107
if ( code === 0 ) {
95
108
resolve ( ) ;
96
109
} else {
@@ -121,9 +134,11 @@ tasks.set('publish:gh', () => {
121
134
. then ( ( ) => git ( 'push' , 'origin' , `HEAD:${ remote . branch } ` , '--force' , '--set-upstream' ) ) ;
122
135
} ) ;
123
136
137
+ //
124
138
// Build and publish the website to Amazon S3
139
+ // -----------------------------------------------------------------------------
125
140
tasks . set ( 'publish:s3' , ( ) => {
126
- const s3 = require ( 's3' ) ; // eslint-disable-line global-require
141
+ const s3 = require ( 's3' ) ;
127
142
return run ( 'build' ) . then ( ( ) => new Promise ( ( resolve , reject ) => {
128
143
const client = s3 . createClient ( {
129
144
s3Options : {
@@ -141,7 +156,9 @@ tasks.set('publish:s3', () => {
141
156
} ) ) ;
142
157
} ) ;
143
158
159
+ //
144
160
// Build website and launch it in a browser for testing (default)
161
+ // -----------------------------------------------------------------------------
145
162
tasks . set ( 'start' , ( ) =>
146
163
new Promise ( resolve => {
147
164
// Hot Module Replacement (HMR) + React Hot Reload
0 commit comments