@@ -18,28 +18,32 @@ module.exports = function getStartAndEndCommands({
1818} ) {
1919 let isCustomBlueprint = endBlueprint . name !== 'ember-cli' ;
2020
21+ let startRange ;
22+ let endRange ;
23+ if ( isCustomBlueprint ) {
24+ startRange = endRange = '' ;
25+ } else {
26+ startRange = startBlueprint && startBlueprint . version ;
27+ endRange = endBlueprint . version ;
28+ }
29+
2130 return {
2231 projectName,
23- ...isCustomBlueprint ? { } : {
24- packageName : 'ember-cli' ,
25- commandName : 'ember' ,
26- // `createProjectFromCache` no longer works with custom blueprints.
27- // It would look for an `ember-cli` version with the same version
28- // as the blueprint.
29- createProjectFromCache
30- } ,
32+ packageName : 'ember-cli' ,
33+ commandName : 'ember' ,
34+ createProjectFromCache,
3135 createProjectFromRemote,
3236 startOptions : {
3337 blueprint : startBlueprint ,
3438
3539 // for cache detection logic
36- packageVersion : startBlueprint && startBlueprint . version
40+ packageRange : startRange
3741 } ,
3842 endOptions : {
3943 blueprint : endBlueprint ,
4044
4145 // for cache detection logic
42- packageVersion : endBlueprint . version
46+ packageRange : endRange
4347 }
4448 } ;
4549} ;
@@ -60,26 +64,57 @@ function getArgs(projectName, blueprint) {
6064 'new' ,
6165 projectName ,
6266 '-sn' ,
67+ '-sb' ,
6368 '-sg' ,
6469 '-b' ,
6570 _blueprint ,
6671 ...blueprint . options
6772 ] ;
6873}
6974
75+ async function runEmberLocally ( {
76+ packageRoot,
77+ args,
78+ cwd
79+ } ) {
80+ await utils . spawn ( 'node' , [
81+ path . join ( packageRoot , 'bin/ember' ) ,
82+ ...args
83+ ] , {
84+ cwd
85+ } ) ;
86+ }
87+
7088function createProjectFromCache ( {
7189 packageRoot,
7290 options
7391} ) {
74- let args = getArgs ( options . projectName , options . blueprint ) ;
75-
7692 return async function createProject ( cwd ) {
77- await utils . spawn ( 'node' , [
78- path . join ( packageRoot , 'bin/ember' ) ,
79- ...args
80- ] , {
81- cwd
82- } ) ;
93+ if ( options . blueprint ) {
94+ let args = getArgs ( options . projectName , options . blueprint ) ;
95+
96+ await runEmberLocally ( {
97+ packageRoot,
98+ args,
99+ cwd
100+ } ) ;
101+
102+ let isCustomBlueprint = options . blueprint . name !== 'ember-cli' ;
103+
104+ if ( isCustomBlueprint ) {
105+ await postCreateCustomBlueprint ( {
106+ cwd,
107+ packageRoot,
108+ options
109+ } ) ;
110+ }
111+ } else {
112+ // We are doing a blueprint init, and need an empty first commit.
113+ await module . exports . createEmptyCommit ( {
114+ cwd,
115+ projectName : options . projectName
116+ } ) ;
117+ }
83118
84119 return postCreateProject ( {
85120 cwd,
@@ -101,20 +136,9 @@ function createProjectFromRemote({
101136 await utils . npx ( `ember-cli ${ command } ` , { cwd } ) ;
102137 // await utils.npx(`-p github:ember-cli/ember-cli#cfb9780 ember new ${options.projectName} -sn -sg -b ${options.blueprint.name}@${options.blueprint.version}`, { cwd });
103138
104- // This means it's not a full app blueprint, but a default blueprint of an addon.
105- // There may be a faster way to detect this.
106- let files = await utils . readdir ( path . join ( cwd , options . projectName ) ) ;
107- if ( ! files . length ) {
108- await module . exports . installAddonBlueprint ( {
109- cwd,
110- projectName : options . projectName ,
111- blueprintPath : options . blueprint . path
112- } ) ;
113- }
114-
115- await module . exports . appendNodeModulesIgnore ( {
139+ await postCreateCustomBlueprint ( {
116140 cwd,
117- projectName : options . projectName
141+ options
118142 } ) ;
119143 } else {
120144 await utils . npx ( `-p ember-cli@${ options . blueprint . version } ember ${ command } ` , { cwd } ) ;
@@ -134,6 +158,29 @@ function createProjectFromRemote({
134158 } ;
135159}
136160
161+ async function postCreateCustomBlueprint ( {
162+ cwd,
163+ packageRoot,
164+ options
165+ } ) {
166+ // This means it's not a full app blueprint, but a default blueprint of an addon.
167+ // There may be a faster way to detect this.
168+ let files = await utils . readdir ( path . join ( cwd , options . projectName ) ) ;
169+ if ( ! files . length ) {
170+ await module . exports . installAddonBlueprint ( {
171+ cwd,
172+ packageRoot,
173+ projectName : options . projectName ,
174+ blueprintPath : options . blueprint . path
175+ } ) ;
176+ }
177+
178+ await module . exports . appendNodeModulesIgnore ( {
179+ cwd,
180+ projectName : options . projectName
181+ } ) ;
182+ }
183+
137184function postCreateProject ( {
138185 cwd,
139186 options : {
@@ -145,18 +192,29 @@ function postCreateProject({
145192
146193module . exports . installAddonBlueprint = async function installAddonBlueprint ( {
147194 cwd,
195+ packageRoot,
148196 projectName,
149197 blueprintPath
150198} ) {
151199 let defaultBlueprint = {
152200 name : 'ember-cli'
153201 } ;
154202
155- let command = getArgs ( projectName , loadSafeBlueprint ( defaultBlueprint ) ) . join ( ' ' ) ;
203+ let args = getArgs ( projectName , loadSafeBlueprint ( defaultBlueprint ) ) ;
156204
157205 await fs . remove ( path . join ( cwd , projectName ) ) ;
158206
159- await utils . npx ( `ember-cli ${ command } ` , { cwd } ) ;
207+ if ( packageRoot ) {
208+ await runEmberLocally ( {
209+ packageRoot,
210+ args,
211+ cwd
212+ } ) ;
213+ } else {
214+ let command = args . join ( ' ' ) ;
215+
216+ await utils . npx ( `ember-cli ${ command } ` , { cwd } ) ;
217+ }
160218
161219 await run ( 'npm install' , { cwd : path . join ( cwd , projectName ) } ) ;
162220
0 commit comments