Skip to content

Commit

Permalink
fix: make sure --applicationName is honored
Browse files Browse the repository at this point in the history
  • Loading branch information
raymondfeng committed Jun 8, 2018
1 parent 50d99ce commit db3600e
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 7 deletions.
2 changes: 1 addition & 1 deletion docs/site/Application-generator.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ lb4 [app] [options] [<name>]

### Options

`--applicationName` : Application name.
`--applicationName` : Application class name.

`--description` : Description of the application.

Expand Down
24 changes: 20 additions & 4 deletions packages/cli/generators/app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,27 @@ module.exports = class AppGenerator extends ProjectGenerator {

this.option('applicationName', {
type: String,
description: 'Application name',
description: 'Application class name',
});

return super._setupGenerator();
}

setOptions() {
return super.setOptions();
async setOptions() {
await super.setOptions();
if (this.shouldExit()) return;
if (this.options.applicationName) {
const clsName = utils.toClassName(this.options.applicationName);
if (typeof clsName === 'string') {
this.projectInfo.applicationName = clsName;
} else if (clsName instanceof Error) {
throw clsName;
}
const msg = utils.validateClassName(clsName);
if (msg !== true) {
throw new Error(msg);
}
}
}

promptProjectName() {
Expand All @@ -45,12 +58,15 @@ module.exports = class AppGenerator extends ProjectGenerator {
message: 'Application class name:',
default: utils.pascalCase(this.projectInfo.name) + 'Application',
validate: utils.validateClassName,
when: this.projectInfo.applicationName == null,
},
];

return this.prompt(prompts).then(props => {
props.applicationName = utils.toClassName(props.applicationName);
Object.assign(this.projectInfo, props);
if (typeof props.applicationName === 'string') {
this.projectInfo.applicationName = props.applicationName;
}
});
}

Expand Down
18 changes: 16 additions & 2 deletions packages/cli/test/integration/generators/app.integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const assert = require('yeoman-assert');
const helpers = require('yeoman-test');
const generator = path.join(__dirname, '../../../generators/app');
const props = {
name: 'myApp',
name: 'my-app',
description: 'My app for LoopBack 4',
};

Expand Down Expand Up @@ -56,7 +56,21 @@ describe('app-generator specific files', () => {
'src/controllers/ping.controller.ts',
/\'\@loopback\/openapi\-v3\'/,
);
});
});

assert.file;
describe('app-generator with --applicationName', () => {
before(() => {
return helpers
.run(generator)
.withOptions({applicationName: 'MyApp'})
.withPrompts(props);
});
it('generates all the proper files', () => {
assert.file('src/application.ts');
assert.fileContent(
'src/application.ts',
/class MyApp extends BootMixin\(RestApplication/,
);
});
});

0 comments on commit db3600e

Please sign in to comment.