Skip to content

Commit e664ce6

Browse files
m-absNathanWalker
authored andcommitted
fix(generators): Inconsistent named feature arrays. (#69)
1 parent 25e61d4 commit e664ce6

File tree

6 files changed

+84
-10
lines changed

6 files changed

+84
-10
lines changed

src/directive/_index_files/index.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
11
import { <%= utils.classify(name) %>Directive } from './<%= name %>.directive';
22

3-
export const <%= utils.sanitize(name).toUpperCase() %>_DIRECTIVES = [<%= utils.classify(name) %>Directive];
3+
<% if (feature) { %>
4+
export const <%= utils.sanitize(feature).toUpperCase() %>_DIRECTIVES = [
5+
<% } else { %>
6+
export const DIRECTIVES = [
7+
<% } %>
8+
<%= utils.classify(name) %>Directive
9+
];

src/directive/index_spec.ts

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,11 @@ describe('directive schematic', () => {
3636
name: 'foo',
3737
platforms: 'nativescript,web'
3838
}, tree);
39-
const options: GenerateOptions = { ...defaultOptions };
39+
let options: GenerateOptions = { ...defaultOptions };
40+
41+
// Directives without the feature option are added to the ui-feature
4042
tree = schematicRunner.runSchematic('directive', options, tree);
41-
const files = tree.files;
43+
let files = tree.files;
4244
// console.log(files.slice(91,files.length));
4345

4446
// component
@@ -52,9 +54,32 @@ describe('directive schematic', () => {
5254

5355
let modulePath = '/libs/features/ui/ui.module.ts';
5456
let moduleContent = getFileContent(tree, modulePath);
57+
5558
// console.log(modulePath + ':');
5659
// console.log(moduleContent);
5760
expect(moduleContent.indexOf(`...UI_DIRECTIVES`)).toBeGreaterThanOrEqual(0);
61+
62+
// Directives added to the foo-feature
63+
options = { ...defaultOptions, feature: 'foo' };
64+
tree = schematicRunner.runSchematic('directive', options, tree);
65+
files = tree.files;
66+
// console.log(files.slice(91,files.length));
67+
68+
// component
69+
expect(files.indexOf('/libs/features/foo/directives/active-link.directive.ts')).toBeGreaterThanOrEqual(0);
70+
71+
// file content
72+
content = getFileContent(tree, '/libs/features/foo/directives/active-link.directive.ts');
73+
// console.log(content);
74+
expect(content.indexOf(`@Directive({`)).toBeGreaterThanOrEqual(0);
75+
expect(content.indexOf(`selector: '[active-link]'`)).toBeGreaterThanOrEqual(0);
76+
77+
modulePath = '/libs/features/foo/foo.module.ts';
78+
moduleContent = getFileContent(tree, modulePath);
79+
80+
// console.log(modulePath + ':');
81+
// console.log(moduleContent);
82+
expect(moduleContent.indexOf(`...FOO_DIRECTIVES`)).toBeGreaterThanOrEqual(0);
5883
});
5984

6085
it('should create directive for specified projects only', () => {
@@ -72,7 +97,7 @@ describe('directive schematic', () => {
7297
projects: 'nativescript-viewer,web-viewer,ionic-viewer',
7398
onlyProject: true
7499
}, tree);
75-
const options: GenerateOptions = {
100+
const options: GenerateOptions = {
76101
name: 'active-link',
77102
feature: 'foo',
78103
projects: 'nativescript-viewer,web-viewer,ionic-viewer'
@@ -111,4 +136,4 @@ describe('directive schematic', () => {
111136
// console.log(barrelIndex);
112137
expect(index.indexOf(`ActiveLinkDirective`)).toBeGreaterThanOrEqual(0);
113138
});
114-
});
139+
});

src/pipe/_index_files/index.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
11
import { <%= utils.classify(name) %>Pipe } from './<%= name %>.pipe';
22

3-
export const <%= utils.sanitize(name).toUpperCase() %>_PIPES = [<%= utils.classify(name) %>Pipe];
3+
<% if (feature) { %>
4+
export const <%= utils.sanitize(feature).toUpperCase() %>_PIPES = [
5+
<% } else { %>
6+
export const PIPES = [
7+
<% } %>
8+
<%= utils.classify(name) %>Pipe
9+
];
10+
11+
export * from './<%= name %>.pipe';

src/pipe/index_spec.ts

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ describe("pipe schematic", () => {
5050
);
5151
let options: GenerateOptions = { ...defaultOptions };
5252
tree = schematicRunner.runSchematic("pipe", options, tree);
53-
const files = tree.files;
53+
let files = tree.files;
5454
// console.log(files.slice(91,files.length));
5555

5656
// component
@@ -66,6 +66,39 @@ describe("pipe schematic", () => {
6666
// console.log(content);
6767
expect(content.indexOf(`@Pipe({`)).toBeGreaterThanOrEqual(0);
6868
expect(content.indexOf(`name: 'truncate'`)).toBeGreaterThanOrEqual(0);
69+
70+
let modulePath = '/libs/features/ui/ui.module.ts';
71+
let moduleContent = getFileContent(tree, modulePath);
72+
73+
// console.log(modulePath + ':');
74+
// console.log(moduleContent);
75+
expect(moduleContent.indexOf(`...PIPES`)).toBeGreaterThanOrEqual(0);
76+
77+
options = { ...defaultOptions, feature: 'foo' };
78+
tree = schematicRunner.runSchematic("pipe", options, tree);
79+
files = tree.files;
80+
// console.log(files.slice(91,files.length));
81+
82+
// component
83+
expect(
84+
files.indexOf("/libs/features/foo/pipes/truncate.pipe.ts")
85+
).toBeGreaterThanOrEqual(0);
86+
87+
// file content
88+
content = getFileContent(
89+
tree,
90+
"/libs/features/foo/pipes/truncate.pipe.ts"
91+
);
92+
// console.log(content);
93+
expect(content.indexOf(`@Pipe({`)).toBeGreaterThanOrEqual(0);
94+
expect(content.indexOf(`name: 'truncate'`)).toBeGreaterThanOrEqual(0);
95+
96+
modulePath = '/libs/features/foo/foo.module.ts';
97+
moduleContent = getFileContent(tree, modulePath);
98+
99+
// console.log(modulePath + ':');
100+
// console.log(moduleContent);
101+
expect(moduleContent.indexOf(`...FOO_PIPES`)).toBeGreaterThanOrEqual(0);
69102
});
70103

71104
it("should create pipe in libs and handle camel case properly", () => {
@@ -94,7 +127,7 @@ describe("pipe schematic", () => {
94127
},
95128
tree
96129
);
97-
let options: GenerateOptions = {
130+
let options: GenerateOptions = {
98131
...defaultOptions,
99132
name: 'test-with-dashes'
100133
};

src/service/_index_files/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { <%= utils.classify(name) %>Service } from './<%= name %>.service';
22

3-
export const <%= utils.sanitize(name).toUpperCase() %>_PROVIDERS = [<%= utils.classify(name) %>Service];
3+
export const <%= utils.sanitize(feature).toUpperCase() %>_PROVIDERS = [
4+
<%= utils.classify(name) %>Service
5+
];
46

57
export * from './<%= name %>.service';

src/utils/generator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,7 @@ export function adjustBarrelIndex(
546546
}
547547
}
548548

549-
if (type === "component" || type === "service") {
549+
if (type === "component" || type === "service" || type === 'pipe') {
550550
// export symbol from barrel
551551
if ((isBase || importIfSubFolder) && options.subFolder) {
552552
changes.push(

0 commit comments

Comments
 (0)