From 391d1fffbe131e25a88a8d72578a590b1468298c Mon Sep 17 00:00:00 2001 From: Wesley Andrade Soares Date: Fri, 10 Dec 2021 04:43:51 -0300 Subject: [PATCH 1/2] feat: adding permission for the question to be optional --- README.md | 48 +++++++++++++++-------------- examples/tools/items.js | 2 +- src/GenerateTemplateFiles.ts | 6 ++-- src/models/IReplacerSlotQuestion.ts | 1 + 4 files changed, 30 insertions(+), 27 deletions(-) diff --git a/README.md b/README.md index f80e851..1dc0013 100755 --- a/README.md +++ b/README.md @@ -180,11 +180,12 @@ Replacer slot can be any string value you want to use. You can use something lik Below is an example of a `IReplacerSlotQuestion` ```javascript -{question: 'Insert model name', slot: '__model__'} +{question: 'Insert model name', slot: '__model__', optional: true} ``` - `question` - The question to ask the use what value should be used for the replacer `slot` - `slot` - The string value for the [Replacer Slots](#replacer-slots-or-ireplacerslotquestion) +- `optional` - When the question is optional #### Dynamic Replacer Slots @@ -212,17 +213,17 @@ Here is the string `Lives down BY the River` with each of the converters: // If you typed in 'Lives down BY the River' for the a Replacer Slot named '__replacerSlot__' and // used one of the optional Case Converters you would get the following: -__replacerSlot__(noCase) // Lives down BY the River -__replacerSlot__(camelCase) // livesDownByTheRiver -__replacerSlot__(constantCase) // LIVES_DOWN_BY_THE_RIVER -__replacerSlot__(dotCase) // lives.down.by.the.river -__replacerSlot__(kebabCase) // lives-down-by-the-river -__replacerSlot__(lowerCase) // livesdownbytheriver -__replacerSlot__(pascalCase) // LivesDownByTheRiver -__replacerSlot__(pathCase) // lives/down/by/the/river -__replacerSlot__(sentenceCase) // Lives down by the river -__replacerSlot__(snakeCase) // lives_down_by_the_river -__replacerSlot__(titleCase) // Lives Down By The River +__replacerSlot__(noCase); // Lives down BY the River +__replacerSlot__(camelCase); // livesDownByTheRiver +__replacerSlot__(constantCase); // LIVES_DOWN_BY_THE_RIVER +__replacerSlot__(dotCase); // lives.down.by.the.river +__replacerSlot__(kebabCase); // lives-down-by-the-river +__replacerSlot__(lowerCase); // livesdownbytheriver +__replacerSlot__(pascalCase); // LivesDownByTheRiver +__replacerSlot__(pathCase); // lives/down/by/the/river +__replacerSlot__(sentenceCase); // Lives down by the river +__replacerSlot__(snakeCase); // lives_down_by_the_river +__replacerSlot__(titleCase); // Lives Down By The River // Note: you can set a 'defaultCase' converter in IConfigItem so all // Replacer Slots without a Case Converter will be transformed the same way. @@ -232,18 +233,19 @@ __replacerSlot__; // LivesDownByTheRiver You may also specify the case using an underscores-only syntax e.g. `PascalCase__`: ```js -__replacerSlot__NoCase__ // Lives down BY the River -__replacerSlot__CamelCase__ // livesDownByTheRiver -__replacerSlot__ConstantCase__ // LIVES_DOWN_BY_THE_RIVER -__replacerSlot__DotCase__ // lives.down.by.the.river -__replacerSlot__KebabCase__ // lives-down-by-the-river -__replacerSlot__LowerCase__ // livesdownbytheriver -__replacerSlot__PascalCase__ // LivesDownByTheRiver -__replacerSlot__PathCase__ // lives/down/by/the/river -__replacerSlot__SentenceCase__ // Lives down by the river -__replacerSlot__SnakeCase__ // lives_down_by_the_river -__replacerSlot__TitleCase__ // Lives Down By The River +__replacerSlot__NoCase__; // Lives down BY the River +__replacerSlot__CamelCase__; // livesDownByTheRiver +__replacerSlot__ConstantCase__; // LIVES_DOWN_BY_THE_RIVER +__replacerSlot__DotCase__; // lives.down.by.the.river +__replacerSlot__KebabCase__; // lives-down-by-the-river +__replacerSlot__LowerCase__; // livesdownbytheriver +__replacerSlot__PascalCase__; // LivesDownByTheRiver +__replacerSlot__PathCase__; // lives/down/by/the/river +__replacerSlot__SentenceCase__; // Lives down by the river +__replacerSlot__SnakeCase__; // lives_down_by_the_river +__replacerSlot__TitleCase__; // Lives Down By The River ``` + Take your [Replacer Slots](#replacer-slots-or-ireplacerslotquestion) `__replacerSlot__`, the [Case Converters](#case-converters) `PascalCase__` and combine them together to make `__replacerSlot__PascalCase__`. One Rule: no spaces between the [Replacer Slots](#replacer-slots-or-ireplacerslotquestion) and [Case Converters](#case-converters). If there is a space, [Case Converters](#case-converters) will not work. diff --git a/examples/tools/items.js b/examples/tools/items.js index 88bb3e7..252310a 100644 --- a/examples/tools/items.js +++ b/examples/tools/items.js @@ -11,7 +11,7 @@ const items = [ entry: { folderPath: './tools/templates/angular/ngrx-store/', }, - stringReplacers: ['__name__', {question: 'Insert model name', slot: '__model__'}], + stringReplacers: ['__name__', {question: 'Insert model name', slot: '__model__', optional: true}], dynamicReplacers: [ {slot: '__version__', slotValue: config.version}, {slot: '__description__', slotValue: config.description}, diff --git a/src/GenerateTemplateFiles.ts b/src/GenerateTemplateFiles.ts index 10cafb2..ed0f44a 100644 --- a/src/GenerateTemplateFiles.ts +++ b/src/GenerateTemplateFiles.ts @@ -180,13 +180,13 @@ export default class GenerateTemplateFiles { private async _getReplacerSlotValues(selectedConfigItem: IConfigItem): Promise { const stringReplacers: (string | IReplacerSlotQuestion)[] = selectedConfigItem.stringReplacers ?? []; - const replacerQuestions: any[] = stringReplacers.map((item: string | IReplacerSlotQuestion) => { + const replacerQuestions: any[] = stringReplacers.map((item: any | IReplacerSlotQuestion) => { return { type: 'input', - name: StringUtility.isString(item) ? item : item.slot, + name: item.slot, message: StringUtility.isString(item) ? `Replace ${item} with` : item.question, validate: (replacerSlotValue: string) => { - const isValid: boolean = Boolean(replacerSlotValue.trim()); + const isValid: boolean = Boolean(replacerSlotValue.trim() || item.optional); return isValid || 'You must provide an answer.'; }, diff --git a/src/models/IReplacerSlotQuestion.ts b/src/models/IReplacerSlotQuestion.ts index 8ef65b8..cfa5078 100644 --- a/src/models/IReplacerSlotQuestion.ts +++ b/src/models/IReplacerSlotQuestion.ts @@ -1,4 +1,5 @@ export default interface IReplacerSlotQuestion { readonly question: string; readonly slot: string; + readonly optional: boolean; } From 470414804e62019d4402dc6d85f4c18d7b61bf07 Mon Sep 17 00:00:00 2001 From: Wesley A Date: Fri, 10 Dec 2021 04:49:37 -0300 Subject: [PATCH 2/2] feat: adding permission for the question to be optional