@@ -150,21 +150,22 @@ class Application extends EventEmitter {
150150 let files = this . _codeSource . all . getJSFiles ( ) ;
151151
152152 for ( const entity of this . _config . include ) {
153- files = files . concat ( entity . modules || [ ] ) ;
153+ files = files . concat ( entity . modules || [ ] )
154+ . map ( ( filePath ) => this . _pathHelper . resolveAbsolutePath ( filePath ) )
155+ . filter (
156+ ( filename ) => {
157+ const exists = fs . existsSync ( filename ) ;
158+ if ( ! exists ) {
159+ logger . warn ( `File ${ chalk . underline ( filename ) } does not exist` ) ;
160+ }
161+ return exists ;
162+ }
163+ ) ;
154164 }
155165
156- files = files . map ( ( filePath ) => this . _pathHelper . resolveAbsolutePath ( filePath ) ) ;
157166 logger . silly ( `Compiling js files: \n\t${ files . join ( '\n\t' ) } ` ) ;
158167
159- return files . filter (
160- ( filename ) => {
161- const exists = fs . existsSync ( filename ) ;
162- if ( ! exists ) {
163- logger . warn ( `File ${ chalk . underline ( filename ) } does not exist` ) ;
164- }
165- return exists ;
166- }
167- ) ;
168+ return files ;
168169 }
169170
170171 /**
@@ -194,21 +195,20 @@ class Application extends EventEmitter {
194195
195196 // Finally anything included as extra entities
196197 for ( const entity of this . _config . include ) {
197- files = files . concat ( entity . css || [ ] ) ;
198+ files = files . concat ( entity . css || [ ] )
199+ . map ( ( filePath ) => this . _pathHelper . resolveAbsolutePath ( filePath ) )
200+ . filter ( ( filename ) => {
201+ const exists = fs . existsSync ( filename ) ;
202+ if ( ! exists ) {
203+ logger . warn ( `File ${ chalk . underline ( filename ) } does not exist` ) ;
204+ }
205+ return exists ;
206+ } ) ;
198207 }
199208
200- files = files . map ( ( filePath ) => this . _pathHelper . resolveAbsolutePath ( filePath ) ) ;
201-
202209 logger . silly ( `Compiling css files: \n\t${ files . join ( '\n\t' ) } ` ) ;
203210
204- return files
205- . filter ( ( filename ) => {
206- const exists = fs . existsSync ( filename ) ;
207- if ( ! exists ) {
208- logger . warn ( `File ${ chalk . underline ( filename ) } does not exist` ) ;
209- }
210- return exists ;
211- } ) ;
211+ return files ;
212212 }
213213
214214 /**
@@ -256,8 +256,8 @@ class Application extends EventEmitter {
256256 /**
257257 * Compile templates, build base classes, etc.
258258 */
259- buildCode ( ) {
260- this . _codeSource . generated . generate ( ) ;
259+ async buildCode ( ) {
260+ await this . _codeSource . generated . generate ( ) ;
261261 }
262262
263263 /**
@@ -314,10 +314,10 @@ class Application extends EventEmitter {
314314 return null ;
315315 }
316316
317- const [ componentName , ...parts ] = aliasedPath . split ( path . sep ) ;
317+ const [ componentName , ...parts ] = aliasedPath . split ( '/' ) ;
318318 const absolutePath = map . get ( componentName ) ;
319319 if ( absolutePath ) {
320- return [ absolutePath , ...parts ] . join ( '/' ) ;
320+ return path . join ( absolutePath , ...parts ) ;
321321 }
322322 return null ;
323323 }
@@ -334,174 +334,12 @@ class Application extends EventEmitter {
334334
335335 for ( const [ alias , path ] of map ) {
336336 if ( fsPath . startsWith ( path ) ) {
337- return alias + fsPath . slice ( path . length ) ;
337+ return alias + fsPath . slice ( path . length ) . replace ( / \\ / g , '/' ) ;
338338 }
339339 }
340340 return null ;
341341 }
342342
343- /**
344- * TODO: remove in 2.7.0
345- * @param {Array<AbstractPlatform> } platforms
346- * @return {Promise }
347- */
348- compile ( platforms ) {
349- logger . warn ( `Running deprecated Application.compile(), use Application.build() instead` ) ;
350-
351- let resolvePromise = ( ) => { /* Noop */ } ;
352- let rejectPromise = ( ) => { /* Noop */ } ;
353- const deferred = new Promise ( ( resolve , reject ) => {
354- resolvePromise = resolve ;
355- rejectPromise = reject ;
356- } ) ;
357-
358- const mkPlatformDir = ( name ) => {
359- const platformDir = this . _pathHelper . getDistDir ( {
360- baseDir : this . _config . project . dist ,
361- version : this . getAppVersion ( ) ,
362- platformName : name
363- } ) ;
364-
365- if ( fs . existsSync ( platformDir ) ) {
366- logger . debug ( `Removing old build directory ${ chalk . underline ( platformDir ) } ` ) ;
367- fse . removeSync ( platformDir ) ;
368- }
369-
370- fse . ensureDirSync ( platformDir ) ;
371-
372- return platformDir ;
373- } ;
374-
375- const runExternalScript = ( scriptName , buildDir , platformName , platform , callback ) => {
376- if ( fs . existsSync ( scriptName ) ) {
377- logger . info ( `Running hook ${ chalk . underline ( scriptName ) } ` ) ;
378- try {
379- // eslint-disable-next-line global-require
380- const externalCallback = require ( scriptName ) ;
381- externalCallback ( callback , {
382- app : this ,
383- buildDir,
384- platformName,
385- platform : platform || null
386- } ) ;
387- } catch ( e ) {
388- logger . error ( `Hook error: ${ e . toString ( ) } ` ) ;
389- logger . debug ( e . trace ) ;
390- callback ( e ) ;
391- }
392- } else {
393- callback ( ) ;
394- }
395- } ;
396-
397- this . buildCode ( ) ;
398-
399- /**
400- * @param {AbstractPlatform } platform
401- * @param {function(*) } callback
402- */
403- const buildPlatform = ( platform , callback ) => {
404- const dir = mkPlatformDir ( platform . getName ( ) ) ;
405- const args = [ dir , platform . getName ( ) , platform ] ;
406-
407- logger . info ( `Building application for ${ chalk . bold ( platform . getName ( ) ) } in ${ chalk . underline ( dir ) } ` ) ;
408-
409- runExternalScript ( this . _pathHelper . getPreBuildHook ( ) , ...args , ( error ) => {
410- if ( error ) {
411- callback ( error ) ;
412-
413- return ;
414- }
415-
416- this . _config . appendObject ( {
417- define : {
418- PLATFORM_NAME : platform . getName ( )
419- }
420- } ) ;
421-
422- this . _codeSource . generated . generateDefines ( ) ;
423-
424- platform . buildApp ( this , dir )
425- . then ( ( warnings ) => {
426- if ( warnings ) {
427- const { report, truncated} = extractCompilationReport ( warnings ) ;
428-
429- if ( truncated ) {
430- logger . warn ( `Compilation finished with warnings: \n\n${ truncated } ` ) ;
431- }
432-
433- if ( report ) {
434- logger . info ( `Compilation result: ${ chalk . bold ( report ) } ` ) ;
435- }
436- }
437-
438- runExternalScript ( this . _pathHelper . getPostBuildHook ( ) , ...args , ( error ) => callback ( error ) ) ;
439- } , ( error ) => callback ( error ) ) ;
440- } ) ;
441- } ;
442-
443- const buildFirstPlatform = ( callback ) => {
444- const platform = platforms . shift ( ) ;
445- if ( platform ) {
446- buildPlatform ( platform , callback ) ;
447- } else {
448- callback ( ) ;
449- }
450- } ;
451-
452- const buildPlatforms = ( ) => {
453- buildFirstPlatform ( function done ( error ) {
454- if ( error ) {
455- if ( error instanceof Error ) {
456- logger . error ( error . toString ( ) ) ;
457- } else {
458- const { report, truncated} = extractCompilationReport ( error ) ;
459-
460- if ( truncated ) {
461- logger . error ( `Compilation finished with errors: \n\n${ truncated } ` ) ;
462- }
463-
464- if ( report ) {
465- logger . info ( `Compilation result: ${ chalk . bold ( report ) } ` ) ;
466- }
467- }
468-
469- logger . error ( `Build failed!` ) ;
470-
471- rejectPromise ( error ) ;
472- } else if ( platforms . length === 0 ) {
473- logger . output ( `Build done!` ) ;
474-
475- resolvePromise ( ) ;
476- } else {
477- buildFirstPlatform ( done ) ;
478- }
479- } ) ;
480- } ;
481-
482- const extractCompilationReport = ( text ) => {
483- const regex = / \n ? \d + e r r o r \( s \) , \d + w a r n i n g \( s \) (?: , [ \d . , ] + % t y p e d ) ? \n ? / ;
484- const match = text . match ( regex ) ;
485-
486- let report = '' ;
487- let truncated = text ;
488-
489- if ( match ) {
490- report = match [ 0 ] . trim ( ) ;
491- truncated = text . replace ( match [ 0 ] , '' ) ;
492- }
493-
494- return {
495- report,
496- truncated
497- } ;
498- } ;
499-
500- buildPlatforms ( ) ;
501-
502- return deferred ;
503- }
504-
505343 /**
506344 * @param {AbstractPlatform } platform
507345 * @return {Promise }
@@ -528,7 +366,7 @@ class Application extends EventEmitter {
528366 }
529367 } ) ;
530368
531- this . _codeSource . generated . generateDefines ( ) ;
369+ await this . _codeSource . generated . generateDefines ( ) ;
532370
533371 const [ cssCompilationResult , jsCompilationResult ] = await Promise . all ( [
534372 buildHelper . getCompressedStyles ( distDir ) ,
@@ -548,14 +386,21 @@ class Application extends EventEmitter {
548386 logger . debug ( jsCompilationResult . stderr ) ;
549387 logger . debug ( e . stack ) ;
550388
551- throw new Error ( `Failed to parse GCC output: ${ e . message } ` ) ;
389+ const match = e . message . match ( / U n e x p e c t e d t o k e n (?: .+ ) i n J S O N a t p o s i t i o n (?< position > \d + ) / ) ;
390+ let message = `Failed to parse GCC output: ${ e . message } ` ;
391+ if ( match && match . groups . position ) {
392+ message += '\n' + jsCompilationResult . stderr . slice ( parseInt ( match . groups . position , 10 ) ) ;
393+ }
394+ throw new Error ( message ) ;
552395 }
553396
554397 logger . silly ( `GCC compilation report: \n${ JSON . stringify ( jsCompilationReport , null , '\t' ) } ` ) ;
555398 logger . silly ( `CSS compilation report: \n${ JSON . stringify ( cssCompilationReport , null , '\t' ) } ` ) ;
556399
557- await fse . writeFile ( indexHtmlPath , indexHtmlContent , 'utf8' ) ;
558- buildHelper . copyStaticFiles ( distDir ) ;
400+ await Promise . all ( [
401+ fse . writeFile ( indexHtmlPath , indexHtmlContent , 'utf8' ) ,
402+ buildHelper . copyStaticFiles ( distDir )
403+ ] ) ;
559404
560405 cssCompilationReport . forEach ( ( message ) => {
561406 // TODO: fancier output
@@ -595,18 +440,7 @@ class Application extends EventEmitter {
595440 }
596441
597442 logger . verbose ( `Packaging application` ) ;
598- try {
599- await platform . pack ( this , distDir ) ;
600- } catch ( error ) {
601- // TODO: Remove catch block in 2.7.0
602- logger . error ( error . toString ( ) ) ;
603- logger . debug ( error . stack ) ;
604- logger . info ( `Is the platform up to date? Trying legacy building approach` ) ;
605-
606- await fse . emptyDir ( distDir ) ;
607- const warnings = await platform . buildApp ( this , distDir ) ;
608- logger . warn ( warnings ) ;
609- }
443+ await platform . pack ( this , distDir ) ;
610444
611445 await this . _runBuildHook ( this . _pathHelper . getPostBuildHook ( ) , platform ) ;
612446 }
@@ -684,8 +518,10 @@ class Application extends EventEmitter {
684518
685519 let platformFilter = ( ) => true ;
686520 if ( platform ) {
687- const otherPlatforms = this . getPlatforms ( ) . filter ( ( otherPlatform ) => otherPlatform !== platform ) ;
688- const otherIncludes = otherPlatforms . flatMap ( ( otherPlatform ) => otherPlatform . getConfig ( ) . include || [ ] ) ;
521+ const otherIncludes = this . getPlatforms ( )
522+ . filter ( ( otherPlatform ) => otherPlatform !== platform )
523+ . map ( ( otherPlatform ) => otherPlatform . getConfig ( ) . include || [ ] )
524+ . reduce ( ( all , other ) => all . concat ( other ) , [ ] ) ;
689525
690526 platformFilter = ( entity ) => {
691527 const shouldExclude = otherIncludes . some ( ( otherEntity ) => otherEntity . name === entity . name ) ;
@@ -790,7 +626,7 @@ class Application extends EventEmitter {
790626 try {
791627 this . _addonLoader . loadAddon ( pathOrAddon ) ;
792628 } catch ( e ) {
793- logger . debug ( e . trace ) ;
629+ logger . debug ( e . stack ) ;
794630 throw new Error ( `Can't load addon at "${ pathOrAddon } ": ${ e . toString ( ) } ` ) ;
795631 }
796632 } else if ( type === 'object' ) {
@@ -863,10 +699,9 @@ class Application extends EventEmitter {
863699 */
864700 _checkVersions ( ) {
865701 logger . verbose ( `Cross-checking ZombieBox packages dependencies` ) ;
866- const dependencies = this . getAppPackageJson ( ) . dependencies || { } ;
867- const packages = [ this . getZbPackageJson ( ) , ...this . _addonLoader . getPackageJsons ( ) ] ;
702+ const packages = [ this . getAppPackageJson ( ) , this . getZbPackageJson ( ) , ...this . _addonLoader . getPackageJsons ( ) ] ;
868703
869- const checker = new VersionsChecker ( dependencies , packages ) ;
704+ const checker = new VersionsChecker ( this . getAppPackageJson ( ) , packages ) ;
870705 const { warns, errors} = checker . check ( ) ;
871706
872707 warns . forEach ( ( message ) => logger . warn ( message ) ) ;
0 commit comments