Skip to content

Commit 0b5f480

Browse files
Keen Yee LiauAndrewKushnir
authored andcommittedApr 24, 2019
fix(bazel): make name param in ng add optional (#30074)
PR Close #30074
1 parent 2905bf5 commit 0b5f480

File tree

4 files changed

+17
-4
lines changed

4 files changed

+17
-4
lines changed
 

‎packages/bazel/src/schematics/ng-add/index.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import {JsonAstObject, parseJsonAst} from '@angular-devkit/core';
1212
import {Rule, SchematicContext, SchematicsException, Tree, apply, applyTemplates, chain, mergeWith, url} from '@angular-devkit/schematics';
1313
import {NodePackageInstallTask} from '@angular-devkit/schematics/tasks';
14-
import {getWorkspacePath} from '@schematics/angular/utility/config';
14+
import {getWorkspace, getWorkspacePath} from '@schematics/angular/utility/config';
1515
import {findPropertyInAstObject, insertPropertyInAstObjectInOrder} from '@schematics/angular/utility/json-utils';
1616
import {validateProjectName} from '@schematics/angular/utility/validation';
1717

@@ -118,7 +118,7 @@ function updateGitignore() {
118118
*/
119119
function updateAngularJsonToUseBazelBuilder(options: Schema): Rule {
120120
return (host: Tree, context: SchematicContext) => {
121-
const {name} = options;
121+
const name = options.name !;
122122
const workspacePath = getWorkspacePath(host);
123123
if (!workspacePath) {
124124
throw new Error('Could not find angular.json');
@@ -374,6 +374,10 @@ function installNodeModules(options: Schema): Rule {
374374

375375
export default function(options: Schema): Rule {
376376
return (host: Tree) => {
377+
options.name = options.name || getWorkspace(host).defaultProject;
378+
if (!options.name) {
379+
throw new Error('Please specify a project using "--name project-name"');
380+
}
377381
validateProjectName(options.name);
378382

379383
return chain([

‎packages/bazel/src/schematics/ng-add/index_spec.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ describe('ng-add schematic', () => {
5555
},
5656
},
5757
},
58+
defaultProject: 'demo',
5859
}));
5960
schematicRunner =
6061
new SchematicTestRunner('@angular/bazel', require.resolve('../collection.json'));
@@ -202,6 +203,15 @@ describe('ng-add schematic', () => {
202203
expect(lint.builder).toBe('@angular-devkit/build-angular:tslint');
203204
});
204205

206+
it('should get defaultProject if name is not provided', () => {
207+
const options = {};
208+
host = schematicRunner.runSchematic('ng-add', options, host);
209+
const content = host.readContent('/angular.json');
210+
const json = JSON.parse(content);
211+
const builder = json.projects.demo.architect.build.builder;
212+
expect(builder).toBe('@angular/bazel:build');
213+
});
214+
205215
it('should create a backup for original tsconfig.json', () => {
206216
expect(host.files).toContain('/tsconfig.json');
207217
const original = host.readContent('/tsconfig.json');

‎packages/bazel/src/schematics/ng-add/schema.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export interface Schema {
99
/**
1010
* The name of the project.
1111
*/
12-
name: string;
12+
name?: string;
1313
/**
1414
* When true, does not install dependency packages.
1515
*/

‎packages/bazel/src/schematics/ng-add/schema.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,5 @@
2020
}
2121
},
2222
"required": [
23-
"name"
2423
]
2524
}

0 commit comments

Comments
 (0)
Please sign in to comment.