Skip to content

Commit

Permalink
feat(feature): shared feature.module.ts is generated with the shared …
Browse files Browse the repository at this point in the history
…module (#42)
  • Loading branch information
m-abs authored and NathanWalker committed Oct 23, 2018
1 parent 514a423 commit e4e8075
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 12 deletions.
File renamed without changes.
6 changes: 6 additions & 0 deletions src/feature/_lib_files/__name__.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { NgModule, NO_ERRORS_SCHEMA } from '@angular/core';

@NgModule({
schemas: [NO_ERRORS_SCHEMA],
})
export class <%= utils.classify(name) %>Module {}
3 changes: 2 additions & 1 deletion src/feature/_lib_files/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './base';
<% if (!ignoreBase && !onlyModule) { %>export * from './base';<% } %>
export * from './<%= name %>.module';
4 changes: 3 additions & 1 deletion src/feature/_nativescript_files/__name__.module.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { NgModule, NO_ERRORS_SCHEMA } from '@angular/core';<% if (!onlyModule && onlyProject && routing) { %>
import { Routes } from '@angular/router';
import { NativeScriptRouterModule } from 'nativescript-angular/router';<% } %>
import { <%= utils.classify(name) %>Module as Shared<%= utils.classify(name) %>Module } from '@<%= npmScope %>/features';
<% if (onlyProject) { %>
import { SharedModule } from '../shared/shared.module';<% } else { %>
import { UIModule } from '../ui/ui.module';<% } if (!onlyModule) { %>
Expand All @@ -15,8 +16,9 @@ export const routes: Routes = [

@NgModule({
imports: [
Shared<%= utils.classify(name) %>Module,
<% if (onlyProject) { %>SharedModule<% if (routing) { %>,
NativeScriptRouterModule.forChild(routes)<% } } else { %>UIModule<% } %>
NativeScriptRouterModule.forChild(routes)<% } } else { %>UIModule<% } %>
],<% if (!onlyModule) { %>
declarations: [
...<%= utils.sanitize(name).toUpperCase() %>_COMPONENTS
Expand Down
7 changes: 4 additions & 3 deletions src/feature/_web_files/__name__.module.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { NgModule } from '@angular/core';<% if (!onlyModule && onlyProject && routing) { %>
import { RouterModule, Routes } from '@angular/router';<% } %>
import { <%= utils.classify(name) %>Module as Shared<%= utils.classify(name) %>Module } from '@<%= npmScope %>/features';
<% if (onlyProject) { %>
import { SharedModule } from '../shared/shared.module';<% } else { %>
import { UIModule } from '../ui/ui.module';<% } if (!onlyModule) { %>
Expand All @@ -14,8 +15,9 @@ export const routes: Routes = [

@NgModule({
imports: [
Shared<%= utils.classify(name) %>Module,
<% if (onlyProject) { %>SharedModule<% if (routing) { %>,
RouterModule.forChild(routes)<% } } else { %>UIModule<% } %>
RouterModule.forChild(routes)<% } } else { %>UIModule<% } %>
],<% if (!onlyModule) { %>
declarations: [
...<%= utils.sanitize(name).toUpperCase() %>_COMPONENTS
Expand All @@ -25,5 +27,4 @@ export const routes: Routes = [
]<% } %>
})
export class <%= utils.classify(name) %>Module {}



11 changes: 8 additions & 3 deletions src/feature/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,17 @@ export default function(options: featureOptions) {
prerun(),
// libs
(tree: Tree, context: SchematicContext) =>
options.onlyProject || options.onlyModule || options.ignoreBase
options.onlyProject
? noop()(tree, context)
: addFiles(options)(tree, context),
// libs
(tree: Tree, context: SchematicContext) =>
options.onlyProject || options.ignoreBase || options.onlyModule
? noop()(tree, context)
: addFiles(options, null, null, "_component")(tree, context),
// update libs index
(tree: Tree, context: SchematicContext) =>
options.onlyProject || options.onlyModule || options.ignoreBase
options.onlyProject
? noop()(tree, context)
: adjustBarrelIndex("libs/features/index.ts")(tree, context),
// web
Expand Down Expand Up @@ -180,7 +185,7 @@ export default function(options: featureOptions) {
: noop()(tree, context),
// project handling
...projectChains,
options.skipFormat
options.skipFormat
? noop()
: formatFiles(options)
]);
Expand Down
12 changes: 8 additions & 4 deletions src/feature/index_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ describe('feature schematic', () => {

// feature in shared code
expect(files.indexOf('/libs/features/foo/index.ts')).toBeGreaterThanOrEqual(0);
expect(files.indexOf('/libs/features/foo/foo.module.ts')).toBeGreaterThanOrEqual(0);
expect(files.indexOf('/libs/features/foo/base/foo.base-component.ts')).toBeGreaterThanOrEqual(0);
expect(files.indexOf('/xplat/nativescript/features/foo/index.ts')).toBeGreaterThanOrEqual(0);
expect(files.indexOf('/xplat/nativescript/features/foo/foo.module.ts')).toBeGreaterThanOrEqual(0);
Expand Down Expand Up @@ -105,7 +106,8 @@ describe('feature schematic', () => {
expect(files.indexOf('/xplat/web/index.ts')).toBeGreaterThanOrEqual(0);

// feature
expect(files.indexOf('/libs/features/foo/index.ts')).toBe(-1);
expect(files.indexOf('/libs/features/foo/index.ts')).toBeGreaterThanOrEqual(0);
expect(files.indexOf('/libs/features/foo/foo.module.ts')).toBeGreaterThanOrEqual(0);
expect(files.indexOf('/libs/features/foo/base/foo.base-component.ts')).toBe(-1);
expect(files.indexOf('/xplat/nativescript/features/foo/index.ts')).toBeGreaterThanOrEqual(0);
expect(files.indexOf('/xplat/nativescript/features/foo/foo.module.ts')).toBeGreaterThanOrEqual(0);
Expand Down Expand Up @@ -143,7 +145,7 @@ describe('feature schematic', () => {
name: 'viewer',
prefix: 'tt'
}, tree);
const options: FeatureOptions = {
const options: FeatureOptions = {
name: 'foo',
platforms: 'web',
ignoreBase: true
Expand All @@ -158,7 +160,8 @@ describe('feature schematic', () => {
expect(files.indexOf('/xplat/web/index.ts')).toBeGreaterThanOrEqual(0);

// feature
expect(files.indexOf('/libs/features/foo/index.ts')).toBe(-1);
expect(files.indexOf('/libs/features/foo/index.ts')).toBeGreaterThanOrEqual(0);
expect(files.indexOf('/libs/features/foo/foo.module.ts')).toBeGreaterThanOrEqual(0);
expect(files.indexOf('/libs/features/foo/base/foo.base-component.ts')).toBe(-1);
expect(files.indexOf('/xplat/nativescript/features/foo/index.ts')).toBeGreaterThanOrEqual(-1);
expect(files.indexOf('/xplat/nativescript/features/foo/foo.module.ts')).toBeGreaterThanOrEqual(-1);
Expand All @@ -184,7 +187,7 @@ describe('feature schematic', () => {
// console.log(compPath + ':');
// console.log(compContent);
expect(compContent.indexOf('extends BaseComponent')).toBeGreaterThanOrEqual(0);

});

it('should create feature module for specified projects only', () => {
Expand All @@ -204,6 +207,7 @@ describe('feature schematic', () => {

// feature should not be in shared code
expect(files.indexOf('/libs/features/foo/index.ts')).toBe(-1);
expect(files.indexOf('/libs/features/foo/foo.module.ts')).toBe(-1);
expect(files.indexOf('/xplat/nativescript/features/foo/index.ts')).toBe(-1);
expect(files.indexOf('/xplat/web/features/foo/index.ts')).toBe(-1);

Expand Down

0 comments on commit e4e8075

Please sign in to comment.