@@ -77,22 +77,42 @@ function createApp(name) {
77
77
run ( root , appName , originalDirectory ) ;
78
78
}
79
79
80
- function run ( root , appName , originalDirectory ) {
81
- const templatePath = path . resolve ( __dirname , 'template' ) ;
82
- if ( fs . existsSync ( templatePath ) ) {
83
- fs . copySync ( templatePath , root ) ;
84
- let packageJsonPath = path . join ( root , 'package.json' ) ;
85
- let packageJson = require ( packageJsonPath ) ;
86
- packageJson . name = appName ;
87
- packageJson . version = '0.0.1' ;
88
-
89
- fs . writeFileSync ( packageJsonPath , JSON . stringify ( packageJson , null , 2 ) ) ;
90
- console . log ( 'Installing packages. This might take a couple of minutes.' ) ;
91
- return install ( ) ;
92
- } else {
93
- console . error ( `Could not locate supplied template: ${ chalk . green ( templatePath ) } ` ) ;
94
- return ;
80
+ async function run ( root , appName , originalDirectory ) {
81
+ function installTemplate ( templateName ) {
82
+ try {
83
+ console . log ( 'loading template' , templateName ) ;
84
+ const res = require ( 'child_process' )
85
+ . execSync ( `npm install ${ templateName } ` )
86
+ . toString ( )
87
+ . trim ( ) ;
88
+ console . log ( `${ templateName } loaded successfully` ) ;
89
+ } catch ( e ) {
90
+ console . log ( `${ templateName } err` ) ;
91
+ }
92
+ }
93
+ const templateName = '@nobrainr/typescript_universal-webpack-karma_jasmine' ;
94
+ const templatePath = path . resolve ( __dirname , 'node_modules' , templateName ) ;
95
+ if ( ! fs . existsSync ( templatePath ) ) {
96
+ try {
97
+ installTemplate ( templateName ) ;
98
+ } catch ( e ) {
99
+ console . log ( e ) ;
100
+ }
95
101
}
102
+ fs . copySync ( templatePath , root , {
103
+ dereference : true ,
104
+ filter : function ( path ) {
105
+ return path . indexOf ( `${ templateName } /node_modules` ) === - 1 ;
106
+ }
107
+ } ) ;
108
+ let packageJsonPath = path . join ( root , 'package.json' ) ;
109
+ let packageJson = require ( packageJsonPath ) ;
110
+ packageJson . name = appName ;
111
+ packageJson . version = '0.0.1' ;
112
+
113
+ fs . writeFileSync ( packageJsonPath , JSON . stringify ( packageJson , null , 2 ) ) ;
114
+ console . log ( 'Installing packages. This might take a couple of minutes.' ) ;
115
+ return await install ( ) ;
96
116
}
97
117
98
118
function install ( ) {
0 commit comments