Skip to content
Closed
Show file tree
Hide file tree
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
10 changes: 1 addition & 9 deletions packages/angular/cli/src/command-builder/command-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/

import { analytics, logging, normalize, schema, strings } from '@angular-devkit/core';
import { analytics, logging, schema, strings } from '@angular-devkit/core';
import { readFileSync } from 'fs';
import * as path from 'path';
import {
Expand Down Expand Up @@ -197,8 +197,6 @@ export abstract class CommandModule<T extends {} = {}> implements CommandModuleI
* **Note:** This method should be called from the command bundler method.
*/
protected addSchemaOptionsToCommand<T>(localYargs: Argv<T>, options: Option[]): Argv<T> {
const workingDir = normalize(path.relative(this.context.root, process.cwd()));

for (const option of options) {
const {
default: defaultVal,
Expand All @@ -211,7 +209,6 @@ export abstract class CommandModule<T extends {} = {}> implements CommandModuleI
hidden,
name,
choices,
format,
} = option;

const sharedOptions: YargsOptions & PositionalOptions = {
Expand All @@ -224,11 +221,6 @@ export abstract class CommandModule<T extends {} = {}> implements CommandModuleI
...(this.context.args.options.help ? { default: defaultVal } : {}),
};

// Special case for schematics
if (workingDir && format === 'path' && name === 'path' && hidden) {
sharedOptions.default = workingDir;
}

if (positional === undefined) {
localYargs = localYargs.option(strings.dasherize(name), {
type,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
* found in the LICENSE file at https://angular.io/license
*/

import { schema, tags } from '@angular-devkit/core';
import { normalize as devkitNormalize, isJsonObject, schema, tags } from '@angular-devkit/core';
import { Collection, UnsuccessfulWorkflowExecution, formats } from '@angular-devkit/schematics';
import {
FileSystemCollectionDescription,
FileSystemSchematicDescription,
NodeWorkflow,
} from '@angular-devkit/schematics/tools';
import type { CheckboxQuestion, Question } from 'inquirer';
import { resolve } from 'path';
import { relative, resolve } from 'path';
import { Argv } from 'yargs';
import { getProjectByCwd, getSchematicDefaults } from '../utilities/config';
import { memoize } from '../utilities/memoize';
Expand Down Expand Up @@ -137,6 +137,8 @@ export abstract class SchematicsCommandModule
workflow.registry.useXDeprecatedProvider((msg) => logger.warn(msg));

let shouldReportAnalytics = true;
const workingDir = devkitNormalize(relative(this.context.root, process.cwd()));

workflow.engineHost.registerOptionsTransform(async (schematic, options) => {
if (shouldReportAnalytics) {
shouldReportAnalytics = false;
Expand All @@ -150,6 +152,30 @@ export abstract class SchematicsCommandModule
]);
}

// Handle `"format": "path"` options.
const schema = schematic?.schemaJson;
if (!options || workingDir === '' || !schema || !isJsonObject(schema)) {
return options;
}

if (!('path' in options && (options as Record<string, unknown>)['path'] === undefined)) {
return options;
}

const properties = schema?.['properties'];
if (!properties || !isJsonObject(properties)) {
return options;
}

const property = properties['path'];
if (!property || !isJsonObject(property)) {
return options;
}

if (property['format'] === 'path') {
(options as Record<string, unknown>)['path'] = workingDir;
}

return options;
});

Expand Down