File tree 3 files changed +23
-1
lines changed
packages/bazel/src/schematics/bazel-workspace
3 files changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -23,7 +23,8 @@ ng_module(
23
23
]),
24
24
deps = [
25
25
"@angular//packages/core",
26
- "@angular//packages/platform-browser",
26
+ "@angular//packages/platform-browser",<% if (routing) { %>
27
+ "@angular//packages/router",<% } %>
27
28
"@npm//@types",
28
29
],
29
30
)
Original file line number Diff line number Diff line change @@ -51,6 +51,15 @@ export function clean(version: string): string|null {
51
51
return matches && matches . pop ( ) || null ;
52
52
}
53
53
54
+ /**
55
+ * Returns true if project contains routing module, false otherwise.
56
+ */
57
+ function hasRoutingModule ( host : Tree ) {
58
+ let hasRouting = false ;
59
+ host . visit ( ( file : string ) => { hasRouting = hasRouting || file . endsWith ( '-routing.module.ts' ) ; } ) ;
60
+ return hasRouting ;
61
+ }
62
+
54
63
export default function ( options : BazelWorkspaceOptions ) : Rule {
55
64
return ( host : Tree , context : SchematicContext ) => {
56
65
if ( ! options . name ) {
@@ -93,6 +102,7 @@ export default function(options: BazelWorkspaceOptions): Rule {
93
102
utils : strings ,
94
103
...options ,
95
104
'dot' : '.' , ...workspaceVersions ,
105
+ routing : hasRoutingModule ( host ) ,
96
106
} ) ,
97
107
move ( appDir ) ,
98
108
] ) ) ;
Original file line number Diff line number Diff line change @@ -51,6 +51,17 @@ describe('Bazel-workspace Schematic', () => {
51
51
expect ( content ) . toContain ( 'entry_module = "demo_app/src/main.dev"' ) ;
52
52
} ) ;
53
53
54
+ it ( 'should add router if project contains routing module' , ( ) => {
55
+ let host = new UnitTestTree ( new HostTree ) ;
56
+ host . create ( '/demo/src/app/app-routing.module.ts' , '' ) ;
57
+ expect ( host . files ) . toContain ( '/demo/src/app/app-routing.module.ts' ) ;
58
+ const options = { ...defaultOptions } ;
59
+ host = schematicRunner . runSchematic ( 'bazel-workspace' , options , host ) ;
60
+ expect ( host . files ) . toContain ( '/demo/src/BUILD.bazel' ) ;
61
+ const content = host . readContent ( '/demo/src/BUILD.bazel' ) ;
62
+ expect ( content ) . toContain ( '@angular//packages/router' ) ;
63
+ } ) ;
64
+
54
65
describe ( 'WORKSPACE' , ( ) => {
55
66
it ( 'should contain project name' , ( ) => {
56
67
const options = { ...defaultOptions } ;
You can’t perform that action at this time.
0 commit comments