Skip to content

Commit

Permalink
fix(cli): display meanful error when not installed locally
Browse files Browse the repository at this point in the history
  • Loading branch information
JeroenVinke committed Mar 26, 2018
1 parent 9644da8 commit 71893be
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
12 changes: 6 additions & 6 deletions lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,14 @@ exports.CLI = class {

return this._establishProject(this.options)
.then(project => {
if (project) {
if (project && this.options.runningLocally) {
this.project = project;
this.container.registerInstance(Project, project);
} else if (this.options.runningLocally) {
} else if (project && this.options.runningGlobally) {
this.logger.error('The current directory is likely an Aurelia-CLI project, but no local installation of Aurelia-CLI could be found. ' +
'(Do you need to restore node modules using npm install?)');
return Promise.resolve();
} else if (!project && this.options.runningLocally) {
this.logger.error('It appears that the Aurelia CLI is running locally from ' + __dirname + '. However, no project directory could be found. ' +
'The Aurelia CLI has to be installed globally (npm install -g aurelia-cli) and locally (npm install aurelia-cli) in an Aurelia CLI project directory');
return Promise.resolve();
Expand Down Expand Up @@ -96,10 +100,6 @@ exports.CLI = class {
}

_establishProject(options) {
if (!options.runningLocally) {
return Promise.resolve();
}

return determineWorkingDirectory(process.cwd())
.then(dir => dir ? Project.establish(this.ui, dir) : this.ui.log('No Aurelia project found.'));
}
Expand Down
2 changes: 1 addition & 1 deletion lib/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ exports.ConsoleUI = class {
let logoLocation = require.resolve('./resources/logo.txt');

return fs.readFile(logoLocation).then(logo => {
console.log(logo.toString());
this.log(logo.toString());
});
}
};
Expand Down
3 changes: 3 additions & 0 deletions spec/lib/cli.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,12 @@ describe('The cli', () => {
});

it('registers the project instance', done => {
cli.options.runningLocally = true;

spyOn(cli, '_establishProject').and.returnValue(new Promise(resolve => {
resolve(project);
}));

spyOn(cli.container, 'registerInstance');
spyOn(cli, 'createCommand').and.returnValue(Promise.resolve({ execute: () => {} }));

Expand Down

0 comments on commit 71893be

Please sign in to comment.