flagpole
Version:
Simple and fast DOM integration, headless or headful browser, and REST API testing framework.
136 lines • 6.01 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());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const command_1 = require("../command");
const cli_1 = require("../cli");
const flagpole_execution_1 = require("../../flagpole-execution");
const prompts = require("prompts");
const cli_helper_1 = require("../cli-helper");
const path_1 = require("path");
const flagpole_config_1 = require("../../flagpole-config");
const fs = require("fs-extra");
class Init extends command_1.Command {
constructor() {
super(...arguments);
this.commandString = "init";
this.description = "initialize Flagpole in this project";
}
action() {
return __awaiter(this, void 0, void 0, function* () {
cli_1.Cli.subheader("Initialize Flagpole Project");
const opts = yield getConfigOpts();
cli_1.Cli.log("Creating your Flagpole project...");
const configFile = new flagpole_config_1.FlagpoleConfig(opts, flagpole_execution_1.FlagpoleExecution.global.config.getConfigPath() || process.cwd());
yield fs.ensureDir(configFile.getConfigFolder());
yield fs.ensureDir(configFile.getRootFolder());
yield fs.ensureDir(configFile.getCacheFolder());
yield fs.ensureDir(configFile.getImagesFolder());
yield configFile.save();
if (configFile.project.isTypeScript) {
yield configFile.writeTsConfig();
yield fs.ensureDir(configFile.getTestsFolder());
yield fs.ensureDir(configFile.getSourceFolder());
}
cli_1.Cli.log("", "Your Flagpole project was created.").exit(0);
});
}
}
exports.default = Init;
function getConfigOpts() {
return __awaiter(this, void 0, void 0, function* () {
const projectName = yield promptForProjectName();
const environments = yield promptForEnvironments();
const domains = yield promptForDomains(environments);
const useTypeScript = yield promptIfWantToUseTypeScript();
const rootFolder = yield promptForRootFolder(useTypeScript);
const tsFolders = yield promptForTypeScriptFolders(rootFolder, useTypeScript);
return {
project: {
name: projectName,
path: rootFolder,
source: tsFolders === undefined ? undefined : tsFolders.sourceFolder,
output: tsFolders === undefined ? undefined : tsFolders.outputFolder,
},
environments: (() => {
const out = {};
environments.forEach((env) => {
out[env] = {
name: env,
defaultDomain: domains[`domain_${env}`],
};
});
return out;
})(),
suites: {},
};
});
}
function promptForDomains(environments) {
const domainPrompts = [];
environments.forEach((env) => {
domainPrompts.push(cli_helper_1.promptUrl(`domain_${env}`, `Default Domain for ${env}`));
});
return prompts(domainPrompts);
}
function promptIfWantToUseTypeScript() {
return __awaiter(this, void 0, void 0, function* () {
return (yield prompts(cli_helper_1.promptToggle("useTypeScript", "Do you want Flagpole to use TypeScript?", true))).useTypeScript;
});
}
function promptForRootFolder(useTypeScript) {
return __awaiter(this, void 0, void 0, function* () {
return (yield prompts(cli_helper_1.promptTextPath("path", useTypeScript
? "What subfolder do you want to put your tests in? (tsconfig.json will go here)"
: "What subfolder do you want to put your tests in?", "tests"))).path;
});
}
function promptForProjectName() {
return __awaiter(this, void 0, void 0, function* () {
return (yield prompts(cli_helper_1.promptTextName("project", "What is the name of your project?", process.cwd().split(path_1.sep).pop()))).project;
});
}
function promptForEnvironments() {
return __awaiter(this, void 0, void 0, function* () {
return (yield prompts(cli_helper_1.promptMultiSelect("env", "What environments do you want to support?", [
{ value: "dev", title: "dev" },
{ value: "stag", title: "stag" },
{ value: "prod", title: "prod" },
{ value: "preprod", title: "preprod" },
{ value: "qa", title: "qa" },
{ value: "local", title: "local" },
{ value: "alpha", title: "alpha" },
{ value: "beta", title: "beta" },
], 1, 8))).env;
});
}
function promptForTypeScriptFolders(rootFolder, useTypeScript) {
return __awaiter(this, void 0, void 0, function* () {
let tsFolders = undefined;
if (useTypeScript) {
tsFolders = yield prompts([
{
type: "text",
name: "sourceFolder",
message: `Source Folder ${rootFolder}/`,
initial: `src`,
},
{
type: "text",
name: "outputFolder",
message: `Output Folder ${rootFolder}/`,
initial: `out`,
},
]);
}
return tsFolders;
});
}
//# sourceMappingURL=init.js.map
;