mirror of
https://github.com/angular/angular-cli.git
synced 2025-05-18 03:23:57 +08:00
feat(@angular-devkit/core): support both 'targets' and 'architect' keys in workspace
This commit is contained in:
parent
a29a53e2ff
commit
aad5f83050
packages/angular_devkit/core/src/workspace
@ -33,6 +33,10 @@
|
||||
"$ref": "#/definitions/tool",
|
||||
"default": {}
|
||||
},
|
||||
"targets": {
|
||||
"$ref": "#/definitions/tool",
|
||||
"default": {}
|
||||
},
|
||||
"projects": {
|
||||
"type": "object",
|
||||
"description": "A map of project names to project options.",
|
||||
@ -83,6 +87,10 @@
|
||||
"architect": {
|
||||
"$ref": "#/definitions/tool",
|
||||
"default": {}
|
||||
},
|
||||
"targets": {
|
||||
"$ref": "#/definitions/tool",
|
||||
"default": {}
|
||||
}
|
||||
},
|
||||
"additionalProperties": false,
|
||||
|
@ -35,6 +35,10 @@ export interface WorkspaceSchema {
|
||||
* Tool options.
|
||||
*/
|
||||
architect?: WorkspaceTool;
|
||||
/**
|
||||
* Tool options.
|
||||
*/
|
||||
targets?: WorkspaceTool;
|
||||
/**
|
||||
* A map of project names to project options.
|
||||
*/
|
||||
@ -74,6 +78,10 @@ export interface WorkspaceProject {
|
||||
* Tool options.
|
||||
*/
|
||||
architect?: WorkspaceTool;
|
||||
/**
|
||||
* Tool options.
|
||||
*/
|
||||
targets?: WorkspaceTool;
|
||||
}
|
||||
/**
|
||||
* Architect options.
|
||||
|
@ -129,13 +129,14 @@ export class Workspace {
|
||||
throw new ProjectNotFoundException(projectName);
|
||||
}
|
||||
|
||||
return {
|
||||
...workspaceProject,
|
||||
// Return only the project properties, and remove the tools.
|
||||
cli: {},
|
||||
schematics: {},
|
||||
architect: {},
|
||||
};
|
||||
// Return only the project properties, and remove the tools.
|
||||
const workspaceProjectClone = {...workspaceProject};
|
||||
delete workspaceProjectClone['cli'];
|
||||
delete workspaceProjectClone['schematics'];
|
||||
delete workspaceProjectClone['architect'];
|
||||
delete workspaceProjectClone['targets'];
|
||||
|
||||
return workspaceProjectClone;
|
||||
}
|
||||
|
||||
getDefaultProjectName(): string | null {
|
||||
@ -209,8 +210,8 @@ export class Workspace {
|
||||
return this._getTool('schematics');
|
||||
}
|
||||
|
||||
getArchitect() {
|
||||
return this._getTool('architect');
|
||||
getTargets() {
|
||||
return this._getTool('targets');
|
||||
}
|
||||
|
||||
getProjectCli(projectName: string) {
|
||||
@ -221,14 +222,19 @@ export class Workspace {
|
||||
return this._getProjectTool(projectName, 'schematics');
|
||||
}
|
||||
|
||||
getProjectArchitect(projectName: string) {
|
||||
return this._getProjectTool(projectName, 'architect');
|
||||
getProjectTargets(projectName: string) {
|
||||
return this._getProjectTool(projectName, 'targets');
|
||||
}
|
||||
|
||||
private _getTool(toolName: 'cli' | 'schematics' | 'architect'): WorkspaceTool {
|
||||
private _getTool(toolName: 'cli' | 'schematics' | 'targets'): WorkspaceTool {
|
||||
this._assertLoaded();
|
||||
|
||||
const workspaceTool = this._workspace[toolName];
|
||||
let workspaceTool = this._workspace[toolName];
|
||||
|
||||
// Try falling back to 'architect' if 'targets' is not there or is empty.
|
||||
if ((!workspaceTool || Object.keys(workspaceTool).length === 0) && toolName === 'targets') {
|
||||
workspaceTool = this._workspace['architect'];
|
||||
}
|
||||
|
||||
if (!workspaceTool) {
|
||||
throw new WorkspaceToolNotFoundException(toolName);
|
||||
@ -238,7 +244,7 @@ export class Workspace {
|
||||
}
|
||||
|
||||
private _getProjectTool(
|
||||
projectName: string, toolName: 'cli' | 'schematics' | 'architect',
|
||||
projectName: string, toolName: 'cli' | 'schematics' | 'targets',
|
||||
): WorkspaceTool {
|
||||
this._assertLoaded();
|
||||
|
||||
@ -248,7 +254,13 @@ export class Workspace {
|
||||
throw new ProjectNotFoundException(projectName);
|
||||
}
|
||||
|
||||
const projectTool = workspaceProject[toolName];
|
||||
let projectTool = workspaceProject[toolName];
|
||||
|
||||
// Try falling back to 'architect' if 'targets' is not there or is empty.
|
||||
if ((!projectTool || Object.keys(projectTool).length === 0) && toolName === 'targets') {
|
||||
projectTool = workspaceProject['architect'];
|
||||
}
|
||||
|
||||
|
||||
if (!projectTool) {
|
||||
throw new ProjectToolNotFoundException(toolName);
|
||||
|
@ -48,7 +48,7 @@ describe('Workspace', () => {
|
||||
},
|
||||
},
|
||||
},
|
||||
architect: {},
|
||||
targets: {},
|
||||
projects: {
|
||||
app: {
|
||||
root: 'projects/app',
|
||||
@ -63,7 +63,7 @@ describe('Workspace', () => {
|
||||
},
|
||||
},
|
||||
},
|
||||
architect: {
|
||||
targets: {
|
||||
build: {
|
||||
builder: '@angular-devkit/build-angular:browser',
|
||||
transforms: [
|
||||
@ -101,13 +101,11 @@ describe('Workspace', () => {
|
||||
},
|
||||
},
|
||||
};
|
||||
const appProject = {
|
||||
...workspaceJson.projects['app'],
|
||||
// Tools should not be returned when getting a project.
|
||||
cli: {},
|
||||
schematics: {},
|
||||
architect: {},
|
||||
} as {} as WorkspaceProject;
|
||||
// Tools should not be returned when getting a project.
|
||||
const appProject = { ...workspaceJson.projects['app'] };
|
||||
delete appProject['cli'];
|
||||
delete appProject['schematics'];
|
||||
delete appProject['targets'];
|
||||
|
||||
it('loads workspace from json', (done) => {
|
||||
const workspace = new Workspace(root, host);
|
||||
@ -246,10 +244,20 @@ describe('Workspace', () => {
|
||||
).toPromise().then(done, done.fail);
|
||||
});
|
||||
|
||||
it('gets workspace architect', (done) => {
|
||||
it('gets workspace targets', (done) => {
|
||||
const workspace = new Workspace(root, host);
|
||||
workspace.loadWorkspaceFromJson(workspaceJson).pipe(
|
||||
tap((ws) => expect(ws.getArchitect()).toEqual(workspaceJson.architect as WorkspaceTool)),
|
||||
tap((ws) => expect(ws.getTargets()).toEqual(workspaceJson.targets as WorkspaceTool)),
|
||||
).toPromise().then(done, done.fail);
|
||||
});
|
||||
|
||||
it('gets workspace architect when targets is not there', (done) => {
|
||||
const workspace = new Workspace(root, host);
|
||||
const workspaceJsonClone = { ...workspaceJson };
|
||||
workspaceJsonClone['architect'] = workspaceJsonClone['targets'];
|
||||
delete workspaceJsonClone['targets'];
|
||||
workspace.loadWorkspaceFromJson(workspaceJsonClone).pipe(
|
||||
tap((ws) => expect(ws.getTargets()).toEqual(workspaceJson.targets as WorkspaceTool)),
|
||||
).toPromise().then(done, done.fail);
|
||||
});
|
||||
|
||||
@ -269,11 +277,26 @@ describe('Workspace', () => {
|
||||
).toPromise().then(done, done.fail);
|
||||
});
|
||||
|
||||
it('gets project architect', (done) => {
|
||||
it('gets project targets', (done) => {
|
||||
const workspace = new Workspace(root, host);
|
||||
workspace.loadWorkspaceFromJson(workspaceJson).pipe(
|
||||
tap((ws) => expect(ws.getProjectArchitect('app'))
|
||||
.toEqual(workspaceJson.projects.app.architect as WorkspaceTool)),
|
||||
tap((ws) => expect(ws.getProjectTargets('app'))
|
||||
.toEqual(workspaceJson.projects.app.targets as WorkspaceTool)),
|
||||
).toPromise().then(done, done.fail);
|
||||
});
|
||||
|
||||
it('gets project architect when targets is not there', (done) => {
|
||||
const workspace = new Workspace(root, host);
|
||||
const appJsonClone = { ...workspaceJson.projects.app };
|
||||
appJsonClone['architect'] = appJsonClone['targets'];
|
||||
delete appJsonClone['targets'];
|
||||
const simpleWorkspace = {
|
||||
version: 1,
|
||||
projects: { app: appJsonClone },
|
||||
};
|
||||
workspace.loadWorkspaceFromJson(simpleWorkspace).pipe(
|
||||
tap((ws) => expect(ws.getProjectTargets('app'))
|
||||
.toEqual(workspaceJson.projects.app.targets as WorkspaceTool)),
|
||||
).toPromise().then(done, done.fail);
|
||||
});
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user