|
6 | 6 | * found in the LICENSE file at https://angular.io/license
|
7 | 7 | */
|
8 | 8 |
|
9 |
| -import { schema, tags } from '@angular-devkit/core'; |
| 9 | +import { JsonObject, isJsonObject, schema, tags } from '@angular-devkit/core'; |
10 | 10 | import { Collection, UnsuccessfulWorkflowExecution, formats } from '@angular-devkit/schematics';
|
11 | 11 | import {
|
12 | 12 | FileSystemCollectionDescription,
|
13 | 13 | FileSystemSchematicDescription,
|
14 | 14 | NodeWorkflow,
|
15 | 15 | } from '@angular-devkit/schematics/tools';
|
16 | 16 | import type { CheckboxQuestion, Question } from 'inquirer';
|
17 |
| -import { resolve } from 'path'; |
| 17 | +import { normalize, relative, resolve } from 'path'; |
18 | 18 | import { Argv } from 'yargs';
|
19 | 19 | import { getProjectByCwd, getSchematicDefaults } from '../utilities/config';
|
20 | 20 | import { memoize } from '../utilities/memoize';
|
@@ -150,6 +150,37 @@ export abstract class SchematicsCommandModule
|
150 | 150 | ]);
|
151 | 151 | }
|
152 | 152 |
|
| 153 | + // Handle `"format": "path"` options. |
| 154 | + const schema = schematic?.schemaJson; |
| 155 | + if (!options || !schema || !isJsonObject(schema)) { |
| 156 | + return options; |
| 157 | + } |
| 158 | + |
| 159 | + const workingDir = normalize(relative(this.context.root, process.cwd())); |
| 160 | + |
| 161 | + for (const [key, value] of Object.entries(options)) { |
| 162 | + if (value !== undefined) { |
| 163 | + continue; |
| 164 | + } |
| 165 | + |
| 166 | + const properties = schema?.['properties']; |
| 167 | + if (!properties || !isJsonObject(properties)) { |
| 168 | + break; |
| 169 | + } |
| 170 | + |
| 171 | + const property = properties[key]; |
| 172 | + if (!property || !isJsonObject(property)) { |
| 173 | + continue; |
| 174 | + } |
| 175 | + |
| 176 | + if (property['format'] === 'path') { |
| 177 | + options = { |
| 178 | + ...options, |
| 179 | + [key]: workingDir, |
| 180 | + }; |
| 181 | + } |
| 182 | + } |
| 183 | + |
153 | 184 | return options;
|
154 | 185 | });
|
155 | 186 |
|
|
0 commit comments