Skip to content

Commit

Permalink
fix(cli): use this.exit instead of throwing an error
Browse files Browse the repository at this point in the history
  • Loading branch information
virkt25 committed Jul 31, 2018
1 parent 0601e37 commit 8d25a79
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 13 deletions.
31 changes: 20 additions & 11 deletions packages/cli/generators/controller/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,25 +98,34 @@ module.exports = class ControllerGenerator extends ArtifactGenerator {
) {
return;
}
const modelList = await utils.getArtifactList(
this.artifactInfo.modelDir,
'model',
);
const repositoryList = await utils.getArtifactList(
this.artifactInfo.repositoryDir,
'repository',
true,
);

let modelList, repositoryList;

try {
modelList = await utils.getArtifactList(
this.artifactInfo.modelDir,
'model',
);

repositoryList = await utils.getArtifactList(
this.artifactInfo.repositoryDir,
'repository',
true,
);
} catch (err) {
return this.exit(err);
}

if (_.isEmpty(modelList)) {
throw new Error(
return this.exit(
`No models found in ${this.artifactInfo.modelDir}.
${chalk.yellow(
'Please visit http://loopback.io/doc/en/lb4/Controller-generator.html for information on how models are discovered',
)}`,
);
}
if (_.isEmpty(repositoryList)) {
throw new Error(
return this.exit(
`No repositories found in ${this.artifactInfo.repositoryDir}.
${chalk.yellow(
'Please visit http://loopback.io/doc/en/lb4/Controller-generator.html for information on how repositories are discovered',
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
"unicode-10.0.0": "^0.7.4",
"url-slug": "^2.0.0",
"validate-npm-package-name": "^3.0.0",
"yeoman-generator": "^2.0.3"
"yeoman-generator": "^3.1.1"
},
"scripts": {
"prepublishOnly": "nsp check",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ const testlab = require('@loopback/testlab');
const expect = testlab.expect;
const TestSandbox = testlab.TestSandbox;

const debug = require('../../../lib/debug')('lb4:controller:test');
const ControllerGenerator = require('../../../generators/controller');
const generator = path.join(__dirname, '../../../generators/controller');
const tests = require('../lib/artifact-generator')(generator);
Expand Down

0 comments on commit 8d25a79

Please sign in to comment.