Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions packages/angular/cli/models/schematic-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
} from '@angular-devkit/schematics/tools';
import * as inquirer from 'inquirer';
import * as systemPath from 'path';
import { resolve } from 'path';
import { colors } from '../utilities/color';
import { getProjectByCwd, getSchematicDefaults, getWorkspace } from '../utilities/config';
import { parseJsonSchemaToOptions } from '../utilities/json-schema';
Expand Down Expand Up @@ -373,20 +374,26 @@ export abstract class SchematicCommand<
}

protected async getDefaultSchematicCollection(): Promise<string> {
// Resolve relative collections from the location of `angular.json`
const resolveRelativeCollection = (collectionName: string) =>
collectionName.charAt(0) === '.'
? resolve(this.context.root, collectionName)
: collectionName;

let workspace = await getWorkspace('local');

if (workspace) {
const project = getProjectByCwd(workspace);
if (project && workspace.getProjectCli(project)) {
const value = workspace.getProjectCli(project)['defaultCollection'];
if (typeof value == 'string') {
return value;
return resolveRelativeCollection(value);
}
}
if (workspace.getCli()) {
const value = workspace.getCli()['defaultCollection'];
if (typeof value == 'string') {
return value;
return resolveRelativeCollection(value);
}
}
}
Expand All @@ -395,7 +402,7 @@ export abstract class SchematicCommand<
if (workspace && workspace.getCli()) {
const value = workspace.getCli()['defaultCollection'];
if (typeof value == 'string') {
return value;
return resolveRelativeCollection(value);
}
}

Expand Down