22
33const path = require ( 'path' ) ;
44const fs = require ( 'fs-extra' ) ;
5+ const run = require ( './run' ) ;
56const utils = require ( './utils' ) ;
67
78const nodeModulesIgnore = `
@@ -23,7 +24,7 @@ module.exports = function getStartAndEndCommands({
2324 options += ' --yarn' ;
2425 }
2526
26- if ( ! projectOptions . includes ( 'welcome' ) && ! projectOptions . includes ( 'blueprint' ) ) {
27+ if ( ! projectOptions . includes ( 'welcome' ) && startBlueprint && startBlueprint . name === 'ember-cli' ) {
2728 options += ' --no-welcome' ;
2829 }
2930
@@ -40,14 +41,14 @@ module.exports = function getStartAndEndCommands({
4041 return {
4142 projectName,
4243 projectOptions,
43- ...projectOptions . includes ( 'blueprint' ) ? { } : {
44+ ...endBlueprint . name === 'ember-cli' ? {
4445 packageName : 'ember-cli' ,
4546 commandName : 'ember' ,
4647 // `createProjectFromCache` no longer works with custom blueprints.
4748 // It would look for an `ember-cli` version with the same version
4849 // as the blueprint.
4950 createProjectFromCache : createProjectFromCache ( command )
50- } ,
51+ } : { } ,
5152 createProjectFromRemote : createProjectFromRemote ( command ) ,
5253 startOptions : {
5354 packageVersion : startVersion ,
@@ -86,16 +87,36 @@ function createProjectFromRemote(command) {
8687 options
8788 } ) {
8889 return async function createProject ( cwd ) {
89- if ( options . blueprint . name !== 'ember-cli' ) {
90- await utils . npx ( `ember-cli ${ command } -b ${ options . blueprint . path } ` , { cwd } ) ;
91- // await utils.npx(`-p github:ember-cli/ember-cli#cfb9780 ember ${command} -b ${options.blueprint.name}@${options.packageVersion}`, { cwd });
92-
93- await module . exports . appendNodeModulesIgnore ( {
90+ if ( options . blueprint ) {
91+ if ( options . blueprint . name !== 'ember-cli' ) {
92+ await utils . npx ( `ember-cli ${ command } -b ${ options . blueprint . path } ` , { cwd } ) ;
93+ // await utils.npx(`-p github:ember-cli/ember-cli#cfb9780 ember ${command} -b ${options.blueprint.name}@${options.packageVersion}`, { cwd });
94+
95+ // This means it's not a full app blueprint, but a default blueprint of an addon.
96+ // There may be a faster way to detect this.
97+ let files = await utils . readdir ( path . join ( cwd , options . projectName ) ) ;
98+ if ( ! files . length ) {
99+ await module . exports . installAddonBlueprint ( {
100+ cwd,
101+ projectName : options . projectName ,
102+ command,
103+ blueprintPath : options . blueprint . path
104+ } ) ;
105+ }
106+
107+ await module . exports . appendNodeModulesIgnore ( {
108+ cwd,
109+ projectName : options . projectName
110+ } ) ;
111+ } else {
112+ await utils . npx ( `-p ember-cli@${ options . packageVersion } ember ${ command } ` , { cwd } ) ;
113+ }
114+ } else {
115+ // We are doing a blueprint init, and need an empty first commit.
116+ await module . exports . createEmptyCommit ( {
94117 cwd,
95118 projectName : options . projectName
96119 } ) ;
97- } else {
98- await utils . npx ( `-p ember-cli@${ options . packageVersion } ember ${ command } ` , { cwd } ) ;
99120 }
100121
101122 return postCreateProject ( {
@@ -115,6 +136,35 @@ function postCreateProject({
115136 return path . join ( cwd , projectName ) ;
116137}
117138
139+ module . exports . installAddonBlueprint = async function installAddonBlueprint ( {
140+ cwd,
141+ projectName,
142+ command,
143+ blueprintPath
144+ } ) {
145+ await fs . remove ( path . join ( cwd , projectName ) ) ;
146+
147+ await utils . npx ( `ember-cli ${ command } ` , { cwd } ) ;
148+
149+ await run ( 'npm install' , { cwd : path . join ( cwd , projectName ) } ) ;
150+
151+ await utils . npx ( `--no-install ember install ${ blueprintPath } ` , { cwd : path . join ( cwd , projectName ) } ) ;
152+
153+ await fs . remove ( path . join ( cwd , projectName , 'package-lock.json' ) ) ;
154+ } ;
155+
156+ module . exports . createEmptyCommit = async function createEmptyCommit ( {
157+ cwd,
158+ projectName
159+ } ) {
160+ await fs . mkdir ( path . join ( cwd , projectName ) ) ;
161+ await fs . writeFile ( path . join ( cwd , projectName , 'package.json' ) , '{}' ) ;
162+ await appendNodeModulesIgnore ( {
163+ cwd,
164+ projectName
165+ } ) ;
166+ } ;
167+
118168async function appendNodeModulesIgnore ( {
119169 cwd,
120170 projectName
0 commit comments