@@ -23,6 +23,8 @@ var ejs = require('ejs'),
23
23
BuildLog = require ( './BuildLog' ) ,
24
24
Orphanage = require ( './Orphanage' ) ;
25
25
26
+ const MvcCompileTask = require ( './tasks/mvc-compile-task' ) ;
27
+
26
28
var alloyRoot = path . join ( __dirname , '..' , '..' ) ,
27
29
viewRegex = new RegExp ( '\\.' + CONST . FILE_EXT . VIEW + '$' ) ,
28
30
controllerRegex = new RegExp ( '\\.' + CONST . FILE_EXT . CONTROLLER + '$' ) ,
@@ -418,93 +420,52 @@ module.exports = function(args, program) {
418
420
CU . models . push ( m ) ;
419
421
} ) ;
420
422
421
- // Create a regex for determining which platform-specific
422
- // folders should be used in the compile process
423
- var filteredPlatforms = _ . reject ( CONST . PLATFORM_FOLDERS_ALLOY , function ( p ) {
424
- return p === buildPlatform ;
425
- } ) ;
426
- filteredPlatforms = _ . map ( filteredPlatforms , function ( p ) { return p + '[\\\\\\/]' ; } ) ;
427
- var filterRegex = new RegExp ( '^(?:(?!' + filteredPlatforms . join ( '|' ) + '))' ) ;
428
-
429
- // don't process XML/controller files inside .svn folders (ALOY-839)
430
- var excludeRegex = new RegExp ( '(?:^|[\\/\\\\])(?:' + CONST . EXCLUDED_FILES . join ( '|' ) + ')(?:$|[\\/\\\\])' ) ;
431
-
432
- // Process all views/controllers and generate their runtime
433
- // commonjs modules and source maps.
434
- var tracker = { } ;
435
- _ . each ( widgetDirs , function ( collection ) {
436
- // generate runtime controllers from views
437
- var theViewDir = path . join ( collection . dir , CONST . DIR . VIEW ) ;
438
- if ( fs . existsSync ( theViewDir ) ) {
439
- _ . each ( walkSync ( theViewDir ) , function ( view ) {
440
- view = path . normalize ( view ) ;
441
- if ( viewRegex . test ( view ) && filterRegex . test ( view ) && ! excludeRegex . test ( view ) ) {
442
- // make sure this controller is only generated once
443
- var theFile = view . substring ( 0 , view . lastIndexOf ( '.' ) ) ;
444
- var theKey = theFile . replace ( new RegExp ( '^' + buildPlatform + '[\\/\\\\]' ) , '' ) ;
445
- var fp = path . join ( collection . dir , theKey ) ;
446
- if ( tracker [ fp ] ) { return ; }
447
-
448
- // generate runtime controller
449
- logger . info ( '[' + view + '] ' + ( collection . manifest ? collection . manifest . id +
450
- ' ' : '' ) + 'view processing...' ) ;
451
- parseAlloyComponent ( view , collection . dir , collection . manifest , null , restrictionPath ) ;
452
- tracker [ fp ] = true ;
453
- }
454
- } ) ;
455
- }
456
-
457
- // generate runtime controllers from any controller code that has no
458
- // corresponding view markup
459
- var theControllerDir = path . join ( collection . dir , CONST . DIR . CONTROLLER ) ;
460
- if ( fs . existsSync ( theControllerDir ) ) {
461
- _ . each ( walkSync ( theControllerDir ) , function ( controller ) {
462
- controller = path . normalize ( controller ) ;
463
- if ( controllerRegex . test ( controller ) && filterRegex . test ( controller ) && ! excludeRegex . test ( controller ) ) {
464
- // make sure this controller is only generated once
465
- var theFile = controller . substring ( 0 , controller . lastIndexOf ( '.' ) ) ;
466
- var theKey = theFile . replace ( new RegExp ( '^' + buildPlatform + '[\\/\\\\]' ) , '' ) ;
467
- var fp = path . join ( collection . dir , theKey ) ;
468
- if ( tracker [ fp ] ) { return ; }
469
-
470
- // generate runtime controller
471
- logger . info ( '[' + controller + '] ' + ( collection . manifest ?
472
- collection . manifest . id + ' ' : '' ) + 'controller processing...' ) ;
473
- parseAlloyComponent ( controller , collection . dir , collection . manifest , true , restrictionPath ) ;
474
- tracker [ fp ] = true ;
475
- }
423
+ return Promise . resolve ( )
424
+ . then ( ( ) => {
425
+ const mvcCompileTask = new MvcCompileTask ( {
426
+ incrementalDirectory : path . join ( compileConfig . dir . project , 'build' , 'alloy' , 'incremental' , 'mvc' ) ,
427
+ logger,
428
+ compileConfig,
429
+ restrictionPath,
430
+ parseAlloyComponent,
431
+ sourceCollections : widgetDirs ,
432
+ targetPlatform : buildPlatform
476
433
} ) ;
477
- }
478
- } ) ;
479
- logger . info ( '' ) ;
480
-
481
- generateAppJs ( paths , compileConfig , restrictionPath , compilerMakeFile ) ;
482
-
483
- // ALOY-905: workaround TiSDK < 3.2.0 iOS device build bug where it can't reference app.js
484
- // in platform-specific folders, so we just copy the platform-specific one to
485
- // the Resources folder.
486
- if ( buildPlatform === 'ios' && tiapp . version . lt ( '3.2.0' ) ) {
487
- U . copyFileSync ( path . join ( paths . resources , titaniumFolder , 'app.js' ) , path . join ( paths . resources , 'app.js' ) ) ;
488
- }
434
+ return mvcCompileTask . run ( ) ;
435
+ } )
436
+ . then ( ( ) => {
437
+ generateAppJs ( paths , compileConfig , restrictionPath , compilerMakeFile ) ;
438
+
439
+ // ALOY-905: workaround TiSDK < 3.2.0 iOS device build bug where it can't reference app.js
440
+ // in platform-specific folders, so we just copy the platform-specific one to
441
+ // the Resources folder.
442
+ if ( buildPlatform === 'ios' && tiapp . version . lt ( '3.2.0' ) ) {
443
+ U . copyFileSync ( path . join ( paths . resources , titaniumFolder , 'app.js' ) , path . join ( paths . resources , 'app.js' ) ) ;
444
+ }
489
445
490
- // optimize code
491
- logger . info ( '----- OPTIMIZING -----' ) ;
446
+ // optimize code
447
+ logger . info ( '----- OPTIMIZING -----' ) ;
492
448
493
- if ( restrictionSkipOptimize ) {
494
- logger . info ( 'Skipping optimize due to file restriction.' ) ;
495
- } else {
496
- optimizeCompiledCode ( alloyConfig , paths ) ;
497
- }
449
+ if ( restrictionSkipOptimize ) {
450
+ logger . info ( 'Skipping optimize due to file restriction.' ) ;
451
+ } else {
452
+ optimizeCompiledCode ( alloyConfig , paths ) ;
453
+ }
498
454
499
- // trigger our custom compiler makefile
500
- if ( compilerMakeFile . isActive ) {
501
- compilerMakeFile . trigger ( 'post:compile' , _ . clone ( compileConfig ) ) ;
502
- }
455
+ // trigger our custom compiler makefile
456
+ if ( compilerMakeFile . isActive ) {
457
+ compilerMakeFile . trigger ( 'post:compile' , _ . clone ( compileConfig ) ) ;
458
+ }
503
459
504
- // write out the log for this build
505
- buildLog . write ( ) ;
460
+ // write out the log for this build
461
+ buildLog . write ( ) ;
506
462
507
- BENCHMARK ( 'TOTAL' , true ) ;
463
+ BENCHMARK ( 'TOTAL' , true ) ;
464
+ } )
465
+ . catch ( e => {
466
+ logger . error ( e ) ;
467
+ U . die ( e . message ) ;
468
+ } ) ;
508
469
} ;
509
470
510
471
0 commit comments