Skip to content

Adding permission for the question to be optional #73

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 25 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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.
Expand All @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion examples/tools/items.js
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down
6 changes: 3 additions & 3 deletions src/GenerateTemplateFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,13 +180,13 @@ export default class GenerateTemplateFiles {
private async _getReplacerSlotValues(selectedConfigItem: IConfigItem): Promise<IReplacer[]> {
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.';
},
Expand Down
1 change: 1 addition & 0 deletions src/models/IReplacerSlotQuestion.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export default interface IReplacerSlotQuestion {
readonly question: string;
readonly slot: string;
readonly optional: boolean;
}