@@ -3,6 +3,7 @@ const fs = require('fs');
33const path = require ( 'path' ) ;
44const child_process = require ( 'child_process' ) ;
55const os = require ( 'os' ) ;
6+ const util = require ( 'util' ) ;
67const { debounce } = require ( 'lodash' ) ;
78
89if ( ! process . env . MMS_HOME ) {
@@ -58,11 +59,42 @@ const webpackWatchProcess = child_process.spawn('npm', ['run', 'watch'], {
5859 stdio : 'inherit' ,
5960} ) ;
6061
62+ const failProofRunner = ( ) =>
63+ new ( class FailProofRunner extends Array {
64+ append ( ...fns ) {
65+ this . push ( ...fns ) ;
66+ return this ;
67+ }
68+
69+ run ( ) {
70+ const errors = this . map ( ( f ) => {
71+ try {
72+ f ( ) ;
73+ } catch ( e ) {
74+ return e ;
75+ }
76+ } ) . filter ( ( e ) => e ) ;
77+
78+ if ( errors . length ) {
79+ fs . writeSync (
80+ process . stdout . fd ,
81+ util . inspect ( errors , { depth : 20 } ) + '\n'
82+ ) ;
83+ }
84+
85+ return errors . length ;
86+ }
87+ } ) ( ) ;
88+
6189function cleanup ( signalName ) {
62- distWatcher . close ( ) ;
63- webpackWatchProcess . kill ( signalName ) ;
64- fs . cpSync ( tmpDir , destDir , { recursive : true } ) ;
65- fs . rmSync ( tmpDir , { recursive : true , force : true } ) ;
90+ const errorCount = failProofRunner ( )
91+ . append ( ( ) => distWatcher . close ( ) )
92+ . append ( ( ) => webpackWatchProcess . kill ( signalName ) )
93+ . append ( ( ) => fs . cpSync ( tmpDir , destDir , { recursive : true } ) )
94+ . append ( ( ) => fs . rmSync ( tmpDir , { recursive : true , force : true } ) )
95+ . run ( ) ;
96+ fs . writeSync ( process . stdout . fd , 'Exit compass-web sync...\n' ) ;
97+ process . exit ( errorCount ) ;
6698}
6799
68100for ( const evt of [ 'SIGINT' , 'SIGTERM' ] ) {
0 commit comments