Skip to content

Commit

Permalink
Merge pull request #10048 from simonihmig/addAddonsToProject-custom-t…
Browse files Browse the repository at this point in the history
…arget

Make addAddonsToProject support creating a new project with custom target directory
  • Loading branch information
ef4 committed Oct 20, 2022
2 parents a637ecc + ea7b66a commit 24ef75b
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions lib/models/blueprint.js
Expand Up @@ -1319,6 +1319,7 @@ let Blueprint = CoreObject.extend({
let installText = packages.length > 1 ? 'install addons' : 'install addon';
this._writeStatusToUI(chalk.green, installText, taskOptions['packages'].join(', '));

let previousCwd;
if (!this.project.isEmberCLIProject()) {
// our blueprint ran *outside* an ember-cli project. So the only way this
// makes sense if the blueprint generated a new project, which we're now
Expand All @@ -1332,13 +1333,24 @@ let Blueprint = CoreObject.extend({
this.project.packageInfoCache._clear();
const Project = require('../../lib/models/project');
this.project = taskOptions.blueprintOptions.project = Project.closestSync(
this.project.root,
options.blueprintOptions.target,
this.project.ui,
this.project.cli
);

// The install task adds dependencies based on the current working directory.
// But in case we created the new project by calling the blueprint with a custom target directory (options.target),
// the current directory will *not* be the one the project is created in, so we must adjust this here.
previousCwd = process.cwd();
process.chdir(options.blueprintOptions.target);
}

let result = this.taskFor('addon-install').run(taskOptions);
if (previousCwd) {
return result.then(() => process.chdir(previousCwd));
}

return this.taskFor('addon-install').run(taskOptions);
return result;
},

/**
Expand Down

0 comments on commit 24ef75b

Please sign in to comment.