import * as inquirer from 'inquirer' ; import { Answers , Question } from 'inquirer' ; import { getValueOrDefault } from '../compiler/helpers/get-value-or-default' ; import { Configuration , ProjectConfiguration } from '../configuration' ; import { generateSelect } from '../questions/questions' ; 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 ) { 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 ) { specConfiguration = getValueOrDefault ( configuration , 'generateOptions.spec' , '' ) ; if ( typeof specConfiguration === 'boolean' ) { return specConfiguration ; } if ( typeof specConfiguration === 'object' && specConfiguration [ schematic ] !== undefined ) { return specConfiguration [ schematic ] ; } } return specValue ; } export async function askForProjectName ( promptQuestion , projects ) { const questions = [ generateSelect ( 'appName' ) ( promptQuestion ) ( projects ) , ] ; const prompt = inquirer . createPromptModule ( ) ; return prompt ( questions ) ; } 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 ; }