@@ -13,20 +13,19 @@ const { resolve: resolvePath } = require('path');
1313const { spawn } = require ( 'child_process' ) ;
1414const flowBinPath = require ( 'flow-bin' ) ;
1515
16-
1716process . env . PATH += ':./node_modules/.bin' ;
1817
1918const cmd = resolvePath ( __dirname ) ;
2019const srcDir = resolvePath ( cmd , '../src' ) ;
2120
2221function exec ( command , options ) {
23- return new Promise ( function ( resolve , reject ) {
22+ return new Promise ( function ( resolve , reject ) {
2423 const child = spawn ( command , options , {
2524 cmd,
2625 env : process . env ,
27- stdio : 'inherit'
26+ stdio : 'inherit' ,
2827 } ) ;
29- child . on ( 'exit' , function ( code ) {
28+ child . on ( 'exit' , function ( code ) {
3029 if ( code === 0 ) {
3130 resolve ( true ) ;
3231 } else {
@@ -36,18 +35,18 @@ function exec(command, options) {
3635 } ) ;
3736}
3837
39- const flowServer = spawn ( flowBinPath , [ 'server' ] , {
38+ const flowServer = spawn ( flowBinPath , [ 'server' ] , {
4039 cmd,
41- env : process . env
40+ env : process . env ,
4241} ) ;
4342
44- const watcher = sane ( srcDir , { glob : [ '**/*.js' , '**/*.graphql' ] } )
43+ const watcher = sane ( srcDir , { glob : [ '**/*.js' , '**/*.graphql' ] } )
4544 . on ( 'ready' , startWatch )
4645 . on ( 'add' , changeFile )
4746 . on ( 'delete' , deleteFile )
4847 . on ( 'change' , changeFile ) ;
4948
50- process . on ( 'SIGINT' , function ( ) {
49+ process . on ( 'SIGINT' , function ( ) {
5150 watcher . close ( ) ;
5251 flowServer . kill ( ) ;
5352 console . log ( CLEARLINE + yellow ( invert ( 'stopped watching' ) ) ) ;
@@ -100,14 +99,17 @@ function checkFiles(filepaths) {
10099
101100 return parseFiles ( filepaths )
102101 . then ( ( ) => runTests ( filepaths ) )
103- . then ( testSuccess => lintFiles ( filepaths )
104- . then ( lintSuccess => typecheckStatus ( )
105- . then ( typecheckSuccess =>
106- testSuccess && lintSuccess && typecheckSuccess ) ) )
102+ . then ( testSuccess =>
103+ lintFiles ( filepaths ) . then ( lintSuccess =>
104+ typecheckStatus ( ) . then (
105+ typecheckSuccess => testSuccess && lintSuccess && typecheckSuccess ,
106+ ) ,
107+ ) ,
108+ )
107109 . catch ( ( ) => false )
108110 . then ( success => {
109111 process . stdout . write (
110- '\n' + ( success ? '' : '\x07' ) + green ( invert ( 'watching...' ) )
112+ '\n' + ( success ? '' : '\x07' ) + green ( invert ( 'watching...' ) ) ,
111113 ) ;
112114 } ) ;
113115}
@@ -117,50 +119,60 @@ function checkFiles(filepaths) {
117119function parseFiles ( filepaths ) {
118120 console . log ( 'Checking Syntax' ) ;
119121
120- return Promise . all ( filepaths . map ( filepath => {
121- if ( isJS ( filepath ) && ! isTest ( filepath ) ) {
122- return exec ( 'babel' , [
123- '--optional' , 'runtime' ,
124- '--out-file' , '/dev/null' ,
125- srcPath ( filepath )
126- ] ) ;
127- }
128- } ) ) ;
122+ return Promise . all (
123+ filepaths . map ( filepath => {
124+ if ( isJS ( filepath ) && ! isTest ( filepath ) ) {
125+ return exec ( 'babel' , [
126+ '--optional' ,
127+ 'runtime' ,
128+ '--out-file' ,
129+ '/dev/null' ,
130+ srcPath ( filepath ) ,
131+ ] ) ;
132+ }
133+ } ) ,
134+ ) ;
129135}
130136
131137function runTests ( filepaths ) {
132138 console . log ( '\nRunning Tests' ) ;
133139
134- return exec ( 'mocha' , [
135- '--reporter' , 'progress' ,
136- '--require' , 'resources/mocha-bootload'
137- ] . concat (
138- allTests ( filepaths ) ? filepaths . map ( srcPath ) :
139- [ 'src/**/__tests__/**/*.js' ]
140- ) ) . catch ( ( ) => false ) ;
140+ return exec (
141+ 'mocha' ,
142+ [ '--reporter' , 'progress' , '--require' , 'resources/mocha-bootload' ] . concat (
143+ allTests ( filepaths )
144+ ? filepaths . map ( srcPath )
145+ : [ 'src/**/__tests__/**/*.js' ] ,
146+ ) ,
147+ ) . catch ( ( ) => false ) ;
141148}
142149
143150function lintFiles ( filepaths ) {
144151 console . log ( 'Linting Code\n' ) ;
145152
146- return filepaths . reduce ( ( prev , filepath ) => prev . then ( prevSuccess => {
147- if ( isJS ( filepath ) ) {
148- process . stdout . write ( ' ' + filepath + ' ...' ) ;
149- return exec ( 'eslint' , [ srcPath ( filepath ) ] )
150- . catch ( ( ) => false )
151- . then ( success => {
152- const msg = CLEARLINE + ' ' + ( success ? CHECK : X ) + ' ' + filepath ;
153- console . log ( msg ) ;
154- return prevSuccess && success ;
155- } ) ;
156- }
157- return prevSuccess ;
158- } ) , Promise . resolve ( true ) ) ;
153+ return filepaths . reduce (
154+ ( prev , filepath ) =>
155+ prev . then ( prevSuccess => {
156+ if ( isJS ( filepath ) ) {
157+ process . stdout . write ( ' ' + filepath + ' ...' ) ;
158+ return exec ( 'eslint' , [ srcPath ( filepath ) ] )
159+ . catch ( ( ) => false )
160+ . then ( success => {
161+ const msg =
162+ CLEARLINE + ' ' + ( success ? CHECK : X ) + ' ' + filepath ;
163+ console . log ( msg ) ;
164+ return prevSuccess && success ;
165+ } ) ;
166+ }
167+ return prevSuccess ;
168+ } ) ,
169+ Promise . resolve ( true ) ,
170+ ) ;
159171}
160172
161173function typecheckStatus ( ) {
162174 console . log ( '\nType Checking\n' ) ;
163- return exec ( flowBinPath , [ 'status' ] ) . catch ( ( ) => false ) ;
175+ return exec ( flowBinPath , [ 'status' ] ) . catch ( ( ) => false ) ;
164176}
165177
166178// Filepath
0 commit comments