import chalk = require('chalk'); import yargs = require('yargs'); import { NxCloudChoices, messages } from '../utils/nx/ab-testing'; import { packageManagerList } from '../utils/package-manager'; export function withNxCloud(argv: yargs.Argv) { const { message } = messages.getPrompt('setupCI'); const result = argv.option('nxCloud', { alias: 'ci', describe: chalk.dim(message), choices: NxCloudChoices, type: 'string', }); return result; } export function withAllPrompts(argv: yargs.Argv) { return argv.option('allPrompts', { alias: 'a', describe: chalk.dim`Show all prompts`, type: 'boolean', default: false, }); } export function withPackageManager(argv: yargs.Argv) { return argv.option('packageManager', { alias: 'pm', describe: chalk.dim`Package manager to use`, choices: [...packageManagerList].sort(), defaultDescription: 'npm', type: 'string', }); } export function withGitOptions(argv: yargs.Argv) { return argv .option('defaultBase', { defaultDescription: 'main', describe: chalk.dim`Default base to use for new projects`, type: 'string', }) .option('skipGit', { describe: chalk.dim`Skip initializing a git repository`, type: 'boolean', default: false, alias: 'g', }) .option('commit.name', { describe: chalk.dim`Name of the committer`, type: 'string', }) .option('commit.email', { describe: chalk.dim`E-mail of the committer`, type: 'string', }) .option('commit.message', { describe: chalk.dim`Commit message`, type: 'string', default: 'Initial commit', }); } export function withOptions( argv: yargs.Argv, ...options: ((argv: yargs.Argv) => yargs.Argv)[] ): any { // Reversing the options keeps the execution order correct. // e.g. [withCI, withGIT] should transform into withGIT(withCI) so withCI resolves first. return options.reverse().reduce((argv, option) => option(argv), argv); }