UNPKG

askui

Version:

Reliable, automated end-to-end-testing that depends on what is shown on your screen instead of the technology you are running on

82 lines (81 loc) 3.15 kB
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; import inquirer from 'inquirer'; import { Command, Option } from 'commander'; import fs from 'fs-extra'; import { CreateExampleProject } from './create-example-project'; /* eslint-disable sort-keys */ const questions = [ { type: 'list', name: 'testFramework', message: 'Which framework do you prefer?:', choices: ['jest'], }, { type: 'confirm', name: 'typescriptConfig', message: 'Do you want to overwrite the tsconfig.json file? Default No:', default: false, when: (_answers) => fs.existsSync('tsconfig.json'), }, ]; /* eslint-enable */ const options = [ { choices: ['jest'], default: 'jest', description: 'the test framework to use.', option: '-f, --test-framework <value>', }, { choices: [], default: 'askui_example', description: 'a name for the directory askui stores its configuration and workflows in.', option: '-ad, --automations-directory <value>', }, { choices: [], description: 'overwrite tsconfig.json flag', option: '-t, --typescript-config', }, ]; const createProgram = () => { const program = new Command('askui'); program.usage('<command> [options]'); return program; }; export function init(argv) { const args = argv || process.argv; const program = createProgram(); const programInit = program.command('init'); // To Ensure Backwards Compatibility programInit.allowUnknownOption(true); programInit.description('Creates an AskUI example project:'); // Loop through the options object and register each option with the program options.forEach((opt) => { const tempOption = new Option(opt.option, opt.description); if (opt.choices.length > 0) { tempOption.choices(opt.choices); } if (opt.default) { tempOption.default(opt.default); } programInit.addOption(tempOption); }); programInit.usage('[options]'); programInit.action((_opts) => __awaiter(this, void 0, void 0, function* () { const userAnswers = programInit.opts(); inquirer.prompt(questions, userAnswers).then((answers) => __awaiter(this, void 0, void 0, function* () { yield new CreateExampleProject(Object.assign(Object.assign({}, userAnswers), answers)).createExampleProject(); })); })); return program.parse(args); }