Skip to content

Commit 90c4406

Browse files
committed
fix(cli): add more exit checks to fail fast
1 parent a2ab86d commit 90c4406

File tree

7 files changed

+29
-1
lines changed

7 files changed

+29
-1
lines changed

packages/cli/generators/controller/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ module.exports = class ControllerGenerator extends ArtifactGenerator {
6262
}
6363

6464
checkLoopBackProject() {
65+
if (this.shouldExit()) return;
6566
return super.checkLoopBackProject();
6667
}
6768

packages/cli/generators/datasource/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ module.exports = class DataSourceGenerator extends ArtifactGenerator {
6868
* Ensure CLI is being run in a LoopBack 4 project.
6969
*/
7070
checkLoopBackProject() {
71+
if (this.shouldExit()) return;
7172
return super.checkLoopBackProject();
7273
}
7374

packages/cli/generators/model/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ module.exports = class ModelGenerator extends ArtifactGenerator {
8383
}
8484

8585
checkLoopBackProject() {
86+
if (this.shouldExit()) return;
8687
return super.checkLoopBackProject();
8788
}
8889

@@ -95,6 +96,7 @@ module.exports = class ModelGenerator extends ArtifactGenerator {
9596

9697
// Ask for Model base class
9798
async promptModelBaseClassName() {
99+
if (this.shouldExit()) return;
98100
const availableModelBaseClasses = [];
99101

100102
availableModelBaseClasses.push(...BASE_MODELS);

packages/cli/generators/repository/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ module.exports = class RepositoryGenerator extends ArtifactGenerator {
139139
}
140140

141141
checkLoopBackProject() {
142+
if (this.shouldExit()) return;
142143
return super.checkLoopBackProject();
143144
}
144145

packages/cli/generators/service/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ module.exports = class ServiceGenerator extends ArtifactGenerator {
5959
}
6060

6161
checkLoopBackProject() {
62+
if (this.shouldExit()) return;
6263
return super.checkLoopBackProject();
6364
}
6465

packages/cli/test/integration/generators/model.integration.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ describe('lb4 model integration', () => {
6565
testUtils
6666
.executeGenerator(generator)
6767
.inDir(SANDBOX_PATH, () =>
68-
testUtils.givenLBProject(SANDBOX_PATH, {excludeKeyword: true}),
68+
testUtils.givenLBProject(SANDBOX_PATH, {excludeKeyword: false}),
6969
)
7070
.withArguments('myNewModel --base InvalidModel'),
7171
).to.be.rejectedWith(/Model was not found in/);

packages/cli/test/integration/lib/base-generator.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,27 @@ module.exports = function(generator) {
6666
assert.equal(gen.options.name, 'abc');
6767
assert.equal(gen.options.description, 'Test');
6868
});
69+
70+
it('fails fast if --config has invalid value', async () => {
71+
const gen = testUtils.testSetUpGen(generator, {
72+
args: ['--config', path.join(__dirname, 'base-config-invalid.json')],
73+
});
74+
await gen.setOptions();
75+
assert(gen.exitGeneration instanceof Error);
76+
});
6977
});
7078

7179
describe('config from json value', () => {
7280
const jsonValue = `{
7381
"name": "xyz",
7482
"description": "Test"
7583
}`;
84+
85+
const invalidJsonValue = `{
86+
name: "xyz",
87+
"description": "Test"
88+
}`;
89+
7690
it('accepts --config', async () => {
7791
const gen = testUtils.testSetUpGen(generator, {
7892
args: ['--config', jsonValue],
@@ -91,6 +105,14 @@ module.exports = function(generator) {
91105
assert.equal(gen.options.name, 'abc');
92106
assert.equal(gen.options.description, 'Test');
93107
});
108+
109+
it('fails fast if --config has invalid value', async () => {
110+
const gen = testUtils.testSetUpGen(generator, {
111+
args: ['--config', invalidJsonValue],
112+
});
113+
await gen.setOptions();
114+
assert(gen.exitGeneration instanceof Error);
115+
});
94116
});
95117

96118
describe('config from stdin', () => {

0 commit comments

Comments
 (0)