Skip to content

Commit

Permalink
fix(angular): add --module option to component generator (#9684)
Browse files Browse the repository at this point in the history
  • Loading branch information
Coly010 committed Apr 5, 2022
1 parent 274c050 commit e42069b
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 2 deletions.
5 changes: 5 additions & 0 deletions docs/generated/packages/angular.json
Expand Up @@ -291,6 +291,11 @@
"default": "Default",
"alias": "c"
},
"module": {
"type": "string",
"description": "The filename or path to the NgModule that will declare this component.",
"alias": "m"
},
"style": {
"description": "The file extension or preprocessor to use for style files, or `none` to skip generating the style file.",
"type": "string",
Expand Down
77 changes: 77 additions & 0 deletions packages/angular/src/generators/component/component.spec.ts
Expand Up @@ -11,6 +11,17 @@ describe('component Generator', () => {
sourceRoot: 'libs/lib1/src',
root: 'libs/lib1',
});
tree.write(
'libs/lib1/src/lib/lib.module.ts',
`
import { NgModule } from '@angular/core';
@NgModule({
declarations: [],
exports: []
})
export class LibModule {}`
);
tree.write('libs/lib1/src/index.ts', '');

// ACT
Expand Down Expand Up @@ -39,6 +50,17 @@ describe('component Generator', () => {
sourceRoot: 'libs/lib1/src',
root: 'libs/lib1',
});
tree.write(
'libs/lib1/src/lib/lib.module.ts',
`
import { NgModule } from '@angular/core';
@NgModule({
declarations: [],
exports: []
})
export class LibModule {}`
);
tree.write('libs/lib1/src/index.ts', '');

// ACT
Expand Down Expand Up @@ -69,6 +91,17 @@ describe('component Generator', () => {
sourceRoot: 'libs/lib1/src',
root: 'libs/lib1',
});
tree.write(
'libs/lib1/src/lib/lib.module.ts',
`
import { NgModule } from '@angular/core';
@NgModule({
declarations: [],
exports: []
})
export class LibModule {}`
);

// ACT
await componentGenerator(tree, {
Expand Down Expand Up @@ -97,6 +130,17 @@ describe('component Generator', () => {
sourceRoot: 'libs/lib1/src',
root: 'libs/lib1',
});
tree.write(
'libs/lib1/src/lib/lib.module.ts',
`
import { NgModule } from '@angular/core';
@NgModule({
declarations: [],
exports: []
})
export class LibModule {}`
);
tree.write('libs/lib1/src/index.ts', '');

// ACT
Expand Down Expand Up @@ -126,6 +170,17 @@ describe('component Generator', () => {
sourceRoot: 'libs/lib1/src',
root: 'libs/lib1',
});
tree.write(
'libs/lib1/src/lib/lib.module.ts',
`
import { NgModule } from '@angular/core';
@NgModule({
declarations: [],
exports: []
})
export class LibModule {}`
);
tree.write('libs/lib1/src/index.ts', '');

// ACT
Expand Down Expand Up @@ -159,6 +214,17 @@ describe('component Generator', () => {
sourceRoot: 'libs/lib1/src',
root: 'libs/lib1',
});
tree.write(
'libs/lib1/src/lib/lib.module.ts',
`
import { NgModule } from '@angular/core';
@NgModule({
declarations: [],
exports: []
})
export class LibModule {}`
);
tree.write('libs/lib1/src/index.ts', '');

// ACT
Expand Down Expand Up @@ -190,6 +256,17 @@ describe('component Generator', () => {
sourceRoot: 'libs/lib1/src',
root: 'libs/lib1',
});
tree.write(
'libs/lib1/src/lib/lib.module.ts',
`
import { NgModule } from '@angular/core';
@NgModule({
declarations: [],
exports: []
})
export class LibModule {}`
);
tree.write('libs/lib1/src/index.ts', '');

// ACT & ASSERT
Expand Down
2 changes: 0 additions & 2 deletions packages/angular/src/generators/component/component.ts
Expand Up @@ -7,7 +7,6 @@ import {
readProjectConfiguration,
normalizePath,
} from '@nrwl/devkit';
import { normalize } from 'path';
import { pathStartsWith } from '../utils/path';

export async function componentGenerator(tree: Tree, schema: Schema) {
Expand All @@ -19,7 +18,6 @@ export async function componentGenerator(tree: Tree, schema: Schema) {
);
await angularComponentSchematic(tree, {
...schema,
skipImport: true,
});

exportComponent(tree, schema);
Expand Down
1 change: 1 addition & 0 deletions packages/angular/src/generators/component/schema.d.ts
Expand Up @@ -12,6 +12,7 @@ export interface Schema {
type?: string;
flat?: boolean;
selector?: string;
module?: string;
skipSelector?: boolean;
export?: boolean;
}
5 changes: 5 additions & 0 deletions packages/angular/src/generators/component/schema.json
Expand Up @@ -60,6 +60,11 @@
"default": "Default",
"alias": "c"
},
"module": {
"type": "string",
"description": "The filename or path to the NgModule that will declare this component.",
"alias": "m"
},
"style": {
"description": "The file extension or preprocessor to use for style files, or `none` to skip generating the style file.",
"type": "string",
Expand Down

1 comment on commit e42069b

@vercel
Copy link

@vercel vercel bot commented on e42069b Apr 5, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.