From 46c246b03c78a1c98d46fe61ac6655c9b4295333 Mon Sep 17 00:00:00 2001 From: Santosh Yadav Date: Sun, 3 Mar 2019 19:29:48 +0530 Subject: [PATCH 1/9] refactor(schematics):entity schematics should update the state to plural --- .../schematics-core/utility/ngrx-utils.ts | 2 +- .../schematics-core/utility/strings.ts | 22 +++++++++++++++++-- .../schematics-core/utility/ngrx-utils.ts | 2 +- .../entity/schematics-core/utility/strings.ts | 22 +++++++++++++++++-- .../schematics-core/utility/ngrx-utils.ts | 2 +- .../schematics-core/utility/strings.ts | 22 +++++++++++++++++-- modules/schematics-core/utility/ngrx-utils.ts | 2 +- modules/schematics-core/utility/strings.ts | 22 +++++++++++++++++-- .../schematics-core/utility/ngrx-utils.ts | 2 +- .../schematics-core/utility/strings.ts | 22 +++++++++++++++++-- modules/schematics/src/reducer/index.spec.ts | 2 +- .../schematics-core/utility/ngrx-utils.ts | 2 +- .../schematics-core/utility/strings.ts | 22 +++++++++++++++++-- .../schematics-core/utility/ngrx-utils.ts | 2 +- .../store/schematics-core/utility/strings.ts | 22 +++++++++++++++++-- 15 files changed, 148 insertions(+), 22 deletions(-) diff --git a/modules/effects/schematics-core/utility/ngrx-utils.ts b/modules/effects/schematics-core/utility/ngrx-utils.ts index 28294e1110..2caefcbf7a 100644 --- a/modules/effects/schematics-core/utility/ngrx-utils.ts +++ b/modules/effects/schematics-core/utility/ngrx-utils.ts @@ -91,7 +91,7 @@ export function addReducerToStateInterface( } const keyInsert = - stringUtils.camelize(options.name) + + stringUtils.pluralize(options.name) + ': from' + stringUtils.classify(options.name) + '.State;'; diff --git a/modules/effects/schematics-core/utility/strings.ts b/modules/effects/schematics-core/utility/strings.ts index dae37e563c..1eee8455f4 100644 --- a/modules/effects/schematics-core/utility/strings.ts +++ b/modules/effects/schematics-core/utility/strings.ts @@ -100,16 +100,34 @@ export function underscore(str: string): string { Returns the Capitalized form of a string ```javascript - 'innerHTML'.capitalize() // 'InnerHTML' + 'regex'.capitalize() // 'regexes' 'action_name'.capitalize() // 'Action_name' 'css-class-name'.capitalize() // 'Css-class-name' - 'my favorite items'.capitalize() // 'My favorite items' + 'user'.capitalize() // 'users' ``` */ export function capitalize(str: string): string { return str.charAt(0).toUpperCase() + str.substr(1); } +/** + Returns the Pluralize form of a string + + ```javascript + 'innerHTML'.pluralize() // 'InnerHTMLs' + 'action_name'.pluralize() // 'actionNames' + 'css-class-name'.pluralize() // 'cssClassNames' + 'my favorite items'.pluralize() // 'My favorite items' + ``` + */ +export function pluralize(str: string): string { + return camelize( + [/([^aeiou])y$/, /()fe?$/, /([^aeiou]o|[sxz]|[cs]h)$/].map( + (c, i) => (str = str.replace(c, `$1${'iv'[i] || ''}e`)) + ) && str + 's' + ); +} + export function group(name: string, group: string | undefined) { return group ? `${group}/${name}` : name; } diff --git a/modules/entity/schematics-core/utility/ngrx-utils.ts b/modules/entity/schematics-core/utility/ngrx-utils.ts index 28294e1110..2caefcbf7a 100644 --- a/modules/entity/schematics-core/utility/ngrx-utils.ts +++ b/modules/entity/schematics-core/utility/ngrx-utils.ts @@ -91,7 +91,7 @@ export function addReducerToStateInterface( } const keyInsert = - stringUtils.camelize(options.name) + + stringUtils.pluralize(options.name) + ': from' + stringUtils.classify(options.name) + '.State;'; diff --git a/modules/entity/schematics-core/utility/strings.ts b/modules/entity/schematics-core/utility/strings.ts index dae37e563c..1eee8455f4 100644 --- a/modules/entity/schematics-core/utility/strings.ts +++ b/modules/entity/schematics-core/utility/strings.ts @@ -100,16 +100,34 @@ export function underscore(str: string): string { Returns the Capitalized form of a string ```javascript - 'innerHTML'.capitalize() // 'InnerHTML' + 'regex'.capitalize() // 'regexes' 'action_name'.capitalize() // 'Action_name' 'css-class-name'.capitalize() // 'Css-class-name' - 'my favorite items'.capitalize() // 'My favorite items' + 'user'.capitalize() // 'users' ``` */ export function capitalize(str: string): string { return str.charAt(0).toUpperCase() + str.substr(1); } +/** + Returns the Pluralize form of a string + + ```javascript + 'innerHTML'.pluralize() // 'InnerHTMLs' + 'action_name'.pluralize() // 'actionNames' + 'css-class-name'.pluralize() // 'cssClassNames' + 'my favorite items'.pluralize() // 'My favorite items' + ``` + */ +export function pluralize(str: string): string { + return camelize( + [/([^aeiou])y$/, /()fe?$/, /([^aeiou]o|[sxz]|[cs]h)$/].map( + (c, i) => (str = str.replace(c, `$1${'iv'[i] || ''}e`)) + ) && str + 's' + ); +} + export function group(name: string, group: string | undefined) { return group ? `${group}/${name}` : name; } diff --git a/modules/router-store/schematics-core/utility/ngrx-utils.ts b/modules/router-store/schematics-core/utility/ngrx-utils.ts index 28294e1110..2caefcbf7a 100644 --- a/modules/router-store/schematics-core/utility/ngrx-utils.ts +++ b/modules/router-store/schematics-core/utility/ngrx-utils.ts @@ -91,7 +91,7 @@ export function addReducerToStateInterface( } const keyInsert = - stringUtils.camelize(options.name) + + stringUtils.pluralize(options.name) + ': from' + stringUtils.classify(options.name) + '.State;'; diff --git a/modules/router-store/schematics-core/utility/strings.ts b/modules/router-store/schematics-core/utility/strings.ts index dae37e563c..1eee8455f4 100644 --- a/modules/router-store/schematics-core/utility/strings.ts +++ b/modules/router-store/schematics-core/utility/strings.ts @@ -100,16 +100,34 @@ export function underscore(str: string): string { Returns the Capitalized form of a string ```javascript - 'innerHTML'.capitalize() // 'InnerHTML' + 'regex'.capitalize() // 'regexes' 'action_name'.capitalize() // 'Action_name' 'css-class-name'.capitalize() // 'Css-class-name' - 'my favorite items'.capitalize() // 'My favorite items' + 'user'.capitalize() // 'users' ``` */ export function capitalize(str: string): string { return str.charAt(0).toUpperCase() + str.substr(1); } +/** + Returns the Pluralize form of a string + + ```javascript + 'innerHTML'.pluralize() // 'InnerHTMLs' + 'action_name'.pluralize() // 'actionNames' + 'css-class-name'.pluralize() // 'cssClassNames' + 'my favorite items'.pluralize() // 'My favorite items' + ``` + */ +export function pluralize(str: string): string { + return camelize( + [/([^aeiou])y$/, /()fe?$/, /([^aeiou]o|[sxz]|[cs]h)$/].map( + (c, i) => (str = str.replace(c, `$1${'iv'[i] || ''}e`)) + ) && str + 's' + ); +} + export function group(name: string, group: string | undefined) { return group ? `${group}/${name}` : name; } diff --git a/modules/schematics-core/utility/ngrx-utils.ts b/modules/schematics-core/utility/ngrx-utils.ts index 28294e1110..2caefcbf7a 100644 --- a/modules/schematics-core/utility/ngrx-utils.ts +++ b/modules/schematics-core/utility/ngrx-utils.ts @@ -91,7 +91,7 @@ export function addReducerToStateInterface( } const keyInsert = - stringUtils.camelize(options.name) + + stringUtils.pluralize(options.name) + ': from' + stringUtils.classify(options.name) + '.State;'; diff --git a/modules/schematics-core/utility/strings.ts b/modules/schematics-core/utility/strings.ts index dae37e563c..1eee8455f4 100644 --- a/modules/schematics-core/utility/strings.ts +++ b/modules/schematics-core/utility/strings.ts @@ -100,16 +100,34 @@ export function underscore(str: string): string { Returns the Capitalized form of a string ```javascript - 'innerHTML'.capitalize() // 'InnerHTML' + 'regex'.capitalize() // 'regexes' 'action_name'.capitalize() // 'Action_name' 'css-class-name'.capitalize() // 'Css-class-name' - 'my favorite items'.capitalize() // 'My favorite items' + 'user'.capitalize() // 'users' ``` */ export function capitalize(str: string): string { return str.charAt(0).toUpperCase() + str.substr(1); } +/** + Returns the Pluralize form of a string + + ```javascript + 'innerHTML'.pluralize() // 'InnerHTMLs' + 'action_name'.pluralize() // 'actionNames' + 'css-class-name'.pluralize() // 'cssClassNames' + 'my favorite items'.pluralize() // 'My favorite items' + ``` + */ +export function pluralize(str: string): string { + return camelize( + [/([^aeiou])y$/, /()fe?$/, /([^aeiou]o|[sxz]|[cs]h)$/].map( + (c, i) => (str = str.replace(c, `$1${'iv'[i] || ''}e`)) + ) && str + 's' + ); +} + export function group(name: string, group: string | undefined) { return group ? `${group}/${name}` : name; } diff --git a/modules/schematics/schematics-core/utility/ngrx-utils.ts b/modules/schematics/schematics-core/utility/ngrx-utils.ts index 28294e1110..2caefcbf7a 100644 --- a/modules/schematics/schematics-core/utility/ngrx-utils.ts +++ b/modules/schematics/schematics-core/utility/ngrx-utils.ts @@ -91,7 +91,7 @@ export function addReducerToStateInterface( } const keyInsert = - stringUtils.camelize(options.name) + + stringUtils.pluralize(options.name) + ': from' + stringUtils.classify(options.name) + '.State;'; diff --git a/modules/schematics/schematics-core/utility/strings.ts b/modules/schematics/schematics-core/utility/strings.ts index dae37e563c..1eee8455f4 100644 --- a/modules/schematics/schematics-core/utility/strings.ts +++ b/modules/schematics/schematics-core/utility/strings.ts @@ -100,16 +100,34 @@ export function underscore(str: string): string { Returns the Capitalized form of a string ```javascript - 'innerHTML'.capitalize() // 'InnerHTML' + 'regex'.capitalize() // 'regexes' 'action_name'.capitalize() // 'Action_name' 'css-class-name'.capitalize() // 'Css-class-name' - 'my favorite items'.capitalize() // 'My favorite items' + 'user'.capitalize() // 'users' ``` */ export function capitalize(str: string): string { return str.charAt(0).toUpperCase() + str.substr(1); } +/** + Returns the Pluralize form of a string + + ```javascript + 'innerHTML'.pluralize() // 'InnerHTMLs' + 'action_name'.pluralize() // 'actionNames' + 'css-class-name'.pluralize() // 'cssClassNames' + 'my favorite items'.pluralize() // 'My favorite items' + ``` + */ +export function pluralize(str: string): string { + return camelize( + [/([^aeiou])y$/, /()fe?$/, /([^aeiou]o|[sxz]|[cs]h)$/].map( + (c, i) => (str = str.replace(c, `$1${'iv'[i] || ''}e`)) + ) && str + 's' + ); +} + export function group(name: string, group: string | undefined) { return group ? `${group}/${name}` : name; } diff --git a/modules/schematics/src/reducer/index.spec.ts b/modules/schematics/src/reducer/index.spec.ts index f060c579d3..0532e98473 100644 --- a/modules/schematics/src/reducer/index.spec.ts +++ b/modules/schematics/src/reducer/index.spec.ts @@ -117,7 +117,7 @@ describe('Reducer Schematic', () => { `${projectPath}/src/app/reducers/index.ts` ); - expect(reducers).toMatch(/foo\: fromFoo.State/); + expect(reducers).toMatch(/foos\: fromFoo.State/); }); it('should add the reducer function to the ActionReducerMap', () => { diff --git a/modules/store-devtools/schematics-core/utility/ngrx-utils.ts b/modules/store-devtools/schematics-core/utility/ngrx-utils.ts index 28294e1110..2caefcbf7a 100644 --- a/modules/store-devtools/schematics-core/utility/ngrx-utils.ts +++ b/modules/store-devtools/schematics-core/utility/ngrx-utils.ts @@ -91,7 +91,7 @@ export function addReducerToStateInterface( } const keyInsert = - stringUtils.camelize(options.name) + + stringUtils.pluralize(options.name) + ': from' + stringUtils.classify(options.name) + '.State;'; diff --git a/modules/store-devtools/schematics-core/utility/strings.ts b/modules/store-devtools/schematics-core/utility/strings.ts index dae37e563c..1eee8455f4 100644 --- a/modules/store-devtools/schematics-core/utility/strings.ts +++ b/modules/store-devtools/schematics-core/utility/strings.ts @@ -100,16 +100,34 @@ export function underscore(str: string): string { Returns the Capitalized form of a string ```javascript - 'innerHTML'.capitalize() // 'InnerHTML' + 'regex'.capitalize() // 'regexes' 'action_name'.capitalize() // 'Action_name' 'css-class-name'.capitalize() // 'Css-class-name' - 'my favorite items'.capitalize() // 'My favorite items' + 'user'.capitalize() // 'users' ``` */ export function capitalize(str: string): string { return str.charAt(0).toUpperCase() + str.substr(1); } +/** + Returns the Pluralize form of a string + + ```javascript + 'innerHTML'.pluralize() // 'InnerHTMLs' + 'action_name'.pluralize() // 'actionNames' + 'css-class-name'.pluralize() // 'cssClassNames' + 'my favorite items'.pluralize() // 'My favorite items' + ``` + */ +export function pluralize(str: string): string { + return camelize( + [/([^aeiou])y$/, /()fe?$/, /([^aeiou]o|[sxz]|[cs]h)$/].map( + (c, i) => (str = str.replace(c, `$1${'iv'[i] || ''}e`)) + ) && str + 's' + ); +} + export function group(name: string, group: string | undefined) { return group ? `${group}/${name}` : name; } diff --git a/modules/store/schematics-core/utility/ngrx-utils.ts b/modules/store/schematics-core/utility/ngrx-utils.ts index 28294e1110..2caefcbf7a 100644 --- a/modules/store/schematics-core/utility/ngrx-utils.ts +++ b/modules/store/schematics-core/utility/ngrx-utils.ts @@ -91,7 +91,7 @@ export function addReducerToStateInterface( } const keyInsert = - stringUtils.camelize(options.name) + + stringUtils.pluralize(options.name) + ': from' + stringUtils.classify(options.name) + '.State;'; diff --git a/modules/store/schematics-core/utility/strings.ts b/modules/store/schematics-core/utility/strings.ts index dae37e563c..1eee8455f4 100644 --- a/modules/store/schematics-core/utility/strings.ts +++ b/modules/store/schematics-core/utility/strings.ts @@ -100,16 +100,34 @@ export function underscore(str: string): string { Returns the Capitalized form of a string ```javascript - 'innerHTML'.capitalize() // 'InnerHTML' + 'regex'.capitalize() // 'regexes' 'action_name'.capitalize() // 'Action_name' 'css-class-name'.capitalize() // 'Css-class-name' - 'my favorite items'.capitalize() // 'My favorite items' + 'user'.capitalize() // 'users' ``` */ export function capitalize(str: string): string { return str.charAt(0).toUpperCase() + str.substr(1); } +/** + Returns the Pluralize form of a string + + ```javascript + 'innerHTML'.pluralize() // 'InnerHTMLs' + 'action_name'.pluralize() // 'actionNames' + 'css-class-name'.pluralize() // 'cssClassNames' + 'my favorite items'.pluralize() // 'My favorite items' + ``` + */ +export function pluralize(str: string): string { + return camelize( + [/([^aeiou])y$/, /()fe?$/, /([^aeiou]o|[sxz]|[cs]h)$/].map( + (c, i) => (str = str.replace(c, `$1${'iv'[i] || ''}e`)) + ) && str + 's' + ); +} + export function group(name: string, group: string | undefined) { return group ? `${group}/${name}` : name; } From dbde8bc47e9fbb93dbe36efab864efc6d431af5f Mon Sep 17 00:00:00 2001 From: Santosh Yadav Date: Sun, 3 Mar 2019 19:37:50 +0530 Subject: [PATCH 2/9] changes for reducer --- modules/effects/schematics-core/utility/ngrx-utils.ts | 2 +- modules/entity/schematics-core/utility/ngrx-utils.ts | 2 +- modules/router-store/schematics-core/utility/ngrx-utils.ts | 2 +- modules/schematics-core/utility/ngrx-utils.ts | 2 +- modules/schematics/schematics-core/utility/ngrx-utils.ts | 2 +- modules/schematics/src/reducer/index.spec.ts | 2 +- modules/store-devtools/schematics-core/utility/ngrx-utils.ts | 2 +- modules/store/schematics-core/utility/ngrx-utils.ts | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/modules/effects/schematics-core/utility/ngrx-utils.ts b/modules/effects/schematics-core/utility/ngrx-utils.ts index 2caefcbf7a..2bcf73f497 100644 --- a/modules/effects/schematics-core/utility/ngrx-utils.ts +++ b/modules/effects/schematics-core/utility/ngrx-utils.ts @@ -153,7 +153,7 @@ export function addReducerToActionReducerMap( let node = actionReducerMap.initializer; const keyInsert = - stringUtils.camelize(options.name) + + stringUtils.pluralize(options.name) + ': from' + stringUtils.classify(options.name) + '.reducer,'; diff --git a/modules/entity/schematics-core/utility/ngrx-utils.ts b/modules/entity/schematics-core/utility/ngrx-utils.ts index 2caefcbf7a..2bcf73f497 100644 --- a/modules/entity/schematics-core/utility/ngrx-utils.ts +++ b/modules/entity/schematics-core/utility/ngrx-utils.ts @@ -153,7 +153,7 @@ export function addReducerToActionReducerMap( let node = actionReducerMap.initializer; const keyInsert = - stringUtils.camelize(options.name) + + stringUtils.pluralize(options.name) + ': from' + stringUtils.classify(options.name) + '.reducer,'; diff --git a/modules/router-store/schematics-core/utility/ngrx-utils.ts b/modules/router-store/schematics-core/utility/ngrx-utils.ts index 2caefcbf7a..2bcf73f497 100644 --- a/modules/router-store/schematics-core/utility/ngrx-utils.ts +++ b/modules/router-store/schematics-core/utility/ngrx-utils.ts @@ -153,7 +153,7 @@ export function addReducerToActionReducerMap( let node = actionReducerMap.initializer; const keyInsert = - stringUtils.camelize(options.name) + + stringUtils.pluralize(options.name) + ': from' + stringUtils.classify(options.name) + '.reducer,'; diff --git a/modules/schematics-core/utility/ngrx-utils.ts b/modules/schematics-core/utility/ngrx-utils.ts index 2caefcbf7a..2bcf73f497 100644 --- a/modules/schematics-core/utility/ngrx-utils.ts +++ b/modules/schematics-core/utility/ngrx-utils.ts @@ -153,7 +153,7 @@ export function addReducerToActionReducerMap( let node = actionReducerMap.initializer; const keyInsert = - stringUtils.camelize(options.name) + + stringUtils.pluralize(options.name) + ': from' + stringUtils.classify(options.name) + '.reducer,'; diff --git a/modules/schematics/schematics-core/utility/ngrx-utils.ts b/modules/schematics/schematics-core/utility/ngrx-utils.ts index 2caefcbf7a..2bcf73f497 100644 --- a/modules/schematics/schematics-core/utility/ngrx-utils.ts +++ b/modules/schematics/schematics-core/utility/ngrx-utils.ts @@ -153,7 +153,7 @@ export function addReducerToActionReducerMap( let node = actionReducerMap.initializer; const keyInsert = - stringUtils.camelize(options.name) + + stringUtils.pluralize(options.name) + ': from' + stringUtils.classify(options.name) + '.reducer,'; diff --git a/modules/schematics/src/reducer/index.spec.ts b/modules/schematics/src/reducer/index.spec.ts index 0532e98473..dd624103de 100644 --- a/modules/schematics/src/reducer/index.spec.ts +++ b/modules/schematics/src/reducer/index.spec.ts @@ -128,7 +128,7 @@ describe('Reducer Schematic', () => { `${projectPath}/src/app/reducers/index.ts` ); - expect(reducers).toMatch(/foo\: fromFoo.reducer/); + expect(reducers).toMatch(/foos\: fromFoo.reducer/); }); it('should group within a "reducers" folder if group is set', () => { diff --git a/modules/store-devtools/schematics-core/utility/ngrx-utils.ts b/modules/store-devtools/schematics-core/utility/ngrx-utils.ts index 2caefcbf7a..2bcf73f497 100644 --- a/modules/store-devtools/schematics-core/utility/ngrx-utils.ts +++ b/modules/store-devtools/schematics-core/utility/ngrx-utils.ts @@ -153,7 +153,7 @@ export function addReducerToActionReducerMap( let node = actionReducerMap.initializer; const keyInsert = - stringUtils.camelize(options.name) + + stringUtils.pluralize(options.name) + ': from' + stringUtils.classify(options.name) + '.reducer,'; diff --git a/modules/store/schematics-core/utility/ngrx-utils.ts b/modules/store/schematics-core/utility/ngrx-utils.ts index 2caefcbf7a..2bcf73f497 100644 --- a/modules/store/schematics-core/utility/ngrx-utils.ts +++ b/modules/store/schematics-core/utility/ngrx-utils.ts @@ -153,7 +153,7 @@ export function addReducerToActionReducerMap( let node = actionReducerMap.initializer; const keyInsert = - stringUtils.camelize(options.name) + + stringUtils.pluralize(options.name) + ': from' + stringUtils.classify(options.name) + '.reducer,'; From 2ceba07b45e08757f1ee67157f323c177ce3f682 Mon Sep 17 00:00:00 2001 From: Santosh Yadav Date: Sun, 3 Mar 2019 19:53:24 +0530 Subject: [PATCH 3/9] comments corrected --- modules/effects/schematics-core/utility/strings.ts | 7 ++++--- modules/entity/schematics-core/utility/strings.ts | 7 ++++--- modules/router-store/schematics-core/utility/strings.ts | 7 ++++--- modules/schematics-core/utility/strings.ts | 7 ++++--- modules/schematics/schematics-core/utility/strings.ts | 7 ++++--- modules/store-devtools/schematics-core/utility/strings.ts | 7 ++++--- modules/store/schematics-core/utility/strings.ts | 7 ++++--- 7 files changed, 28 insertions(+), 21 deletions(-) diff --git a/modules/effects/schematics-core/utility/strings.ts b/modules/effects/schematics-core/utility/strings.ts index 1eee8455f4..50cb159740 100644 --- a/modules/effects/schematics-core/utility/strings.ts +++ b/modules/effects/schematics-core/utility/strings.ts @@ -100,10 +100,10 @@ export function underscore(str: string): string { Returns the Capitalized form of a string ```javascript - 'regex'.capitalize() // 'regexes' + 'innerHTML'.capitalize() // 'InnerHTML' 'action_name'.capitalize() // 'Action_name' 'css-class-name'.capitalize() // 'Css-class-name' - 'user'.capitalize() // 'users' + 'my favorite items'.capitalize() // 'My favorite items' ``` */ export function capitalize(str: string): string { @@ -117,7 +117,8 @@ export function capitalize(str: string): string { 'innerHTML'.pluralize() // 'InnerHTMLs' 'action_name'.pluralize() // 'actionNames' 'css-class-name'.pluralize() // 'cssClassNames' - 'my favorite items'.pluralize() // 'My favorite items' + 'regex'.capitalize() // 'regexes' + 'user'.capitalize() // 'users' ``` */ export function pluralize(str: string): string { diff --git a/modules/entity/schematics-core/utility/strings.ts b/modules/entity/schematics-core/utility/strings.ts index 1eee8455f4..50cb159740 100644 --- a/modules/entity/schematics-core/utility/strings.ts +++ b/modules/entity/schematics-core/utility/strings.ts @@ -100,10 +100,10 @@ export function underscore(str: string): string { Returns the Capitalized form of a string ```javascript - 'regex'.capitalize() // 'regexes' + 'innerHTML'.capitalize() // 'InnerHTML' 'action_name'.capitalize() // 'Action_name' 'css-class-name'.capitalize() // 'Css-class-name' - 'user'.capitalize() // 'users' + 'my favorite items'.capitalize() // 'My favorite items' ``` */ export function capitalize(str: string): string { @@ -117,7 +117,8 @@ export function capitalize(str: string): string { 'innerHTML'.pluralize() // 'InnerHTMLs' 'action_name'.pluralize() // 'actionNames' 'css-class-name'.pluralize() // 'cssClassNames' - 'my favorite items'.pluralize() // 'My favorite items' + 'regex'.capitalize() // 'regexes' + 'user'.capitalize() // 'users' ``` */ export function pluralize(str: string): string { diff --git a/modules/router-store/schematics-core/utility/strings.ts b/modules/router-store/schematics-core/utility/strings.ts index 1eee8455f4..50cb159740 100644 --- a/modules/router-store/schematics-core/utility/strings.ts +++ b/modules/router-store/schematics-core/utility/strings.ts @@ -100,10 +100,10 @@ export function underscore(str: string): string { Returns the Capitalized form of a string ```javascript - 'regex'.capitalize() // 'regexes' + 'innerHTML'.capitalize() // 'InnerHTML' 'action_name'.capitalize() // 'Action_name' 'css-class-name'.capitalize() // 'Css-class-name' - 'user'.capitalize() // 'users' + 'my favorite items'.capitalize() // 'My favorite items' ``` */ export function capitalize(str: string): string { @@ -117,7 +117,8 @@ export function capitalize(str: string): string { 'innerHTML'.pluralize() // 'InnerHTMLs' 'action_name'.pluralize() // 'actionNames' 'css-class-name'.pluralize() // 'cssClassNames' - 'my favorite items'.pluralize() // 'My favorite items' + 'regex'.capitalize() // 'regexes' + 'user'.capitalize() // 'users' ``` */ export function pluralize(str: string): string { diff --git a/modules/schematics-core/utility/strings.ts b/modules/schematics-core/utility/strings.ts index 1eee8455f4..50cb159740 100644 --- a/modules/schematics-core/utility/strings.ts +++ b/modules/schematics-core/utility/strings.ts @@ -100,10 +100,10 @@ export function underscore(str: string): string { Returns the Capitalized form of a string ```javascript - 'regex'.capitalize() // 'regexes' + 'innerHTML'.capitalize() // 'InnerHTML' 'action_name'.capitalize() // 'Action_name' 'css-class-name'.capitalize() // 'Css-class-name' - 'user'.capitalize() // 'users' + 'my favorite items'.capitalize() // 'My favorite items' ``` */ export function capitalize(str: string): string { @@ -117,7 +117,8 @@ export function capitalize(str: string): string { 'innerHTML'.pluralize() // 'InnerHTMLs' 'action_name'.pluralize() // 'actionNames' 'css-class-name'.pluralize() // 'cssClassNames' - 'my favorite items'.pluralize() // 'My favorite items' + 'regex'.capitalize() // 'regexes' + 'user'.capitalize() // 'users' ``` */ export function pluralize(str: string): string { diff --git a/modules/schematics/schematics-core/utility/strings.ts b/modules/schematics/schematics-core/utility/strings.ts index 1eee8455f4..50cb159740 100644 --- a/modules/schematics/schematics-core/utility/strings.ts +++ b/modules/schematics/schematics-core/utility/strings.ts @@ -100,10 +100,10 @@ export function underscore(str: string): string { Returns the Capitalized form of a string ```javascript - 'regex'.capitalize() // 'regexes' + 'innerHTML'.capitalize() // 'InnerHTML' 'action_name'.capitalize() // 'Action_name' 'css-class-name'.capitalize() // 'Css-class-name' - 'user'.capitalize() // 'users' + 'my favorite items'.capitalize() // 'My favorite items' ``` */ export function capitalize(str: string): string { @@ -117,7 +117,8 @@ export function capitalize(str: string): string { 'innerHTML'.pluralize() // 'InnerHTMLs' 'action_name'.pluralize() // 'actionNames' 'css-class-name'.pluralize() // 'cssClassNames' - 'my favorite items'.pluralize() // 'My favorite items' + 'regex'.capitalize() // 'regexes' + 'user'.capitalize() // 'users' ``` */ export function pluralize(str: string): string { diff --git a/modules/store-devtools/schematics-core/utility/strings.ts b/modules/store-devtools/schematics-core/utility/strings.ts index 1eee8455f4..50cb159740 100644 --- a/modules/store-devtools/schematics-core/utility/strings.ts +++ b/modules/store-devtools/schematics-core/utility/strings.ts @@ -100,10 +100,10 @@ export function underscore(str: string): string { Returns the Capitalized form of a string ```javascript - 'regex'.capitalize() // 'regexes' + 'innerHTML'.capitalize() // 'InnerHTML' 'action_name'.capitalize() // 'Action_name' 'css-class-name'.capitalize() // 'Css-class-name' - 'user'.capitalize() // 'users' + 'my favorite items'.capitalize() // 'My favorite items' ``` */ export function capitalize(str: string): string { @@ -117,7 +117,8 @@ export function capitalize(str: string): string { 'innerHTML'.pluralize() // 'InnerHTMLs' 'action_name'.pluralize() // 'actionNames' 'css-class-name'.pluralize() // 'cssClassNames' - 'my favorite items'.pluralize() // 'My favorite items' + 'regex'.capitalize() // 'regexes' + 'user'.capitalize() // 'users' ``` */ export function pluralize(str: string): string { diff --git a/modules/store/schematics-core/utility/strings.ts b/modules/store/schematics-core/utility/strings.ts index 1eee8455f4..50cb159740 100644 --- a/modules/store/schematics-core/utility/strings.ts +++ b/modules/store/schematics-core/utility/strings.ts @@ -100,10 +100,10 @@ export function underscore(str: string): string { Returns the Capitalized form of a string ```javascript - 'regex'.capitalize() // 'regexes' + 'innerHTML'.capitalize() // 'InnerHTML' 'action_name'.capitalize() // 'Action_name' 'css-class-name'.capitalize() // 'Css-class-name' - 'user'.capitalize() // 'users' + 'my favorite items'.capitalize() // 'My favorite items' ``` */ export function capitalize(str: string): string { @@ -117,7 +117,8 @@ export function capitalize(str: string): string { 'innerHTML'.pluralize() // 'InnerHTMLs' 'action_name'.pluralize() // 'actionNames' 'css-class-name'.pluralize() // 'cssClassNames' - 'my favorite items'.pluralize() // 'My favorite items' + 'regex'.capitalize() // 'regexes' + 'user'.capitalize() // 'users' ``` */ export function pluralize(str: string): string { From ca25fe4a17dd4d358ef79a180a5429c296ddd201 Mon Sep 17 00:00:00 2001 From: Santosh Yadav Date: Tue, 5 Mar 2019 23:52:28 +0530 Subject: [PATCH 4/9] added test case --- modules/schematics/src/entity/index.spec.ts | 32 +++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/modules/schematics/src/entity/index.spec.ts b/modules/schematics/src/entity/index.spec.ts index 1ae89a8054..fb23e2cfeb 100644 --- a/modules/schematics/src/entity/index.spec.ts +++ b/modules/schematics/src/entity/index.spec.ts @@ -127,6 +127,7 @@ describe('Entity Schematic', () => { const tree = schematicRunner.runSchematic('entity', options, appTree); const files = tree.files; + expect( files.indexOf(`${projectPath}/src/app/foo/actions/foo.actions.ts`) ).toBeGreaterThanOrEqual(0); @@ -146,6 +147,7 @@ describe('Entity Schematic', () => { const tree = schematicRunner.runSchematic('entity', options, appTree); const files = tree.files; + expect( files.indexOf(`${projectPath}/src/app/actions/foo.actions.ts`) ).toBeGreaterThanOrEqual(0); @@ -159,4 +161,34 @@ describe('Entity Schematic', () => { files.indexOf(`${projectPath}/src/app/reducers/foo.reducer.spec.ts`) ).toBeGreaterThanOrEqual(0); }); + + it('should create all files of an entity within grouped and nested folders', () => { + const options = { + ...defaultOptions, + name: 'user', + reducers: 'reducers/index.ts', + spec: true, + }; + + const reducerTree = schematicRunner.runSchematic('store', options, appTree); + const tree = schematicRunner.runSchematic('entity', options, appTree); + const files = tree.files; + const content = tree.readContent( + `${projectPath}/src/app/reducers/index.ts` + ); + expect( + files.indexOf(`${projectPath}/src/app/user.actions.ts`) + ).toBeGreaterThanOrEqual(0); + expect( + files.indexOf(`${projectPath}/src/app/user.model.ts`) + ).toBeGreaterThanOrEqual(0); + expect( + files.indexOf(`${projectPath}/src/app/user.reducer.ts`) + ).toBeGreaterThanOrEqual(0); + expect( + files.indexOf(`${projectPath}/src/app/user.reducer.spec.ts`) + ).toBeGreaterThanOrEqual(0); + expect(content).toMatch(/users\: fromUser.State/); + expect(content).toMatch(/users\: fromUser.reducer/); + }); }); From 672f6038a1194de6be4ff29ed47a3a1829c549ee Mon Sep 17 00:00:00 2001 From: Santosh Yadav Date: Fri, 8 Mar 2019 22:25:48 +0530 Subject: [PATCH 5/9] changes to restrict plural to entity --- modules/effects/schematics-core/BUILD.bazel | 17 +++++++++++++ .../schematics-core/utility/ngrx-utils.ts | 24 +++++++++++-------- modules/entity/schematics-core/BUILD.bazel | 17 +++++++++++++ .../schematics-core/utility/ngrx-utils.ts | 24 +++++++++++-------- .../router-store/schematics-core/BUILD.bazel | 17 +++++++++++++ .../schematics-core/utility/ngrx-utils.ts | 24 +++++++++++-------- modules/schematics-core/utility/ngrx-utils.ts | 24 +++++++++++-------- .../schematics/schematics-core/BUILD.bazel | 17 +++++++++++++ .../schematics-core/utility/ngrx-utils.ts | 24 +++++++++++-------- modules/schematics/src/entity/index.ts | 1 + modules/schematics/src/entity/schema.json | 5 ++++ modules/schematics/src/entity/schema.ts | 5 ++++ modules/schematics/src/reducer/index.spec.ts | 4 ++-- .../schematics-core/BUILD.bazel | 17 +++++++++++++ .../schematics-core/utility/ngrx-utils.ts | 24 +++++++++++-------- modules/store/schematics-core/BUILD.bazel | 17 +++++++++++++ .../schematics-core/utility/ngrx-utils.ts | 24 +++++++++++-------- 17 files changed, 213 insertions(+), 72 deletions(-) create mode 100644 modules/effects/schematics-core/BUILD.bazel create mode 100644 modules/entity/schematics-core/BUILD.bazel create mode 100644 modules/router-store/schematics-core/BUILD.bazel create mode 100644 modules/schematics/schematics-core/BUILD.bazel create mode 100644 modules/store-devtools/schematics-core/BUILD.bazel create mode 100644 modules/store/schematics-core/BUILD.bazel diff --git a/modules/effects/schematics-core/BUILD.bazel b/modules/effects/schematics-core/BUILD.bazel new file mode 100644 index 0000000000..01f4701f2b --- /dev/null +++ b/modules/effects/schematics-core/BUILD.bazel @@ -0,0 +1,17 @@ +package(default_visibility = ["//visibility:public"]) + +load("//tools:defaults.bzl", "ts_library") + +ts_library( + name = "schematics-core", + srcs = glob( + [ + "**/*.ts", + ], + ), + deps = [ + "@npm//@angular-devkit/core", + "@npm//@angular-devkit/schematics", + "@npm//typescript", + ], +) diff --git a/modules/effects/schematics-core/utility/ngrx-utils.ts b/modules/effects/schematics-core/utility/ngrx-utils.ts index 2bcf73f497..8d9570baaa 100644 --- a/modules/effects/schematics-core/utility/ngrx-utils.ts +++ b/modules/effects/schematics-core/utility/ngrx-utils.ts @@ -79,7 +79,7 @@ export function addReducerToState(options: any): Rule { export function addReducerToStateInterface( source: ts.SourceFile, reducersPath: string, - options: { name: string } + options: { name: string; plural: boolean } ): Change { const stateInterface = source.statements.find( stm => stm.kind === ts.SyntaxKind.InterfaceDeclaration @@ -90,11 +90,13 @@ export function addReducerToStateInterface( return new NoopChange(); } + const state = + options.plural === undefined + ? stringUtils.camelize(options.name) + : stringUtils.camelize(options.name) + 's'; + console.log(state); const keyInsert = - stringUtils.pluralize(options.name) + - ': from' + - stringUtils.classify(options.name) + - '.State;'; + state + ': from' + stringUtils.classify(options.name) + '.State;'; const expr = node as any; let position; let toInsert; @@ -125,7 +127,7 @@ export function addReducerToStateInterface( export function addReducerToActionReducerMap( source: ts.SourceFile, reducersPath: string, - options: { name: string } + options: { name: string; plural: boolean } ): Change { let initializer: any; const actionReducerMap: any = source.statements @@ -152,11 +154,13 @@ export function addReducerToActionReducerMap( let node = actionReducerMap.initializer; + const state = + options.plural === undefined + ? stringUtils.camelize(options.name) + : stringUtils.camelize(options.name) + 's'; + console.log(state); const keyInsert = - stringUtils.pluralize(options.name) + - ': from' + - stringUtils.classify(options.name) + - '.reducer,'; + state + ': from' + stringUtils.classify(options.name) + '.reducer,'; const expr = node as any; let position; let toInsert; diff --git a/modules/entity/schematics-core/BUILD.bazel b/modules/entity/schematics-core/BUILD.bazel new file mode 100644 index 0000000000..01f4701f2b --- /dev/null +++ b/modules/entity/schematics-core/BUILD.bazel @@ -0,0 +1,17 @@ +package(default_visibility = ["//visibility:public"]) + +load("//tools:defaults.bzl", "ts_library") + +ts_library( + name = "schematics-core", + srcs = glob( + [ + "**/*.ts", + ], + ), + deps = [ + "@npm//@angular-devkit/core", + "@npm//@angular-devkit/schematics", + "@npm//typescript", + ], +) diff --git a/modules/entity/schematics-core/utility/ngrx-utils.ts b/modules/entity/schematics-core/utility/ngrx-utils.ts index 2bcf73f497..8d9570baaa 100644 --- a/modules/entity/schematics-core/utility/ngrx-utils.ts +++ b/modules/entity/schematics-core/utility/ngrx-utils.ts @@ -79,7 +79,7 @@ export function addReducerToState(options: any): Rule { export function addReducerToStateInterface( source: ts.SourceFile, reducersPath: string, - options: { name: string } + options: { name: string; plural: boolean } ): Change { const stateInterface = source.statements.find( stm => stm.kind === ts.SyntaxKind.InterfaceDeclaration @@ -90,11 +90,13 @@ export function addReducerToStateInterface( return new NoopChange(); } + const state = + options.plural === undefined + ? stringUtils.camelize(options.name) + : stringUtils.camelize(options.name) + 's'; + console.log(state); const keyInsert = - stringUtils.pluralize(options.name) + - ': from' + - stringUtils.classify(options.name) + - '.State;'; + state + ': from' + stringUtils.classify(options.name) + '.State;'; const expr = node as any; let position; let toInsert; @@ -125,7 +127,7 @@ export function addReducerToStateInterface( export function addReducerToActionReducerMap( source: ts.SourceFile, reducersPath: string, - options: { name: string } + options: { name: string; plural: boolean } ): Change { let initializer: any; const actionReducerMap: any = source.statements @@ -152,11 +154,13 @@ export function addReducerToActionReducerMap( let node = actionReducerMap.initializer; + const state = + options.plural === undefined + ? stringUtils.camelize(options.name) + : stringUtils.camelize(options.name) + 's'; + console.log(state); const keyInsert = - stringUtils.pluralize(options.name) + - ': from' + - stringUtils.classify(options.name) + - '.reducer,'; + state + ': from' + stringUtils.classify(options.name) + '.reducer,'; const expr = node as any; let position; let toInsert; diff --git a/modules/router-store/schematics-core/BUILD.bazel b/modules/router-store/schematics-core/BUILD.bazel new file mode 100644 index 0000000000..01f4701f2b --- /dev/null +++ b/modules/router-store/schematics-core/BUILD.bazel @@ -0,0 +1,17 @@ +package(default_visibility = ["//visibility:public"]) + +load("//tools:defaults.bzl", "ts_library") + +ts_library( + name = "schematics-core", + srcs = glob( + [ + "**/*.ts", + ], + ), + deps = [ + "@npm//@angular-devkit/core", + "@npm//@angular-devkit/schematics", + "@npm//typescript", + ], +) diff --git a/modules/router-store/schematics-core/utility/ngrx-utils.ts b/modules/router-store/schematics-core/utility/ngrx-utils.ts index 2bcf73f497..8d9570baaa 100644 --- a/modules/router-store/schematics-core/utility/ngrx-utils.ts +++ b/modules/router-store/schematics-core/utility/ngrx-utils.ts @@ -79,7 +79,7 @@ export function addReducerToState(options: any): Rule { export function addReducerToStateInterface( source: ts.SourceFile, reducersPath: string, - options: { name: string } + options: { name: string; plural: boolean } ): Change { const stateInterface = source.statements.find( stm => stm.kind === ts.SyntaxKind.InterfaceDeclaration @@ -90,11 +90,13 @@ export function addReducerToStateInterface( return new NoopChange(); } + const state = + options.plural === undefined + ? stringUtils.camelize(options.name) + : stringUtils.camelize(options.name) + 's'; + console.log(state); const keyInsert = - stringUtils.pluralize(options.name) + - ': from' + - stringUtils.classify(options.name) + - '.State;'; + state + ': from' + stringUtils.classify(options.name) + '.State;'; const expr = node as any; let position; let toInsert; @@ -125,7 +127,7 @@ export function addReducerToStateInterface( export function addReducerToActionReducerMap( source: ts.SourceFile, reducersPath: string, - options: { name: string } + options: { name: string; plural: boolean } ): Change { let initializer: any; const actionReducerMap: any = source.statements @@ -152,11 +154,13 @@ export function addReducerToActionReducerMap( let node = actionReducerMap.initializer; + const state = + options.plural === undefined + ? stringUtils.camelize(options.name) + : stringUtils.camelize(options.name) + 's'; + console.log(state); const keyInsert = - stringUtils.pluralize(options.name) + - ': from' + - stringUtils.classify(options.name) + - '.reducer,'; + state + ': from' + stringUtils.classify(options.name) + '.reducer,'; const expr = node as any; let position; let toInsert; diff --git a/modules/schematics-core/utility/ngrx-utils.ts b/modules/schematics-core/utility/ngrx-utils.ts index 2bcf73f497..8d9570baaa 100644 --- a/modules/schematics-core/utility/ngrx-utils.ts +++ b/modules/schematics-core/utility/ngrx-utils.ts @@ -79,7 +79,7 @@ export function addReducerToState(options: any): Rule { export function addReducerToStateInterface( source: ts.SourceFile, reducersPath: string, - options: { name: string } + options: { name: string; plural: boolean } ): Change { const stateInterface = source.statements.find( stm => stm.kind === ts.SyntaxKind.InterfaceDeclaration @@ -90,11 +90,13 @@ export function addReducerToStateInterface( return new NoopChange(); } + const state = + options.plural === undefined + ? stringUtils.camelize(options.name) + : stringUtils.camelize(options.name) + 's'; + console.log(state); const keyInsert = - stringUtils.pluralize(options.name) + - ': from' + - stringUtils.classify(options.name) + - '.State;'; + state + ': from' + stringUtils.classify(options.name) + '.State;'; const expr = node as any; let position; let toInsert; @@ -125,7 +127,7 @@ export function addReducerToStateInterface( export function addReducerToActionReducerMap( source: ts.SourceFile, reducersPath: string, - options: { name: string } + options: { name: string; plural: boolean } ): Change { let initializer: any; const actionReducerMap: any = source.statements @@ -152,11 +154,13 @@ export function addReducerToActionReducerMap( let node = actionReducerMap.initializer; + const state = + options.plural === undefined + ? stringUtils.camelize(options.name) + : stringUtils.camelize(options.name) + 's'; + console.log(state); const keyInsert = - stringUtils.pluralize(options.name) + - ': from' + - stringUtils.classify(options.name) + - '.reducer,'; + state + ': from' + stringUtils.classify(options.name) + '.reducer,'; const expr = node as any; let position; let toInsert; diff --git a/modules/schematics/schematics-core/BUILD.bazel b/modules/schematics/schematics-core/BUILD.bazel new file mode 100644 index 0000000000..01f4701f2b --- /dev/null +++ b/modules/schematics/schematics-core/BUILD.bazel @@ -0,0 +1,17 @@ +package(default_visibility = ["//visibility:public"]) + +load("//tools:defaults.bzl", "ts_library") + +ts_library( + name = "schematics-core", + srcs = glob( + [ + "**/*.ts", + ], + ), + deps = [ + "@npm//@angular-devkit/core", + "@npm//@angular-devkit/schematics", + "@npm//typescript", + ], +) diff --git a/modules/schematics/schematics-core/utility/ngrx-utils.ts b/modules/schematics/schematics-core/utility/ngrx-utils.ts index 2bcf73f497..8d9570baaa 100644 --- a/modules/schematics/schematics-core/utility/ngrx-utils.ts +++ b/modules/schematics/schematics-core/utility/ngrx-utils.ts @@ -79,7 +79,7 @@ export function addReducerToState(options: any): Rule { export function addReducerToStateInterface( source: ts.SourceFile, reducersPath: string, - options: { name: string } + options: { name: string; plural: boolean } ): Change { const stateInterface = source.statements.find( stm => stm.kind === ts.SyntaxKind.InterfaceDeclaration @@ -90,11 +90,13 @@ export function addReducerToStateInterface( return new NoopChange(); } + const state = + options.plural === undefined + ? stringUtils.camelize(options.name) + : stringUtils.camelize(options.name) + 's'; + console.log(state); const keyInsert = - stringUtils.pluralize(options.name) + - ': from' + - stringUtils.classify(options.name) + - '.State;'; + state + ': from' + stringUtils.classify(options.name) + '.State;'; const expr = node as any; let position; let toInsert; @@ -125,7 +127,7 @@ export function addReducerToStateInterface( export function addReducerToActionReducerMap( source: ts.SourceFile, reducersPath: string, - options: { name: string } + options: { name: string; plural: boolean } ): Change { let initializer: any; const actionReducerMap: any = source.statements @@ -152,11 +154,13 @@ export function addReducerToActionReducerMap( let node = actionReducerMap.initializer; + const state = + options.plural === undefined + ? stringUtils.camelize(options.name) + : stringUtils.camelize(options.name) + 's'; + console.log(state); const keyInsert = - stringUtils.pluralize(options.name) + - ': from' + - stringUtils.classify(options.name) + - '.reducer,'; + state + ': from' + stringUtils.classify(options.name) + '.reducer,'; const expr = node as any; let position; let toInsert; diff --git a/modules/schematics/src/entity/index.ts b/modules/schematics/src/entity/index.ts index 4278b6ad9e..bbdf70be63 100644 --- a/modules/schematics/src/entity/index.ts +++ b/modules/schematics/src/entity/index.ts @@ -31,6 +31,7 @@ export default function(options: EntityOptions): Rule { const parsedPath = parseName(options.path, options.name); options.name = parsedPath.name; options.path = parsedPath.path; + options.plural = true; if (options.module) { options.module = findModuleFromOptions(host, options); diff --git a/modules/schematics/src/entity/schema.json b/modules/schematics/src/entity/schema.json index 0bd229520c..7fe33e9b50 100644 --- a/modules/schematics/src/entity/schema.json +++ b/modules/schematics/src/entity/schema.json @@ -49,6 +49,11 @@ "description": "Group actions, reducers and effects within relative subfolders", "aliases": ["g"] + }, + "plural": { + "type": "boolean", + "default": true, + "description": "Update state with plural." } }, "required": [] diff --git a/modules/schematics/src/entity/schema.ts b/modules/schematics/src/entity/schema.ts index 82b0f13ffe..98cce4d77d 100644 --- a/modules/schematics/src/entity/schema.ts +++ b/modules/schematics/src/entity/schema.ts @@ -36,4 +36,9 @@ export interface Schema { */ group?: boolean; + /** + * Specifies if this is state and reducer variable will be plural + */ + + plural?: boolean; } diff --git a/modules/schematics/src/reducer/index.spec.ts b/modules/schematics/src/reducer/index.spec.ts index dd624103de..f060c579d3 100644 --- a/modules/schematics/src/reducer/index.spec.ts +++ b/modules/schematics/src/reducer/index.spec.ts @@ -117,7 +117,7 @@ describe('Reducer Schematic', () => { `${projectPath}/src/app/reducers/index.ts` ); - expect(reducers).toMatch(/foos\: fromFoo.State/); + expect(reducers).toMatch(/foo\: fromFoo.State/); }); it('should add the reducer function to the ActionReducerMap', () => { @@ -128,7 +128,7 @@ describe('Reducer Schematic', () => { `${projectPath}/src/app/reducers/index.ts` ); - expect(reducers).toMatch(/foos\: fromFoo.reducer/); + expect(reducers).toMatch(/foo\: fromFoo.reducer/); }); it('should group within a "reducers" folder if group is set', () => { diff --git a/modules/store-devtools/schematics-core/BUILD.bazel b/modules/store-devtools/schematics-core/BUILD.bazel new file mode 100644 index 0000000000..01f4701f2b --- /dev/null +++ b/modules/store-devtools/schematics-core/BUILD.bazel @@ -0,0 +1,17 @@ +package(default_visibility = ["//visibility:public"]) + +load("//tools:defaults.bzl", "ts_library") + +ts_library( + name = "schematics-core", + srcs = glob( + [ + "**/*.ts", + ], + ), + deps = [ + "@npm//@angular-devkit/core", + "@npm//@angular-devkit/schematics", + "@npm//typescript", + ], +) diff --git a/modules/store-devtools/schematics-core/utility/ngrx-utils.ts b/modules/store-devtools/schematics-core/utility/ngrx-utils.ts index 2bcf73f497..8d9570baaa 100644 --- a/modules/store-devtools/schematics-core/utility/ngrx-utils.ts +++ b/modules/store-devtools/schematics-core/utility/ngrx-utils.ts @@ -79,7 +79,7 @@ export function addReducerToState(options: any): Rule { export function addReducerToStateInterface( source: ts.SourceFile, reducersPath: string, - options: { name: string } + options: { name: string; plural: boolean } ): Change { const stateInterface = source.statements.find( stm => stm.kind === ts.SyntaxKind.InterfaceDeclaration @@ -90,11 +90,13 @@ export function addReducerToStateInterface( return new NoopChange(); } + const state = + options.plural === undefined + ? stringUtils.camelize(options.name) + : stringUtils.camelize(options.name) + 's'; + console.log(state); const keyInsert = - stringUtils.pluralize(options.name) + - ': from' + - stringUtils.classify(options.name) + - '.State;'; + state + ': from' + stringUtils.classify(options.name) + '.State;'; const expr = node as any; let position; let toInsert; @@ -125,7 +127,7 @@ export function addReducerToStateInterface( export function addReducerToActionReducerMap( source: ts.SourceFile, reducersPath: string, - options: { name: string } + options: { name: string; plural: boolean } ): Change { let initializer: any; const actionReducerMap: any = source.statements @@ -152,11 +154,13 @@ export function addReducerToActionReducerMap( let node = actionReducerMap.initializer; + const state = + options.plural === undefined + ? stringUtils.camelize(options.name) + : stringUtils.camelize(options.name) + 's'; + console.log(state); const keyInsert = - stringUtils.pluralize(options.name) + - ': from' + - stringUtils.classify(options.name) + - '.reducer,'; + state + ': from' + stringUtils.classify(options.name) + '.reducer,'; const expr = node as any; let position; let toInsert; diff --git a/modules/store/schematics-core/BUILD.bazel b/modules/store/schematics-core/BUILD.bazel new file mode 100644 index 0000000000..01f4701f2b --- /dev/null +++ b/modules/store/schematics-core/BUILD.bazel @@ -0,0 +1,17 @@ +package(default_visibility = ["//visibility:public"]) + +load("//tools:defaults.bzl", "ts_library") + +ts_library( + name = "schematics-core", + srcs = glob( + [ + "**/*.ts", + ], + ), + deps = [ + "@npm//@angular-devkit/core", + "@npm//@angular-devkit/schematics", + "@npm//typescript", + ], +) diff --git a/modules/store/schematics-core/utility/ngrx-utils.ts b/modules/store/schematics-core/utility/ngrx-utils.ts index 2bcf73f497..8d9570baaa 100644 --- a/modules/store/schematics-core/utility/ngrx-utils.ts +++ b/modules/store/schematics-core/utility/ngrx-utils.ts @@ -79,7 +79,7 @@ export function addReducerToState(options: any): Rule { export function addReducerToStateInterface( source: ts.SourceFile, reducersPath: string, - options: { name: string } + options: { name: string; plural: boolean } ): Change { const stateInterface = source.statements.find( stm => stm.kind === ts.SyntaxKind.InterfaceDeclaration @@ -90,11 +90,13 @@ export function addReducerToStateInterface( return new NoopChange(); } + const state = + options.plural === undefined + ? stringUtils.camelize(options.name) + : stringUtils.camelize(options.name) + 's'; + console.log(state); const keyInsert = - stringUtils.pluralize(options.name) + - ': from' + - stringUtils.classify(options.name) + - '.State;'; + state + ': from' + stringUtils.classify(options.name) + '.State;'; const expr = node as any; let position; let toInsert; @@ -125,7 +127,7 @@ export function addReducerToStateInterface( export function addReducerToActionReducerMap( source: ts.SourceFile, reducersPath: string, - options: { name: string } + options: { name: string; plural: boolean } ): Change { let initializer: any; const actionReducerMap: any = source.statements @@ -152,11 +154,13 @@ export function addReducerToActionReducerMap( let node = actionReducerMap.initializer; + const state = + options.plural === undefined + ? stringUtils.camelize(options.name) + : stringUtils.camelize(options.name) + 's'; + console.log(state); const keyInsert = - stringUtils.pluralize(options.name) + - ': from' + - stringUtils.classify(options.name) + - '.reducer,'; + state + ': from' + stringUtils.classify(options.name) + '.reducer,'; const expr = node as any; let position; let toInsert; From ed6655d7111fef770b1baed4a0795e923e0c1aab Mon Sep 17 00:00:00 2001 From: Santosh Yadav Date: Fri, 8 Mar 2019 22:30:28 +0530 Subject: [PATCH 6/9] removed console --- modules/effects/schematics-core/utility/ngrx-utils.ts | 4 ++-- modules/entity/schematics-core/utility/ngrx-utils.ts | 4 ++-- modules/router-store/schematics-core/utility/ngrx-utils.ts | 4 ++-- modules/schematics-core/utility/ngrx-utils.ts | 4 ++-- modules/schematics/schematics-core/utility/ngrx-utils.ts | 4 ++-- modules/store-devtools/schematics-core/utility/ngrx-utils.ts | 4 ++-- modules/store/schematics-core/utility/ngrx-utils.ts | 4 ++-- 7 files changed, 14 insertions(+), 14 deletions(-) diff --git a/modules/effects/schematics-core/utility/ngrx-utils.ts b/modules/effects/schematics-core/utility/ngrx-utils.ts index 8d9570baaa..56ee0b4cf3 100644 --- a/modules/effects/schematics-core/utility/ngrx-utils.ts +++ b/modules/effects/schematics-core/utility/ngrx-utils.ts @@ -94,7 +94,7 @@ export function addReducerToStateInterface( options.plural === undefined ? stringUtils.camelize(options.name) : stringUtils.camelize(options.name) + 's'; - console.log(state); + const keyInsert = state + ': from' + stringUtils.classify(options.name) + '.State;'; const expr = node as any; @@ -158,7 +158,7 @@ export function addReducerToActionReducerMap( options.plural === undefined ? stringUtils.camelize(options.name) : stringUtils.camelize(options.name) + 's'; - console.log(state); + const keyInsert = state + ': from' + stringUtils.classify(options.name) + '.reducer,'; const expr = node as any; diff --git a/modules/entity/schematics-core/utility/ngrx-utils.ts b/modules/entity/schematics-core/utility/ngrx-utils.ts index 8d9570baaa..56ee0b4cf3 100644 --- a/modules/entity/schematics-core/utility/ngrx-utils.ts +++ b/modules/entity/schematics-core/utility/ngrx-utils.ts @@ -94,7 +94,7 @@ export function addReducerToStateInterface( options.plural === undefined ? stringUtils.camelize(options.name) : stringUtils.camelize(options.name) + 's'; - console.log(state); + const keyInsert = state + ': from' + stringUtils.classify(options.name) + '.State;'; const expr = node as any; @@ -158,7 +158,7 @@ export function addReducerToActionReducerMap( options.plural === undefined ? stringUtils.camelize(options.name) : stringUtils.camelize(options.name) + 's'; - console.log(state); + const keyInsert = state + ': from' + stringUtils.classify(options.name) + '.reducer,'; const expr = node as any; diff --git a/modules/router-store/schematics-core/utility/ngrx-utils.ts b/modules/router-store/schematics-core/utility/ngrx-utils.ts index 8d9570baaa..56ee0b4cf3 100644 --- a/modules/router-store/schematics-core/utility/ngrx-utils.ts +++ b/modules/router-store/schematics-core/utility/ngrx-utils.ts @@ -94,7 +94,7 @@ export function addReducerToStateInterface( options.plural === undefined ? stringUtils.camelize(options.name) : stringUtils.camelize(options.name) + 's'; - console.log(state); + const keyInsert = state + ': from' + stringUtils.classify(options.name) + '.State;'; const expr = node as any; @@ -158,7 +158,7 @@ export function addReducerToActionReducerMap( options.plural === undefined ? stringUtils.camelize(options.name) : stringUtils.camelize(options.name) + 's'; - console.log(state); + const keyInsert = state + ': from' + stringUtils.classify(options.name) + '.reducer,'; const expr = node as any; diff --git a/modules/schematics-core/utility/ngrx-utils.ts b/modules/schematics-core/utility/ngrx-utils.ts index 8d9570baaa..56ee0b4cf3 100644 --- a/modules/schematics-core/utility/ngrx-utils.ts +++ b/modules/schematics-core/utility/ngrx-utils.ts @@ -94,7 +94,7 @@ export function addReducerToStateInterface( options.plural === undefined ? stringUtils.camelize(options.name) : stringUtils.camelize(options.name) + 's'; - console.log(state); + const keyInsert = state + ': from' + stringUtils.classify(options.name) + '.State;'; const expr = node as any; @@ -158,7 +158,7 @@ export function addReducerToActionReducerMap( options.plural === undefined ? stringUtils.camelize(options.name) : stringUtils.camelize(options.name) + 's'; - console.log(state); + const keyInsert = state + ': from' + stringUtils.classify(options.name) + '.reducer,'; const expr = node as any; diff --git a/modules/schematics/schematics-core/utility/ngrx-utils.ts b/modules/schematics/schematics-core/utility/ngrx-utils.ts index 8d9570baaa..56ee0b4cf3 100644 --- a/modules/schematics/schematics-core/utility/ngrx-utils.ts +++ b/modules/schematics/schematics-core/utility/ngrx-utils.ts @@ -94,7 +94,7 @@ export function addReducerToStateInterface( options.plural === undefined ? stringUtils.camelize(options.name) : stringUtils.camelize(options.name) + 's'; - console.log(state); + const keyInsert = state + ': from' + stringUtils.classify(options.name) + '.State;'; const expr = node as any; @@ -158,7 +158,7 @@ export function addReducerToActionReducerMap( options.plural === undefined ? stringUtils.camelize(options.name) : stringUtils.camelize(options.name) + 's'; - console.log(state); + const keyInsert = state + ': from' + stringUtils.classify(options.name) + '.reducer,'; const expr = node as any; diff --git a/modules/store-devtools/schematics-core/utility/ngrx-utils.ts b/modules/store-devtools/schematics-core/utility/ngrx-utils.ts index 8d9570baaa..56ee0b4cf3 100644 --- a/modules/store-devtools/schematics-core/utility/ngrx-utils.ts +++ b/modules/store-devtools/schematics-core/utility/ngrx-utils.ts @@ -94,7 +94,7 @@ export function addReducerToStateInterface( options.plural === undefined ? stringUtils.camelize(options.name) : stringUtils.camelize(options.name) + 's'; - console.log(state); + const keyInsert = state + ': from' + stringUtils.classify(options.name) + '.State;'; const expr = node as any; @@ -158,7 +158,7 @@ export function addReducerToActionReducerMap( options.plural === undefined ? stringUtils.camelize(options.name) : stringUtils.camelize(options.name) + 's'; - console.log(state); + const keyInsert = state + ': from' + stringUtils.classify(options.name) + '.reducer,'; const expr = node as any; diff --git a/modules/store/schematics-core/utility/ngrx-utils.ts b/modules/store/schematics-core/utility/ngrx-utils.ts index 8d9570baaa..56ee0b4cf3 100644 --- a/modules/store/schematics-core/utility/ngrx-utils.ts +++ b/modules/store/schematics-core/utility/ngrx-utils.ts @@ -94,7 +94,7 @@ export function addReducerToStateInterface( options.plural === undefined ? stringUtils.camelize(options.name) : stringUtils.camelize(options.name) + 's'; - console.log(state); + const keyInsert = state + ': from' + stringUtils.classify(options.name) + '.State;'; const expr = node as any; @@ -158,7 +158,7 @@ export function addReducerToActionReducerMap( options.plural === undefined ? stringUtils.camelize(options.name) : stringUtils.camelize(options.name) + 's'; - console.log(state); + const keyInsert = state + ': from' + stringUtils.classify(options.name) + '.reducer,'; const expr = node as any; From 757d04ebeb35a8811c214a3b3c9e02318e650034 Mon Sep 17 00:00:00 2001 From: Santosh Yadav Date: Fri, 8 Mar 2019 22:51:43 +0530 Subject: [PATCH 7/9] removed .bazel files --- modules/effects/schematics-core/BUILD.bazel | 17 ----------------- modules/entity/schematics-core/BUILD.bazel | 17 ----------------- .../router-store/schematics-core/BUILD.bazel | 17 ----------------- modules/schematics/schematics-core/BUILD.bazel | 17 ----------------- .../store-devtools/schematics-core/BUILD.bazel | 17 ----------------- modules/store/schematics-core/BUILD.bazel | 17 ----------------- 6 files changed, 102 deletions(-) delete mode 100644 modules/effects/schematics-core/BUILD.bazel delete mode 100644 modules/entity/schematics-core/BUILD.bazel delete mode 100644 modules/router-store/schematics-core/BUILD.bazel delete mode 100644 modules/schematics/schematics-core/BUILD.bazel delete mode 100644 modules/store-devtools/schematics-core/BUILD.bazel delete mode 100644 modules/store/schematics-core/BUILD.bazel diff --git a/modules/effects/schematics-core/BUILD.bazel b/modules/effects/schematics-core/BUILD.bazel deleted file mode 100644 index 01f4701f2b..0000000000 --- a/modules/effects/schematics-core/BUILD.bazel +++ /dev/null @@ -1,17 +0,0 @@ -package(default_visibility = ["//visibility:public"]) - -load("//tools:defaults.bzl", "ts_library") - -ts_library( - name = "schematics-core", - srcs = glob( - [ - "**/*.ts", - ], - ), - deps = [ - "@npm//@angular-devkit/core", - "@npm//@angular-devkit/schematics", - "@npm//typescript", - ], -) diff --git a/modules/entity/schematics-core/BUILD.bazel b/modules/entity/schematics-core/BUILD.bazel deleted file mode 100644 index 01f4701f2b..0000000000 --- a/modules/entity/schematics-core/BUILD.bazel +++ /dev/null @@ -1,17 +0,0 @@ -package(default_visibility = ["//visibility:public"]) - -load("//tools:defaults.bzl", "ts_library") - -ts_library( - name = "schematics-core", - srcs = glob( - [ - "**/*.ts", - ], - ), - deps = [ - "@npm//@angular-devkit/core", - "@npm//@angular-devkit/schematics", - "@npm//typescript", - ], -) diff --git a/modules/router-store/schematics-core/BUILD.bazel b/modules/router-store/schematics-core/BUILD.bazel deleted file mode 100644 index 01f4701f2b..0000000000 --- a/modules/router-store/schematics-core/BUILD.bazel +++ /dev/null @@ -1,17 +0,0 @@ -package(default_visibility = ["//visibility:public"]) - -load("//tools:defaults.bzl", "ts_library") - -ts_library( - name = "schematics-core", - srcs = glob( - [ - "**/*.ts", - ], - ), - deps = [ - "@npm//@angular-devkit/core", - "@npm//@angular-devkit/schematics", - "@npm//typescript", - ], -) diff --git a/modules/schematics/schematics-core/BUILD.bazel b/modules/schematics/schematics-core/BUILD.bazel deleted file mode 100644 index 01f4701f2b..0000000000 --- a/modules/schematics/schematics-core/BUILD.bazel +++ /dev/null @@ -1,17 +0,0 @@ -package(default_visibility = ["//visibility:public"]) - -load("//tools:defaults.bzl", "ts_library") - -ts_library( - name = "schematics-core", - srcs = glob( - [ - "**/*.ts", - ], - ), - deps = [ - "@npm//@angular-devkit/core", - "@npm//@angular-devkit/schematics", - "@npm//typescript", - ], -) diff --git a/modules/store-devtools/schematics-core/BUILD.bazel b/modules/store-devtools/schematics-core/BUILD.bazel deleted file mode 100644 index 01f4701f2b..0000000000 --- a/modules/store-devtools/schematics-core/BUILD.bazel +++ /dev/null @@ -1,17 +0,0 @@ -package(default_visibility = ["//visibility:public"]) - -load("//tools:defaults.bzl", "ts_library") - -ts_library( - name = "schematics-core", - srcs = glob( - [ - "**/*.ts", - ], - ), - deps = [ - "@npm//@angular-devkit/core", - "@npm//@angular-devkit/schematics", - "@npm//typescript", - ], -) diff --git a/modules/store/schematics-core/BUILD.bazel b/modules/store/schematics-core/BUILD.bazel deleted file mode 100644 index 01f4701f2b..0000000000 --- a/modules/store/schematics-core/BUILD.bazel +++ /dev/null @@ -1,17 +0,0 @@ -package(default_visibility = ["//visibility:public"]) - -load("//tools:defaults.bzl", "ts_library") - -ts_library( - name = "schematics-core", - srcs = glob( - [ - "**/*.ts", - ], - ), - deps = [ - "@npm//@angular-devkit/core", - "@npm//@angular-devkit/schematics", - "@npm//typescript", - ], -) From 0b4a3a2270bad38ad2fbae4949113981b0de3c16 Mon Sep 17 00:00:00 2001 From: Santosh Yadav Date: Sat, 9 Mar 2019 16:29:37 +0530 Subject: [PATCH 8/9] code review comments --- .../schematics-core/utility/ngrx-utils.ts | 16 ++++++++-------- .../entity/schematics-core/utility/ngrx-utils.ts | 16 ++++++++-------- .../schematics-core/utility/ngrx-utils.ts | 16 ++++++++-------- modules/schematics-core/utility/ngrx-utils.ts | 16 ++++++++-------- .../schematics-core/utility/ngrx-utils.ts | 16 ++++++++-------- modules/schematics/src/entity/index.spec.ts | 2 +- modules/schematics/src/entity/index.ts | 3 +-- modules/schematics/src/entity/schema.json | 5 ----- modules/schematics/src/entity/schema.ts | 5 ----- .../schematics-core/utility/ngrx-utils.ts | 16 ++++++++-------- .../store/schematics-core/utility/ngrx-utils.ts | 16 ++++++++-------- 11 files changed, 58 insertions(+), 69 deletions(-) diff --git a/modules/effects/schematics-core/utility/ngrx-utils.ts b/modules/effects/schematics-core/utility/ngrx-utils.ts index 56ee0b4cf3..18f0aa095c 100644 --- a/modules/effects/schematics-core/utility/ngrx-utils.ts +++ b/modules/effects/schematics-core/utility/ngrx-utils.ts @@ -90,10 +90,10 @@ export function addReducerToStateInterface( return new NoopChange(); } - const state = - options.plural === undefined - ? stringUtils.camelize(options.name) - : stringUtils.camelize(options.name) + 's'; + let state = stringUtils.camelize(options.name); + if (options.plural) { + state = stringUtils.camelize(options.name) + 's'; + } const keyInsert = state + ': from' + stringUtils.classify(options.name) + '.State;'; @@ -154,10 +154,10 @@ export function addReducerToActionReducerMap( let node = actionReducerMap.initializer; - const state = - options.plural === undefined - ? stringUtils.camelize(options.name) - : stringUtils.camelize(options.name) + 's'; + let state = stringUtils.camelize(options.name); + if (options.plural) { + state = stringUtils.camelize(options.name) + 's'; + } const keyInsert = state + ': from' + stringUtils.classify(options.name) + '.reducer,'; diff --git a/modules/entity/schematics-core/utility/ngrx-utils.ts b/modules/entity/schematics-core/utility/ngrx-utils.ts index 56ee0b4cf3..18f0aa095c 100644 --- a/modules/entity/schematics-core/utility/ngrx-utils.ts +++ b/modules/entity/schematics-core/utility/ngrx-utils.ts @@ -90,10 +90,10 @@ export function addReducerToStateInterface( return new NoopChange(); } - const state = - options.plural === undefined - ? stringUtils.camelize(options.name) - : stringUtils.camelize(options.name) + 's'; + let state = stringUtils.camelize(options.name); + if (options.plural) { + state = stringUtils.camelize(options.name) + 's'; + } const keyInsert = state + ': from' + stringUtils.classify(options.name) + '.State;'; @@ -154,10 +154,10 @@ export function addReducerToActionReducerMap( let node = actionReducerMap.initializer; - const state = - options.plural === undefined - ? stringUtils.camelize(options.name) - : stringUtils.camelize(options.name) + 's'; + let state = stringUtils.camelize(options.name); + if (options.plural) { + state = stringUtils.camelize(options.name) + 's'; + } const keyInsert = state + ': from' + stringUtils.classify(options.name) + '.reducer,'; diff --git a/modules/router-store/schematics-core/utility/ngrx-utils.ts b/modules/router-store/schematics-core/utility/ngrx-utils.ts index 56ee0b4cf3..18f0aa095c 100644 --- a/modules/router-store/schematics-core/utility/ngrx-utils.ts +++ b/modules/router-store/schematics-core/utility/ngrx-utils.ts @@ -90,10 +90,10 @@ export function addReducerToStateInterface( return new NoopChange(); } - const state = - options.plural === undefined - ? stringUtils.camelize(options.name) - : stringUtils.camelize(options.name) + 's'; + let state = stringUtils.camelize(options.name); + if (options.plural) { + state = stringUtils.camelize(options.name) + 's'; + } const keyInsert = state + ': from' + stringUtils.classify(options.name) + '.State;'; @@ -154,10 +154,10 @@ export function addReducerToActionReducerMap( let node = actionReducerMap.initializer; - const state = - options.plural === undefined - ? stringUtils.camelize(options.name) - : stringUtils.camelize(options.name) + 's'; + let state = stringUtils.camelize(options.name); + if (options.plural) { + state = stringUtils.camelize(options.name) + 's'; + } const keyInsert = state + ': from' + stringUtils.classify(options.name) + '.reducer,'; diff --git a/modules/schematics-core/utility/ngrx-utils.ts b/modules/schematics-core/utility/ngrx-utils.ts index 56ee0b4cf3..18f0aa095c 100644 --- a/modules/schematics-core/utility/ngrx-utils.ts +++ b/modules/schematics-core/utility/ngrx-utils.ts @@ -90,10 +90,10 @@ export function addReducerToStateInterface( return new NoopChange(); } - const state = - options.plural === undefined - ? stringUtils.camelize(options.name) - : stringUtils.camelize(options.name) + 's'; + let state = stringUtils.camelize(options.name); + if (options.plural) { + state = stringUtils.camelize(options.name) + 's'; + } const keyInsert = state + ': from' + stringUtils.classify(options.name) + '.State;'; @@ -154,10 +154,10 @@ export function addReducerToActionReducerMap( let node = actionReducerMap.initializer; - const state = - options.plural === undefined - ? stringUtils.camelize(options.name) - : stringUtils.camelize(options.name) + 's'; + let state = stringUtils.camelize(options.name); + if (options.plural) { + state = stringUtils.camelize(options.name) + 's'; + } const keyInsert = state + ': from' + stringUtils.classify(options.name) + '.reducer,'; diff --git a/modules/schematics/schematics-core/utility/ngrx-utils.ts b/modules/schematics/schematics-core/utility/ngrx-utils.ts index 56ee0b4cf3..18f0aa095c 100644 --- a/modules/schematics/schematics-core/utility/ngrx-utils.ts +++ b/modules/schematics/schematics-core/utility/ngrx-utils.ts @@ -90,10 +90,10 @@ export function addReducerToStateInterface( return new NoopChange(); } - const state = - options.plural === undefined - ? stringUtils.camelize(options.name) - : stringUtils.camelize(options.name) + 's'; + let state = stringUtils.camelize(options.name); + if (options.plural) { + state = stringUtils.camelize(options.name) + 's'; + } const keyInsert = state + ': from' + stringUtils.classify(options.name) + '.State;'; @@ -154,10 +154,10 @@ export function addReducerToActionReducerMap( let node = actionReducerMap.initializer; - const state = - options.plural === undefined - ? stringUtils.camelize(options.name) - : stringUtils.camelize(options.name) + 's'; + let state = stringUtils.camelize(options.name); + if (options.plural) { + state = stringUtils.camelize(options.name) + 's'; + } const keyInsert = state + ': from' + stringUtils.classify(options.name) + '.reducer,'; diff --git a/modules/schematics/src/entity/index.spec.ts b/modules/schematics/src/entity/index.spec.ts index fb23e2cfeb..3933d604b6 100644 --- a/modules/schematics/src/entity/index.spec.ts +++ b/modules/schematics/src/entity/index.spec.ts @@ -162,7 +162,7 @@ describe('Entity Schematic', () => { ).toBeGreaterThanOrEqual(0); }); - it('should create all files of an entity within grouped and nested folders', () => { + it('should update the state to plural', () => { const options = { ...defaultOptions, name: 'user', diff --git a/modules/schematics/src/entity/index.ts b/modules/schematics/src/entity/index.ts index bbdf70be63..9cf5572a09 100644 --- a/modules/schematics/src/entity/index.ts +++ b/modules/schematics/src/entity/index.ts @@ -31,7 +31,6 @@ export default function(options: EntityOptions): Rule { const parsedPath = parseName(options.path, options.name); options.name = parsedPath.name; options.path = parsedPath.path; - options.plural = true; if (options.module) { options.module = findModuleFromOptions(host, options); @@ -56,7 +55,7 @@ export default function(options: EntityOptions): Rule { ]); return chain([ - addReducerToState({ ...options }), + addReducerToState({ ...options, plural: true }), addReducerImportToNgModule({ ...options }), branchAndMerge(chain([mergeWith(templateSource)])), ])(host, context); diff --git a/modules/schematics/src/entity/schema.json b/modules/schematics/src/entity/schema.json index 7fe33e9b50..0bd229520c 100644 --- a/modules/schematics/src/entity/schema.json +++ b/modules/schematics/src/entity/schema.json @@ -49,11 +49,6 @@ "description": "Group actions, reducers and effects within relative subfolders", "aliases": ["g"] - }, - "plural": { - "type": "boolean", - "default": true, - "description": "Update state with plural." } }, "required": [] diff --git a/modules/schematics/src/entity/schema.ts b/modules/schematics/src/entity/schema.ts index 98cce4d77d..82b0f13ffe 100644 --- a/modules/schematics/src/entity/schema.ts +++ b/modules/schematics/src/entity/schema.ts @@ -36,9 +36,4 @@ export interface Schema { */ group?: boolean; - /** - * Specifies if this is state and reducer variable will be plural - */ - - plural?: boolean; } diff --git a/modules/store-devtools/schematics-core/utility/ngrx-utils.ts b/modules/store-devtools/schematics-core/utility/ngrx-utils.ts index 56ee0b4cf3..18f0aa095c 100644 --- a/modules/store-devtools/schematics-core/utility/ngrx-utils.ts +++ b/modules/store-devtools/schematics-core/utility/ngrx-utils.ts @@ -90,10 +90,10 @@ export function addReducerToStateInterface( return new NoopChange(); } - const state = - options.plural === undefined - ? stringUtils.camelize(options.name) - : stringUtils.camelize(options.name) + 's'; + let state = stringUtils.camelize(options.name); + if (options.plural) { + state = stringUtils.camelize(options.name) + 's'; + } const keyInsert = state + ': from' + stringUtils.classify(options.name) + '.State;'; @@ -154,10 +154,10 @@ export function addReducerToActionReducerMap( let node = actionReducerMap.initializer; - const state = - options.plural === undefined - ? stringUtils.camelize(options.name) - : stringUtils.camelize(options.name) + 's'; + let state = stringUtils.camelize(options.name); + if (options.plural) { + state = stringUtils.camelize(options.name) + 's'; + } const keyInsert = state + ': from' + stringUtils.classify(options.name) + '.reducer,'; diff --git a/modules/store/schematics-core/utility/ngrx-utils.ts b/modules/store/schematics-core/utility/ngrx-utils.ts index 56ee0b4cf3..18f0aa095c 100644 --- a/modules/store/schematics-core/utility/ngrx-utils.ts +++ b/modules/store/schematics-core/utility/ngrx-utils.ts @@ -90,10 +90,10 @@ export function addReducerToStateInterface( return new NoopChange(); } - const state = - options.plural === undefined - ? stringUtils.camelize(options.name) - : stringUtils.camelize(options.name) + 's'; + let state = stringUtils.camelize(options.name); + if (options.plural) { + state = stringUtils.camelize(options.name) + 's'; + } const keyInsert = state + ': from' + stringUtils.classify(options.name) + '.State;'; @@ -154,10 +154,10 @@ export function addReducerToActionReducerMap( let node = actionReducerMap.initializer; - const state = - options.plural === undefined - ? stringUtils.camelize(options.name) - : stringUtils.camelize(options.name) + 's'; + let state = stringUtils.camelize(options.name); + if (options.plural) { + state = stringUtils.camelize(options.name) + 's'; + } const keyInsert = state + ': from' + stringUtils.classify(options.name) + '.reducer,'; From 4eb91da63b2a79ea6adc0206d3f52d1b46838124 Mon Sep 17 00:00:00 2001 From: Santosh Yadav Date: Sun, 10 Mar 2019 20:17:31 +0530 Subject: [PATCH 9/9] code review changes --- .../effects/schematics-core/utility/ngrx-utils.ts | 14 ++++++-------- modules/effects/schematics-core/utility/strings.ts | 6 +++--- .../entity/schematics-core/utility/ngrx-utils.ts | 14 ++++++-------- modules/entity/schematics-core/utility/strings.ts | 6 +++--- .../schematics-core/utility/ngrx-utils.ts | 14 ++++++-------- .../schematics-core/utility/strings.ts | 6 +++--- modules/schematics-core/utility/ngrx-utils.ts | 14 ++++++-------- modules/schematics-core/utility/strings.ts | 6 +++--- .../schematics-core/utility/ngrx-utils.ts | 14 ++++++-------- .../schematics/schematics-core/utility/strings.ts | 6 +++--- .../schematics-core/utility/ngrx-utils.ts | 14 ++++++-------- .../schematics-core/utility/strings.ts | 6 +++--- .../store/schematics-core/utility/ngrx-utils.ts | 14 ++++++-------- modules/store/schematics-core/utility/strings.ts | 6 +++--- 14 files changed, 63 insertions(+), 77 deletions(-) diff --git a/modules/effects/schematics-core/utility/ngrx-utils.ts b/modules/effects/schematics-core/utility/ngrx-utils.ts index 18f0aa095c..0dd26b3398 100644 --- a/modules/effects/schematics-core/utility/ngrx-utils.ts +++ b/modules/effects/schematics-core/utility/ngrx-utils.ts @@ -90,10 +90,9 @@ export function addReducerToStateInterface( return new NoopChange(); } - let state = stringUtils.camelize(options.name); - if (options.plural) { - state = stringUtils.camelize(options.name) + 's'; - } + const state = options.plural + ? stringUtils.pluralize(options.name) + : stringUtils.camelize(options.name); const keyInsert = state + ': from' + stringUtils.classify(options.name) + '.State;'; @@ -154,10 +153,9 @@ export function addReducerToActionReducerMap( let node = actionReducerMap.initializer; - let state = stringUtils.camelize(options.name); - if (options.plural) { - state = stringUtils.camelize(options.name) + 's'; - } + const state = options.plural + ? stringUtils.pluralize(options.name) + : stringUtils.camelize(options.name); const keyInsert = state + ': from' + stringUtils.classify(options.name) + '.reducer,'; diff --git a/modules/effects/schematics-core/utility/strings.ts b/modules/effects/schematics-core/utility/strings.ts index 50cb159740..5ebec70706 100644 --- a/modules/effects/schematics-core/utility/strings.ts +++ b/modules/effects/schematics-core/utility/strings.ts @@ -111,14 +111,14 @@ export function capitalize(str: string): string { } /** - Returns the Pluralize form of a string + Returns the plural form of a string ```javascript 'innerHTML'.pluralize() // 'InnerHTMLs' 'action_name'.pluralize() // 'actionNames' 'css-class-name'.pluralize() // 'cssClassNames' - 'regex'.capitalize() // 'regexes' - 'user'.capitalize() // 'users' + 'regex'.pluralize() // 'regexes' + 'user'.pluralize() // 'users' ``` */ export function pluralize(str: string): string { diff --git a/modules/entity/schematics-core/utility/ngrx-utils.ts b/modules/entity/schematics-core/utility/ngrx-utils.ts index 18f0aa095c..0dd26b3398 100644 --- a/modules/entity/schematics-core/utility/ngrx-utils.ts +++ b/modules/entity/schematics-core/utility/ngrx-utils.ts @@ -90,10 +90,9 @@ export function addReducerToStateInterface( return new NoopChange(); } - let state = stringUtils.camelize(options.name); - if (options.plural) { - state = stringUtils.camelize(options.name) + 's'; - } + const state = options.plural + ? stringUtils.pluralize(options.name) + : stringUtils.camelize(options.name); const keyInsert = state + ': from' + stringUtils.classify(options.name) + '.State;'; @@ -154,10 +153,9 @@ export function addReducerToActionReducerMap( let node = actionReducerMap.initializer; - let state = stringUtils.camelize(options.name); - if (options.plural) { - state = stringUtils.camelize(options.name) + 's'; - } + const state = options.plural + ? stringUtils.pluralize(options.name) + : stringUtils.camelize(options.name); const keyInsert = state + ': from' + stringUtils.classify(options.name) + '.reducer,'; diff --git a/modules/entity/schematics-core/utility/strings.ts b/modules/entity/schematics-core/utility/strings.ts index 50cb159740..5ebec70706 100644 --- a/modules/entity/schematics-core/utility/strings.ts +++ b/modules/entity/schematics-core/utility/strings.ts @@ -111,14 +111,14 @@ export function capitalize(str: string): string { } /** - Returns the Pluralize form of a string + Returns the plural form of a string ```javascript 'innerHTML'.pluralize() // 'InnerHTMLs' 'action_name'.pluralize() // 'actionNames' 'css-class-name'.pluralize() // 'cssClassNames' - 'regex'.capitalize() // 'regexes' - 'user'.capitalize() // 'users' + 'regex'.pluralize() // 'regexes' + 'user'.pluralize() // 'users' ``` */ export function pluralize(str: string): string { diff --git a/modules/router-store/schematics-core/utility/ngrx-utils.ts b/modules/router-store/schematics-core/utility/ngrx-utils.ts index 18f0aa095c..0dd26b3398 100644 --- a/modules/router-store/schematics-core/utility/ngrx-utils.ts +++ b/modules/router-store/schematics-core/utility/ngrx-utils.ts @@ -90,10 +90,9 @@ export function addReducerToStateInterface( return new NoopChange(); } - let state = stringUtils.camelize(options.name); - if (options.plural) { - state = stringUtils.camelize(options.name) + 's'; - } + const state = options.plural + ? stringUtils.pluralize(options.name) + : stringUtils.camelize(options.name); const keyInsert = state + ': from' + stringUtils.classify(options.name) + '.State;'; @@ -154,10 +153,9 @@ export function addReducerToActionReducerMap( let node = actionReducerMap.initializer; - let state = stringUtils.camelize(options.name); - if (options.plural) { - state = stringUtils.camelize(options.name) + 's'; - } + const state = options.plural + ? stringUtils.pluralize(options.name) + : stringUtils.camelize(options.name); const keyInsert = state + ': from' + stringUtils.classify(options.name) + '.reducer,'; diff --git a/modules/router-store/schematics-core/utility/strings.ts b/modules/router-store/schematics-core/utility/strings.ts index 50cb159740..5ebec70706 100644 --- a/modules/router-store/schematics-core/utility/strings.ts +++ b/modules/router-store/schematics-core/utility/strings.ts @@ -111,14 +111,14 @@ export function capitalize(str: string): string { } /** - Returns the Pluralize form of a string + Returns the plural form of a string ```javascript 'innerHTML'.pluralize() // 'InnerHTMLs' 'action_name'.pluralize() // 'actionNames' 'css-class-name'.pluralize() // 'cssClassNames' - 'regex'.capitalize() // 'regexes' - 'user'.capitalize() // 'users' + 'regex'.pluralize() // 'regexes' + 'user'.pluralize() // 'users' ``` */ export function pluralize(str: string): string { diff --git a/modules/schematics-core/utility/ngrx-utils.ts b/modules/schematics-core/utility/ngrx-utils.ts index 18f0aa095c..0dd26b3398 100644 --- a/modules/schematics-core/utility/ngrx-utils.ts +++ b/modules/schematics-core/utility/ngrx-utils.ts @@ -90,10 +90,9 @@ export function addReducerToStateInterface( return new NoopChange(); } - let state = stringUtils.camelize(options.name); - if (options.plural) { - state = stringUtils.camelize(options.name) + 's'; - } + const state = options.plural + ? stringUtils.pluralize(options.name) + : stringUtils.camelize(options.name); const keyInsert = state + ': from' + stringUtils.classify(options.name) + '.State;'; @@ -154,10 +153,9 @@ export function addReducerToActionReducerMap( let node = actionReducerMap.initializer; - let state = stringUtils.camelize(options.name); - if (options.plural) { - state = stringUtils.camelize(options.name) + 's'; - } + const state = options.plural + ? stringUtils.pluralize(options.name) + : stringUtils.camelize(options.name); const keyInsert = state + ': from' + stringUtils.classify(options.name) + '.reducer,'; diff --git a/modules/schematics-core/utility/strings.ts b/modules/schematics-core/utility/strings.ts index 50cb159740..5ebec70706 100644 --- a/modules/schematics-core/utility/strings.ts +++ b/modules/schematics-core/utility/strings.ts @@ -111,14 +111,14 @@ export function capitalize(str: string): string { } /** - Returns the Pluralize form of a string + Returns the plural form of a string ```javascript 'innerHTML'.pluralize() // 'InnerHTMLs' 'action_name'.pluralize() // 'actionNames' 'css-class-name'.pluralize() // 'cssClassNames' - 'regex'.capitalize() // 'regexes' - 'user'.capitalize() // 'users' + 'regex'.pluralize() // 'regexes' + 'user'.pluralize() // 'users' ``` */ export function pluralize(str: string): string { diff --git a/modules/schematics/schematics-core/utility/ngrx-utils.ts b/modules/schematics/schematics-core/utility/ngrx-utils.ts index 18f0aa095c..0dd26b3398 100644 --- a/modules/schematics/schematics-core/utility/ngrx-utils.ts +++ b/modules/schematics/schematics-core/utility/ngrx-utils.ts @@ -90,10 +90,9 @@ export function addReducerToStateInterface( return new NoopChange(); } - let state = stringUtils.camelize(options.name); - if (options.plural) { - state = stringUtils.camelize(options.name) + 's'; - } + const state = options.plural + ? stringUtils.pluralize(options.name) + : stringUtils.camelize(options.name); const keyInsert = state + ': from' + stringUtils.classify(options.name) + '.State;'; @@ -154,10 +153,9 @@ export function addReducerToActionReducerMap( let node = actionReducerMap.initializer; - let state = stringUtils.camelize(options.name); - if (options.plural) { - state = stringUtils.camelize(options.name) + 's'; - } + const state = options.plural + ? stringUtils.pluralize(options.name) + : stringUtils.camelize(options.name); const keyInsert = state + ': from' + stringUtils.classify(options.name) + '.reducer,'; diff --git a/modules/schematics/schematics-core/utility/strings.ts b/modules/schematics/schematics-core/utility/strings.ts index 50cb159740..5ebec70706 100644 --- a/modules/schematics/schematics-core/utility/strings.ts +++ b/modules/schematics/schematics-core/utility/strings.ts @@ -111,14 +111,14 @@ export function capitalize(str: string): string { } /** - Returns the Pluralize form of a string + Returns the plural form of a string ```javascript 'innerHTML'.pluralize() // 'InnerHTMLs' 'action_name'.pluralize() // 'actionNames' 'css-class-name'.pluralize() // 'cssClassNames' - 'regex'.capitalize() // 'regexes' - 'user'.capitalize() // 'users' + 'regex'.pluralize() // 'regexes' + 'user'.pluralize() // 'users' ``` */ export function pluralize(str: string): string { diff --git a/modules/store-devtools/schematics-core/utility/ngrx-utils.ts b/modules/store-devtools/schematics-core/utility/ngrx-utils.ts index 18f0aa095c..0dd26b3398 100644 --- a/modules/store-devtools/schematics-core/utility/ngrx-utils.ts +++ b/modules/store-devtools/schematics-core/utility/ngrx-utils.ts @@ -90,10 +90,9 @@ export function addReducerToStateInterface( return new NoopChange(); } - let state = stringUtils.camelize(options.name); - if (options.plural) { - state = stringUtils.camelize(options.name) + 's'; - } + const state = options.plural + ? stringUtils.pluralize(options.name) + : stringUtils.camelize(options.name); const keyInsert = state + ': from' + stringUtils.classify(options.name) + '.State;'; @@ -154,10 +153,9 @@ export function addReducerToActionReducerMap( let node = actionReducerMap.initializer; - let state = stringUtils.camelize(options.name); - if (options.plural) { - state = stringUtils.camelize(options.name) + 's'; - } + const state = options.plural + ? stringUtils.pluralize(options.name) + : stringUtils.camelize(options.name); const keyInsert = state + ': from' + stringUtils.classify(options.name) + '.reducer,'; diff --git a/modules/store-devtools/schematics-core/utility/strings.ts b/modules/store-devtools/schematics-core/utility/strings.ts index 50cb159740..5ebec70706 100644 --- a/modules/store-devtools/schematics-core/utility/strings.ts +++ b/modules/store-devtools/schematics-core/utility/strings.ts @@ -111,14 +111,14 @@ export function capitalize(str: string): string { } /** - Returns the Pluralize form of a string + Returns the plural form of a string ```javascript 'innerHTML'.pluralize() // 'InnerHTMLs' 'action_name'.pluralize() // 'actionNames' 'css-class-name'.pluralize() // 'cssClassNames' - 'regex'.capitalize() // 'regexes' - 'user'.capitalize() // 'users' + 'regex'.pluralize() // 'regexes' + 'user'.pluralize() // 'users' ``` */ export function pluralize(str: string): string { diff --git a/modules/store/schematics-core/utility/ngrx-utils.ts b/modules/store/schematics-core/utility/ngrx-utils.ts index 18f0aa095c..0dd26b3398 100644 --- a/modules/store/schematics-core/utility/ngrx-utils.ts +++ b/modules/store/schematics-core/utility/ngrx-utils.ts @@ -90,10 +90,9 @@ export function addReducerToStateInterface( return new NoopChange(); } - let state = stringUtils.camelize(options.name); - if (options.plural) { - state = stringUtils.camelize(options.name) + 's'; - } + const state = options.plural + ? stringUtils.pluralize(options.name) + : stringUtils.camelize(options.name); const keyInsert = state + ': from' + stringUtils.classify(options.name) + '.State;'; @@ -154,10 +153,9 @@ export function addReducerToActionReducerMap( let node = actionReducerMap.initializer; - let state = stringUtils.camelize(options.name); - if (options.plural) { - state = stringUtils.camelize(options.name) + 's'; - } + const state = options.plural + ? stringUtils.pluralize(options.name) + : stringUtils.camelize(options.name); const keyInsert = state + ': from' + stringUtils.classify(options.name) + '.reducer,'; diff --git a/modules/store/schematics-core/utility/strings.ts b/modules/store/schematics-core/utility/strings.ts index 50cb159740..5ebec70706 100644 --- a/modules/store/schematics-core/utility/strings.ts +++ b/modules/store/schematics-core/utility/strings.ts @@ -111,14 +111,14 @@ export function capitalize(str: string): string { } /** - Returns the Pluralize form of a string + Returns the plural form of a string ```javascript 'innerHTML'.pluralize() // 'InnerHTMLs' 'action_name'.pluralize() // 'actionNames' 'css-class-name'.pluralize() // 'cssClassNames' - 'regex'.capitalize() // 'regexes' - 'user'.capitalize() // 'users' + 'regex'.pluralize() // 'regexes' + 'user'.pluralize() // 'users' ``` */ export function pluralize(str: string): string {