Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

fix: Inconsistent named feature arrays. #69

Merged
merged 4 commits into from
Jan 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/directive/_index_files/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
import { <%= utils.classify(name) %>Directive } from './<%= name %>.directive';

export const <%= utils.sanitize(name).toUpperCase() %>_DIRECTIVES = [<%= utils.classify(name) %>Directive];
<% if (feature) { %>
export const <%= utils.sanitize(feature).toUpperCase() %>_DIRECTIVES = [
<% } else { %>
export const DIRECTIVES = [
<% } %>
<%= utils.classify(name) %>Directive
];
33 changes: 29 additions & 4 deletions src/directive/index_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,11 @@ describe('directive schematic', () => {
name: 'foo',
platforms: 'nativescript,web'
}, tree);
const options: GenerateOptions = { ...defaultOptions };
let options: GenerateOptions = { ...defaultOptions };

// Directives without the feature option are added to the ui-feature
tree = schematicRunner.runSchematic('directive', options, tree);
const files = tree.files;
let files = tree.files;
// console.log(files.slice(91,files.length));

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

let modulePath = '/libs/features/ui/ui.module.ts';
let moduleContent = getFileContent(tree, modulePath);

// console.log(modulePath + ':');
// console.log(moduleContent);
expect(moduleContent.indexOf(`...UI_DIRECTIVES`)).toBeGreaterThanOrEqual(0);

// Directives added to the foo-feature
options = { ...defaultOptions, feature: 'foo' };
tree = schematicRunner.runSchematic('directive', options, tree);
files = tree.files;
// console.log(files.slice(91,files.length));

// component
expect(files.indexOf('/libs/features/foo/directives/active-link.directive.ts')).toBeGreaterThanOrEqual(0);

// file content
content = getFileContent(tree, '/libs/features/foo/directives/active-link.directive.ts');
// console.log(content);
expect(content.indexOf(`@Directive({`)).toBeGreaterThanOrEqual(0);
expect(content.indexOf(`selector: '[active-link]'`)).toBeGreaterThanOrEqual(0);

modulePath = '/libs/features/foo/foo.module.ts';
moduleContent = getFileContent(tree, modulePath);

// console.log(modulePath + ':');
// console.log(moduleContent);
expect(moduleContent.indexOf(`...FOO_DIRECTIVES`)).toBeGreaterThanOrEqual(0);
});

it('should create directive for specified projects only', () => {
Expand All @@ -72,7 +97,7 @@ describe('directive schematic', () => {
projects: 'nativescript-viewer,web-viewer,ionic-viewer',
onlyProject: true
}, tree);
const options: GenerateOptions = {
const options: GenerateOptions = {
name: 'active-link',
feature: 'foo',
projects: 'nativescript-viewer,web-viewer,ionic-viewer'
Expand Down Expand Up @@ -111,4 +136,4 @@ describe('directive schematic', () => {
// console.log(barrelIndex);
expect(index.indexOf(`ActiveLinkDirective`)).toBeGreaterThanOrEqual(0);
});
});
});
10 changes: 9 additions & 1 deletion src/pipe/_index_files/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
import { <%= utils.classify(name) %>Pipe } from './<%= name %>.pipe';

export const <%= utils.sanitize(name).toUpperCase() %>_PIPES = [<%= utils.classify(name) %>Pipe];
<% if (feature) { %>
export const <%= utils.sanitize(feature).toUpperCase() %>_PIPES = [
<% } else { %>
export const PIPES = [
<% } %>
<%= utils.classify(name) %>Pipe
];

export * from './<%= name %>.pipe';
37 changes: 35 additions & 2 deletions src/pipe/index_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ describe("pipe schematic", () => {
);
let options: GenerateOptions = { ...defaultOptions };
tree = schematicRunner.runSchematic("pipe", options, tree);
const files = tree.files;
let files = tree.files;
// console.log(files.slice(91,files.length));

// component
Expand All @@ -66,6 +66,39 @@ describe("pipe schematic", () => {
// console.log(content);
expect(content.indexOf(`@Pipe({`)).toBeGreaterThanOrEqual(0);
expect(content.indexOf(`name: 'truncate'`)).toBeGreaterThanOrEqual(0);

let modulePath = '/libs/features/ui/ui.module.ts';
let moduleContent = getFileContent(tree, modulePath);

// console.log(modulePath + ':');
// console.log(moduleContent);
expect(moduleContent.indexOf(`...PIPES`)).toBeGreaterThanOrEqual(0);

options = { ...defaultOptions, feature: 'foo' };
tree = schematicRunner.runSchematic("pipe", options, tree);
files = tree.files;
// console.log(files.slice(91,files.length));

// component
expect(
files.indexOf("/libs/features/foo/pipes/truncate.pipe.ts")
).toBeGreaterThanOrEqual(0);

// file content
content = getFileContent(
tree,
"/libs/features/foo/pipes/truncate.pipe.ts"
);
// console.log(content);
expect(content.indexOf(`@Pipe({`)).toBeGreaterThanOrEqual(0);
expect(content.indexOf(`name: 'truncate'`)).toBeGreaterThanOrEqual(0);

modulePath = '/libs/features/foo/foo.module.ts';
moduleContent = getFileContent(tree, modulePath);

// console.log(modulePath + ':');
// console.log(moduleContent);
expect(moduleContent.indexOf(`...FOO_PIPES`)).toBeGreaterThanOrEqual(0);
});

it("should create pipe in libs and handle camel case properly", () => {
Expand Down Expand Up @@ -94,7 +127,7 @@ describe("pipe schematic", () => {
},
tree
);
let options: GenerateOptions = {
let options: GenerateOptions = {
...defaultOptions,
name: 'test-with-dashes'
};
Expand Down
4 changes: 3 additions & 1 deletion src/service/_index_files/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { <%= utils.classify(name) %>Service } from './<%= name %>.service';

export const <%= utils.sanitize(name).toUpperCase() %>_PROVIDERS = [<%= utils.classify(name) %>Service];
export const <%= utils.sanitize(feature).toUpperCase() %>_PROVIDERS = [
<%= utils.classify(name) %>Service
];

export * from './<%= name %>.service';
2 changes: 1 addition & 1 deletion src/utils/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ export function adjustBarrelIndex(
}
}

if (type === "component" || type === "service") {
if (type === "component" || type === "service" || type === 'pipe') {
// export symbol from barrel
if ((isBase || importIfSubFolder) && options.subFolder) {
changes.push(
Expand Down