fix(bazel): make name param in ng add optional (#30074)
PR Close #30074
This commit is contained in:
parent
2905bf5548
commit
0b5f480eca
|
@ -11,7 +11,7 @@
|
|||
import {JsonAstObject, parseJsonAst} from '@angular-devkit/core';
|
||||
import {Rule, SchematicContext, SchematicsException, Tree, apply, applyTemplates, chain, mergeWith, url} from '@angular-devkit/schematics';
|
||||
import {NodePackageInstallTask} from '@angular-devkit/schematics/tasks';
|
||||
import {getWorkspacePath} from '@schematics/angular/utility/config';
|
||||
import {getWorkspace, getWorkspacePath} from '@schematics/angular/utility/config';
|
||||
import {findPropertyInAstObject, insertPropertyInAstObjectInOrder} from '@schematics/angular/utility/json-utils';
|
||||
import {validateProjectName} from '@schematics/angular/utility/validation';
|
||||
|
||||
|
@ -118,7 +118,7 @@ function updateGitignore() {
|
|||
*/
|
||||
function updateAngularJsonToUseBazelBuilder(options: Schema): Rule {
|
||||
return (host: Tree, context: SchematicContext) => {
|
||||
const {name} = options;
|
||||
const name = options.name !;
|
||||
const workspacePath = getWorkspacePath(host);
|
||||
if (!workspacePath) {
|
||||
throw new Error('Could not find angular.json');
|
||||
|
@ -374,6 +374,10 @@ function installNodeModules(options: Schema): Rule {
|
|||
|
||||
export default function(options: Schema): Rule {
|
||||
return (host: Tree) => {
|
||||
options.name = options.name || getWorkspace(host).defaultProject;
|
||||
if (!options.name) {
|
||||
throw new Error('Please specify a project using "--name project-name"');
|
||||
}
|
||||
validateProjectName(options.name);
|
||||
|
||||
return chain([
|
||||
|
|
|
@ -55,6 +55,7 @@ describe('ng-add schematic', () => {
|
|||
},
|
||||
},
|
||||
},
|
||||
defaultProject: 'demo',
|
||||
}));
|
||||
schematicRunner =
|
||||
new SchematicTestRunner('@angular/bazel', require.resolve('../collection.json'));
|
||||
|
@ -202,6 +203,15 @@ describe('ng-add schematic', () => {
|
|||
expect(lint.builder).toBe('@angular-devkit/build-angular:tslint');
|
||||
});
|
||||
|
||||
it('should get defaultProject if name is not provided', () => {
|
||||
const options = {};
|
||||
host = schematicRunner.runSchematic('ng-add', options, host);
|
||||
const content = host.readContent('/angular.json');
|
||||
const json = JSON.parse(content);
|
||||
const builder = json.projects.demo.architect.build.builder;
|
||||
expect(builder).toBe('@angular/bazel:build');
|
||||
});
|
||||
|
||||
it('should create a backup for original tsconfig.json', () => {
|
||||
expect(host.files).toContain('/tsconfig.json');
|
||||
const original = host.readContent('/tsconfig.json');
|
||||
|
|
|
@ -9,7 +9,7 @@ export interface Schema {
|
|||
/**
|
||||
* The name of the project.
|
||||
*/
|
||||
name: string;
|
||||
name?: string;
|
||||
/**
|
||||
* When true, does not install dependency packages.
|
||||
*/
|
||||
|
|
|
@ -20,6 +20,5 @@
|
|||
}
|
||||
},
|
||||
"required": [
|
||||
"name"
|
||||
]
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue