6
6
* LICENSE file in the root directory of this source tree. An additional grant
7
7
* of patent rights can be found in the PATENTS file in the same directory.
8
8
*/
9
- 'use strict' ;
10
-
11
9
const webpack = require ( 'webpack' ) ;
12
10
const chalk = require ( 'chalk' ) ;
13
11
const webpackConfig = require ( './webpack.config.js' ) ;
@@ -18,27 +16,40 @@ const chokidar = require('chokidar');
18
16
const args = process . argv . slice ( 2 ) ;
19
17
const watchMode = args [ 0 ] === '--watch' || args [ 0 ] === '-w' ;
20
18
19
+ const isCI =
20
+ process . env . CI &&
21
+ ( typeof process . env . CI !== 'string' ||
22
+ process . env . CI . toLowerCase ( ) !== 'false' ) ;
23
+
21
24
function build ( config , name , callback ) {
22
25
console . log ( chalk . cyan ( 'Compiling ' + name ) ) ;
23
26
webpack ( config ) . run ( ( error , stats ) => {
24
27
if ( error ) {
25
28
console . log ( chalk . red ( 'Failed to compile.' ) ) ;
26
29
console . log ( error . message || error ) ;
27
30
console . log ( ) ;
28
- return ;
29
31
}
30
32
31
33
if ( stats . compilation . errors . length ) {
32
34
console . log ( chalk . red ( 'Failed to compile.' ) ) ;
33
35
console . log ( stats . toString ( { all : false , errors : true } ) ) ;
34
- return ;
35
36
}
36
37
37
38
if ( stats . compilation . warnings . length ) {
38
39
console . log ( chalk . yellow ( 'Compiled with warnings.' ) ) ;
39
40
console . log ( stats . toString ( { all : false , warnings : true } ) ) ;
40
41
}
41
42
43
+ // Fail the build if running in a CI server
44
+ if (
45
+ error ||
46
+ stats . compilation . errors . length ||
47
+ stats . compilation . warnings . length
48
+ ) {
49
+ isCI && process . exit ( 1 ) ;
50
+ return ;
51
+ }
52
+
42
53
console . log (
43
54
stats . toString ( { colors : true , modules : false , version : false } )
44
55
) ;
@@ -51,9 +62,7 @@ function build(config, name, callback) {
51
62
function runBuildSteps ( ) {
52
63
build ( iframeWebpackConfig , 'iframeScript.js' , ( ) => {
53
64
build ( webpackConfig , 'index.js' , ( ) => {
54
- console . log ( chalk . bold . green ( 'Compiled successfully!' ) ) ;
55
- console . log ( ) ;
56
- console . log ( ) ;
65
+ console . log ( chalk . bold . green ( 'Compiled successfully!\n\n' ) ) ;
57
66
} ) ;
58
67
} ) ;
59
68
}
@@ -83,7 +92,6 @@ function setupWatch() {
83
92
84
93
// Clean up lib folder
85
94
rimraf ( 'lib/' , ( ) => {
86
- console . log ( 'Cleaned up the lib folder.' ) ;
87
- console . log ( ) ;
95
+ console . log ( 'Cleaned up the lib folder.\n' ) ;
88
96
watchMode ? setupWatch ( ) : runBuildSteps ( ) ;
89
97
} ) ;
0 commit comments