11var path = require ( 'path' ) ;
2+ var Blueprint = require ( 'ember-cli/lib/models/blueprint' ) ;
23var dynamicPathParser = require ( '../../utilities/dynamic-path-parser' ) ;
34
5+ var getFiles = Blueprint . prototype . files ;
6+
47module . exports = {
58 description : '' ,
69
710 availableOptions : [
8- { name : 'flat' , type : Boolean , default : false , aliases : [ 'f' ] }
11+ { name : 'flat' , type : Boolean , default : false }
912 ] ,
1013
1114 normalizeEntityName : function ( entityName ) {
@@ -16,22 +19,59 @@ module.exports = {
1619 } ,
1720
1821 locals : function ( options ) {
22+ //TODO: pull value from config
23+ this . styleExt = 'css' ;
24+
1925 return {
2026 dynamicPath : this . dynamicPath . dir . replace ( this . dynamicPath . appRoot , '' ) ,
21- flat : options . flat
27+ flat : options . flat ,
28+ styleExt : this . styleExt ,
29+ isLazyRoute : ! ! options . isLazyRoute ,
30+ isAppComponent : ! ! options . isAppComponent
2231 } ;
2332 } ,
33+
34+ files : function ( ) {
35+ var fileList = getFiles . call ( this ) ;
36+
37+ if ( this . options . flat ) {
38+ fileList = fileList . filter ( p => p . indexOf ( 'index.ts' ) <= 0 ) ;
39+ }
2440
41+ return fileList ;
42+ } ,
43+
2544 fileMapTokens : function ( options ) {
2645 // Return custom template variables here.
2746 return {
2847 __path__ : ( ) => {
2948 var dir = this . dynamicPath . dir ;
3049 if ( ! options . locals . flat ) {
3150 dir += path . sep + options . dasherizedModuleName ;
51+
52+ if ( options . locals . isLazyRoute ) {
53+ var dirParts = dir . split ( path . sep ) ;
54+ dirParts [ dirParts . length - 1 ] = `+${ dirParts [ dirParts . length - 1 ] } ` ;
55+ dir = dirParts . join ( path . sep ) ;
56+ }
3257 }
58+ this . appDir = dir . replace ( `src${ path . sep } client${ path . sep } ` , '' ) ;
3359 return dir ;
60+ } ,
61+ __styleext__ : ( ) => {
62+ return options . locals . styleExt ;
3463 }
3564 } ;
65+ } ,
66+
67+ afterInstall : function ( options ) {
68+ if ( ! options . flat ) {
69+ var filePath = path . join ( 'src' , 'client' , 'system-config.ts' ) ;
70+ return this . insertIntoFile (
71+ filePath ,
72+ ` '${ this . appDir } ',` ,
73+ { before : ' //barrel registration' }
74+ ) ;
75+ }
3676 }
3777} ;
0 commit comments