Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make addAddonsToProject support creating a new project with custom target directory #10048

Merged
merged 1 commit into from Oct 20, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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