Permalink
Browse files

fix(cli): display meanful error when not installed locally

  • Loading branch information...
JeroenVinke committed Mar 26, 2018
1 parent 9644da8 commit 71893beead16f2ed0bd868b413fadf2131008fb5
Showing with 10 additions and 7 deletions.
  1. +6 −6 lib/cli.js
  2. +1 −1 lib/ui.js
  3. +3 −0 spec/lib/cli.spec.js
@@ -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();
@@ -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.'));
}
@@ -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());
});
}
};
@@ -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: () => {} }));

0 comments on commit 71893be

Please sign in to comment.