@nestjs/cli
Version:
The Nest CLI: create NestJS applications, generate modules, controllers and CRUD resources, and build, run and watch projects and monorepos.
43 lines (42 loc) • 1.95 kB
JavaScript
import { dirname } from 'path';
import { fileURLToPath } from 'url';
import { normalizeToKebabOrSnakeCase } from '../utils/formatting.js';
/**
* The `x-prompt` questions of a schematic that the given options leave open,
* each with the default the schematic falls back to when it can't ask.
* Empty when the schematic's schema can't be read, so a collection the CLI
* can't resolve still runs, just without the summary.
*/
export async function getSkippedPrompts(collection, schematic, options) {
try {
const { NodeWorkflow } = await import('@angular-devkit/schematics/tools/index.js');
// The project's own install first, then the one next to the CLI, the
// same order the schematics binary resolves collections in.
const workflow = new NodeWorkflow(process.cwd(), {
resolvePaths: [process.cwd(), dirname(fileURLToPath(import.meta.url))],
});
const { schemaJson } = workflow.engine
.createCollection(collection)
.createSchematic(schematic).description;
const properties = (schemaJson?.properties ?? {});
const given = new Set(options.map((option) => option.normalizedName));
return Object.entries(properties)
.filter(([name, property]) => property['x-prompt'] !== undefined &&
!given.has(normalizeToKebabOrSnakeCase(name)))
.map(([name, property]) => ({ name, default: property.default }));
}
catch {
return [];
}
}
/** How a skipped prompt was answered, as the flag that answers it the same. */
export function describeSkippedPrompt({ name, default: value, }) {
const flag = `--${normalizeToKebabOrSnakeCase(name)}`;
if (value === undefined) {
return `${flag} (the schematic's own default)`;
}
if (typeof value === 'boolean') {
return value ? flag : `--no-${normalizeToKebabOrSnakeCase(name)}`;
}
return `${flag} ${String(value)}`;
}