flagpole
Version:
Simple and fast DOM integration, headless or headful browser, and REST API testing framework.
103 lines • 4.88 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 flagpoleexecution_1 = require("../../flagpoleexecution");
const child_process_1 = require("child_process");
const prompts = require("prompts");
const cli_helper_1 = require("../cli-helper");
class Build extends command_1.Command {
constructor() {
super(...arguments);
this.commandString = "build";
this.description = "transpile tests from TypeScript to JavaScript";
}
action() {
return __awaiter(this, void 0, void 0, function* () {
yield tsc(true);
});
}
}
exports.default = Build;
function tsc(exitOnSuccess = true) {
return __awaiter(this, void 0, void 0, function* () {
cli_helper_1.printSubheader("Build TypeScript Tests");
if (!(yield isTscInstalled(3, 7, 0))) {
return cli_1.Cli.log(`Must have TypeScript installed globally, with at least version 3.7.0`, "", "Use this command:", "npm i -g typescript", "").exit(1);
}
if (flagpoleexecution_1.FlagpoleExecution.global.config.project.isTypeScript) {
cli_helper_1.printLine("Transpiling TypeScript to JavaScript...");
try {
yield flagpoleexecution_1.FlagpoleExecution.global.config.tsc();
cli_helper_1.printLine("Done!");
if (exitOnSuccess) {
cli_1.Cli.exit(0);
}
}
catch (err) {
cli_1.Cli.log(String(err)).exit(1);
}
return;
}
cli_1.Cli.log("This project is not currently configured to use TypeScript with Flagpole.", "");
const useTypeScript = yield doYouWantToConfigureTypeScript();
if (!useTypeScript) {
cli_1.Cli.exit(1);
return;
}
const rootFolder = yield setRootFolder();
const sourceFolder = yield setSourceFolder(rootFolder);
const outputFolder = yield setOutputFolder(rootFolder);
flagpoleexecution_1.FlagpoleExecution.global.config.project.setTypeScriptFolders(rootFolder, sourceFolder, outputFolder);
yield flagpoleexecution_1.FlagpoleExecution.global.config.save();
yield flagpoleexecution_1.FlagpoleExecution.global.config.writeTsConfig();
cli_1.Cli.log("");
});
}
exports.tsc = tsc;
const isTscInstalled = (major, minor, build) => __awaiter(void 0, void 0, void 0, function* () {
const result = child_process_1.execSync("tsc -v");
const match = result.toString().match(/ ([1-9]+\.[0-9]+\.[0-9]+)/);
if (match === null) {
return false;
}
const version = match[1].split(".").map((n) => parseInt(n));
return (version[0] > major ||
(version[0] == major && version[1] > minor) ||
(version[0] == major && version[1] == minor && version[2] >= build));
});
const doYouWantToConfigureTypeScript = () => {
return new Promise((resolve) => __awaiter(void 0, void 0, void 0, function* () {
const response = yield prompts({
type: "toggle",
name: "useTypeScript",
message: "Configure this project to use TypeScript?",
initial: true,
active: "Yes",
inactive: "No",
});
resolve(response.useTypeScript);
}));
};
const setRootFolder = () => __awaiter(void 0, void 0, void 0, function* () {
const response = yield prompts(cli_helper_1.promptTextPath("rootFolder", "Flagpole Root Folder", `${flagpoleexecution_1.FlagpoleExecution.global.config.project.path}`));
return response.rootFolder;
});
const setSourceFolder = (rootFolder) => __awaiter(void 0, void 0, void 0, function* () {
const response = yield prompts(cli_helper_1.promptTextPath("sourceFolder", `Source Folder ${rootFolder}/`, `src`));
return response.sourceFolder;
});
const setOutputFolder = (rootFolder) => __awaiter(void 0, void 0, void 0, function* () {
const response = yield prompts(cli_helper_1.promptTextPath("outputFolder", `Output Folder ${rootFolder}/`, `out`));
return response.outputFolder;
});
//# sourceMappingURL=build.js.map