Skip to content

Commit 71893be

Browse files
committed
fix(cli): display meanful error when not installed locally
1 parent 9644da8 commit 71893be

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

lib/cli.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,14 @@ exports.CLI = class {
2626

2727
return this._establishProject(this.options)
2828
.then(project => {
29-
if (project) {
29+
if (project && this.options.runningLocally) {
3030
this.project = project;
3131
this.container.registerInstance(Project, project);
32-
} else if (this.options.runningLocally) {
32+
} else if (project && this.options.runningGlobally) {
33+
this.logger.error('The current directory is likely an Aurelia-CLI project, but no local installation of Aurelia-CLI could be found. ' +
34+
'(Do you need to restore node modules using npm install?)');
35+
return Promise.resolve();
36+
} else if (!project && this.options.runningLocally) {
3337
this.logger.error('It appears that the Aurelia CLI is running locally from ' + __dirname + '. However, no project directory could be found. ' +
3438
'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');
3539
return Promise.resolve();
@@ -96,10 +100,6 @@ exports.CLI = class {
96100
}
97101

98102
_establishProject(options) {
99-
if (!options.runningLocally) {
100-
return Promise.resolve();
101-
}
102-
103103
return determineWorkingDirectory(process.cwd())
104104
.then(dir => dir ? Project.establish(this.ui, dir) : this.ui.log('No Aurelia project found.'));
105105
}

lib/ui.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ exports.ConsoleUI = class {
120120
let logoLocation = require.resolve('./resources/logo.txt');
121121

122122
return fs.readFile(logoLocation).then(logo => {
123-
console.log(logo.toString());
123+
this.log(logo.toString());
124124
});
125125
}
126126
};

spec/lib/cli.spec.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,12 @@ describe('The cli', () => {
149149
});
150150

151151
it('registers the project instance', done => {
152+
cli.options.runningLocally = true;
153+
152154
spyOn(cli, '_establishProject').and.returnValue(new Promise(resolve => {
153155
resolve(project);
154156
}));
157+
155158
spyOn(cli.container, 'registerInstance');
156159
spyOn(cli, 'createCommand').and.returnValue(Promise.resolve({ execute: () => {} }));
157160

0 commit comments

Comments
 (0)