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
88 lines (87 loc) • 3.51 kB
JavaScript
;
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());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.init = init;
const inquirer_1 = __importDefault(require("inquirer"));
const commander_1 = require("commander");
const fs_extra_1 = __importDefault(require("fs-extra"));
const create_example_project_1 = require("./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_extra_1.default.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 commander_1.Command('askui');
program.usage('<command> [options]');
return program;
};
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 commander_1.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_1.default.prompt(questions, userAnswers).then((answers) => __awaiter(this, void 0, void 0, function* () {
yield new create_example_project_1.CreateExampleProject(Object.assign(Object.assign({}, userAnswers), answers)).createExampleProject();
}));
}));
return program.parse(args);
}