From 6c8bc9babf4757319ac61f51592d97962caf8d1a Mon Sep 17 00:00:00 2001 From: Yaapa Hage Date: Sun, 23 Aug 2020 15:51:16 +0530 Subject: [PATCH] chore: apply feedback Apply feedback Signed-off-by: Yaapa Hage --- packages/cli/generators/extension/index.js | 6 ++++++ .../generators/extension/templates/src/component.ts.ejs | 8 ++++---- .../cli/generators/extension/templates/src/keys.ts.ejs | 2 +- .../cli/generators/extension/templates/src/types.ts.ejs | 4 ++-- 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/packages/cli/generators/extension/index.js b/packages/cli/generators/extension/index.js index 027fb28366ee..9188c86c371b 100644 --- a/packages/cli/generators/extension/index.js +++ b/packages/cli/generators/extension/index.js @@ -60,6 +60,12 @@ module.exports = class ExtensionGenerator extends ProjectGenerator { promptOptions() { if (this.shouldExit()) return; + const titleCase = + this.projectInfo.name.charAt(0).toUpperCase() + + this.projectInfo.name.slice(1); + this.projectInfo.optionsInterface = `${titleCase}Options`; + this.projectInfo.bindingsNamespace = `${titleCase}Bindings`; + this.projectInfo.defaultOptions = `DEFAULT_${this.projectInfo.name.toUpperCase()}_OPTIONS`; return super.promptOptions(); } diff --git a/packages/cli/generators/extension/templates/src/component.ts.ejs b/packages/cli/generators/extension/templates/src/component.ts.ejs index 1ebcc1cfeacd..29da0a07fca9 100644 --- a/packages/cli/generators/extension/templates/src/component.ts.ejs +++ b/packages/cli/generators/extension/templates/src/component.ts.ejs @@ -1,13 +1,13 @@ import {Component, ProviderMap} from '@loopback/core'; -import {<%= project.name.charAt(0).toUpperCase() + project.name.slice(1) %>Bindings} from './keys' -import {<%= project.name.toUpperCase() %>_OPTIONS} from './types'; +import {<%= project.bindingsNamespace %>} from './keys' +import {<%= project.defaultOptions %>, <%= project.optionsInterface %>} from './types'; -@bind({tags: {[ContextTags.KEY]: {<%= project.name.charAt(0).toUpperCase() + project.name.slice(1) %>Bindings.COMPONENT}}) +@bind({tags: {[ContextTags.KEY]: {<%= project.bindingsNamespace %>.COMPONENT}}) export class <%= project.componentName %> implements Component { constructor( @inject(CoreBindings.APPLICATION_INSTANCE) private application: Application, @config() - options: Options = <%= project.name.toUpperCase() %>_OPTIONS, + options: <%= project.optionsInterface %> = <%= project.defaultOptions %>, ) {} } diff --git a/packages/cli/generators/extension/templates/src/keys.ts.ejs b/packages/cli/generators/extension/templates/src/keys.ts.ejs index 5e93ae6686f7..3a3dbd02fd2e 100644 --- a/packages/cli/generators/extension/templates/src/keys.ts.ejs +++ b/packages/cli/generators/extension/templates/src/keys.ts.ejs @@ -4,7 +4,7 @@ import {<%= project.componentName %>} from './component'; /** * Binding keys used by this component. */ -export namespace <%= project.name.charAt(0).toUpperCase() + project.name.slice(1) %>Bindings { +export namespace <%= project.bindingsNamespace %> { export const COMPONENT = BindingKey.create<<%= project.componentName %>>( `${CoreBindings.COMPONENTS}.<%= project.componentName %>`, ); diff --git a/packages/cli/generators/extension/templates/src/types.ts.ejs b/packages/cli/generators/extension/templates/src/types.ts.ejs index 8cc7d2f3bbf6..81afe574b9b0 100644 --- a/packages/cli/generators/extension/templates/src/types.ts.ejs +++ b/packages/cli/generators/extension/templates/src/types.ts.ejs @@ -1,7 +1,7 @@ -export interface <%= project.name.charAt(0).toUpperCase() + project.name.slice(1) %>Options { +export interface <%= project.optionsInterface %> { } -export const <%= project.name.toUpperCase() %>_OPTIONS: <%= project.name.charAt(0).toUpperCase() + project.name.slice(1) %>Options = { +export const <%= project.defaultOptions %>: <%= project.optionsInterface %> = { };