UNPKG

@quo0/stiletto

Version:

With stiletto library you will be able to mock requests and choose between preconfigured responses right on the fly via UI

70 lines 2.67 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.mapToBoolean = exports.parseProvidedPath = exports.normalizeStilettoPath = exports.trimAndEnsureSlasheAtTheStart = exports.checkPathIsNotExists = exports.checkLength = exports.newSetupQuestions = void 0; const tslib_1 = require("tslib"); const fs_1 = require("../../services/fs"); const constants_1 = require("../../constants"); exports.newSetupQuestions = [ { name: 'setupName', type: 'input', message: 'Please name your setup:', default: 'Default', validate: checkLength, }, { name: 'setupPath', type: 'input', message: 'Please specify path to folder where we should store this setup:', default: '/stiletto', validate: checkPathIsNotExists, filter: parseProvidedPath, }, { name: 'defaultExtension', type: 'list', message: 'Please chose configuration files extension', choices: constants_1.FILE_EXTENSIONS, default: 'ts', }, { name: 'launchPersistentContext', type: 'list', message: 'Do you want to save cookies, localstorage on browser close?', choices: ['yes', 'no'], default: 'no', filter: mapToBoolean, }, ]; function checkLength(providedSetupName) { return !!providedSetupName.length; } exports.checkLength = checkLength; function checkPathIsNotExists(providedPath, answers) { return (0, tslib_1.__awaiter)(this, void 0, void 0, function* () { return !(yield (0, fs_1.pathExists)(`${providedPath}/${answers.setupName}`)); }); } exports.checkPathIsNotExists = checkPathIsNotExists; function trimAndEnsureSlasheAtTheStart(path) { const slashesInTheStart = /^\/*/; const pathWithoutSlashesAtTheStart = path.trim().replace(slashesInTheStart, ''); return `/${pathWithoutSlashesAtTheStart}`; } exports.trimAndEnsureSlasheAtTheStart = trimAndEnsureSlasheAtTheStart; function normalizeStilettoPath(providedPath, answers) { if (providedPath.endsWith(`/${answers.setupName}`)) { return providedPath; } return `${providedPath}/${answers.setupName}`; } exports.normalizeStilettoPath = normalizeStilettoPath; function parseProvidedPath(providedPath, answers) { return trimAndEnsureSlasheAtTheStart(normalizeStilettoPath(providedPath, answers)); } exports.parseProvidedPath = parseProvidedPath; function mapToBoolean(providedChoice) { return providedChoice === 'yes'; } exports.mapToBoolean = mapToBoolean; //# sourceMappingURL=new-setup-questions.js.map