UNPKG

@nestjs/cli

Version:

Nest - modern, fast, powerful node.js web framework (@cli)

72 lines (71 loc) 3.29 kB
import { select } from '@inquirer/prompts'; import { getValueOrDefault } from '../compiler/helpers/get-value-or-default.js'; import { generateSelect } from '../questions/questions.js'; import { gracefullyExitOnPromptError } from './gracefully-exit-on-prompt-error.js'; export function shouldAskForProject(schematic, configurationProjects, appName) { return (['app', 'sub-app', 'library', 'lib'].includes(schematic) === false && configurationProjects && Object.entries(configurationProjects).length !== 0 && !appName); } export function shouldGenerateSpec(configuration, schematic, appName, specValue, specPassedAsInput) { if (specPassedAsInput === true || specPassedAsInput === undefined) { // CLI parameters has the highest priority return specValue; } let specConfiguration = getValueOrDefault(configuration, 'generateOptions.spec', appName || ''); if (typeof specConfiguration === 'boolean') { return specConfiguration; } if (typeof specConfiguration === 'object' && specConfiguration[schematic] !== undefined) { return specConfiguration[schematic]; } if (typeof specConfiguration === 'object' && appName) { // The appName has a generateOption spec, but not for the schematic trying to generate // Check if the global generateOptions has a spec to use instead specConfiguration = getValueOrDefault(configuration, 'generateOptions.spec', ''); if (typeof specConfiguration === 'boolean') { return specConfiguration; } if (typeof specConfiguration === 'object' && specConfiguration[schematic] !== undefined) { return specConfiguration[schematic]; } } return specValue; } export function shouldGenerateFlat(configuration, appName, flatValue) { // CLI parameters have the highest priority if (flatValue === true) { return flatValue; } const flatConfiguration = getValueOrDefault(configuration, 'generateOptions.flat', appName || ''); if (typeof flatConfiguration === 'boolean') { return flatConfiguration; } return flatValue; } export function getSpecFileSuffix(configuration, appName, specFileSuffixValue) { // CLI parameters have the highest priority if (specFileSuffixValue) { return specFileSuffixValue; } const specFileSuffixConfiguration = getValueOrDefault(configuration, 'generateOptions.specFileSuffix', appName || '', undefined, undefined, 'spec'); if (typeof specFileSuffixConfiguration === 'string') { return specFileSuffixConfiguration; } return specFileSuffixValue; } export async function askForProjectName(promptQuestion, projects) { const projectNameSelect = generateSelect('appName')(promptQuestion)(projects); return select(projectNameSelect).catch(gracefullyExitOnPromptError); } export function moveDefaultProjectToStart(configuration, defaultProjectName, defaultLabel) { let projects = configuration.projects != null ? Object.keys(configuration.projects) : []; if (configuration.sourceRoot !== 'src') { projects = projects.filter((p) => p !== defaultProjectName.replace(defaultLabel, '')); } projects.unshift(defaultProjectName); return projects; }