Skip to content

Commit cbc824a

Browse files
clydinBrocco
authored andcommitted
refactor(@angular/cli): cleanup config schematic defaults
1 parent 8e169b8 commit cbc824a

File tree

1 file changed

+43
-10
lines changed

1 file changed

+43
-10
lines changed

packages/@angular/cli/utilities/config.ts

Lines changed: 43 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,8 @@ export function getPackageManager(): string {
146146

147147
if (workspace) {
148148
const project = getProjectByCwd(workspace);
149-
if (project && workspace.getProject(project).cli) {
150-
const value = workspace.getProject(project).cli['packageManager'];
149+
if (project && workspace.getProjectCli(project)) {
150+
const value = workspace.getProjectCli(project)['packageManager'];
151151
if (typeof value == 'string') {
152152
return value;
153153
}
@@ -175,22 +175,22 @@ export function getDefaultSchematicCollection(): string {
175175

176176
if (workspace) {
177177
const project = getProjectByCwd(workspace);
178-
if (project && workspace.getProject(project).schematics) {
179-
const value = workspace.getProject(project).schematics['defaultCollection'];
178+
if (project && workspace.getProjectCli(project)) {
179+
const value = workspace.getProjectCli(project)['defaultCollection'];
180180
if (typeof value == 'string') {
181181
return value;
182182
}
183-
} else if (workspace.getSchematics()) {
184-
const value = workspace.getSchematics()['defaultCollection'];
183+
} else if (workspace.getCli()) {
184+
const value = workspace.getCli()['defaultCollection'];
185185
if (typeof value == 'string') {
186186
return value;
187187
}
188188
}
189189
}
190190

191191
workspace = getWorkspace('global');
192-
if (workspace && workspace.getSchematics()) {
193-
const value = workspace.getSchematics()['defaultCollection'];
192+
if (workspace && workspace.getCli()) {
193+
const value = workspace.getCli()['defaultCollection'];
194194
if (typeof value == 'string') {
195195
return value;
196196
}
@@ -199,13 +199,46 @@ export function getDefaultSchematicCollection(): string {
199199
return '@schematics/angular';
200200
}
201201

202+
export function getSchematicDefaults(collection: string, schematic: string, project?: string): {} {
203+
let result = {};
204+
205+
let workspace = getWorkspace('global');
206+
if (workspace && workspace.getSchematics()) {
207+
const collectionObject = workspace.getSchematics()[collection];
208+
if (typeof collectionObject == 'object' && !Array.isArray(collectionObject)) {
209+
result = collectionObject[schematic] || {};
210+
}
211+
}
212+
213+
workspace = getWorkspace('local');
214+
215+
if (workspace) {
216+
if (workspace.getSchematics()) {
217+
const collectionObject = workspace.getSchematics()[collection];
218+
if (typeof collectionObject == 'object' && !Array.isArray(collectionObject)) {
219+
result = { ...result, ...(collectionObject[schematic] as {}) };
220+
}
221+
}
222+
223+
project = project || getProjectByCwd(workspace);
224+
if (project && workspace.getProjectSchematics(project)) {
225+
const collectionObject = workspace.getProjectSchematics(project)[collection];
226+
if (typeof collectionObject == 'object' && !Array.isArray(collectionObject)) {
227+
result = { ...result, ...(collectionObject[schematic] as {}) };
228+
}
229+
}
230+
}
231+
232+
return result;
233+
}
234+
202235
export function isWarningEnabled(warning: string): boolean {
203236
let workspace = getWorkspace('local');
204237

205238
if (workspace) {
206239
const project = getProjectByCwd(workspace);
207-
if (project && workspace.getProject(project).cli) {
208-
const warnings = workspace.getProject(project).cli['warnings'];
240+
if (project && workspace.getProjectCli(project)) {
241+
const warnings = workspace.getProjectCli(project)['warnings'];
209242
if (typeof warnings == 'object' && !Array.isArray(warnings)) {
210243
const value = warnings[warning];
211244
if (typeof value == 'boolean') {

0 commit comments

Comments
 (0)