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