@ajhenry/stack
Version:
A CLI to bootstrap dev environments lightning fast ⚡
92 lines (91 loc) • 3.62 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const command_1 = require("@oclif/command");
const path_1 = require("path");
const constants_1 = require("../constants");
const logger_1 = tslib_1.__importDefault(require("../logger"));
const parser_1 = tslib_1.__importDefault(require("../parser"));
const runner_1 = tslib_1.__importDefault(require("../runner"));
class Repo extends command_1.Command {
run() {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const { args, flags } = this.parse(Repo);
const { project, directory } = args;
const { overwrite, branch, path, debug, common, start } = flags;
const projectRegex = /([a-z]|[A-Z]|[0-9]|-|_)+\/([a-z]|[A-Z]|[0-9]|-|_)+/g;
if (project.match(projectRegex)[0] !== project) {
logger_1.default.debug(`${project} did not match regex`);
throw new Error("Project does not match format `org/repo`");
}
logger_1.default.setSettings({ minLevel: debug ? "debug" : "info" });
try {
logger_1.default.debug(project);
logger_1.default.debug(directory);
const parser = new parser_1.default();
let stackFile;
if (common) {
stackFile = yield parser.useCommonStack(project, common);
}
else {
stackFile = yield parser.readGitHub(project, { branch, path });
}
logger_1.default.debug(stackFile);
const workingDir = directory !== null && directory !== void 0 ? directory : path_1.join(constants_1.CWD, project.split("/")[1]);
logger_1.default.debug(workingDir);
const runner = new runner_1.default(stackFile, workingDir, { overwrite, start });
yield runner.run();
}
catch (e) {
logger_1.default.error("Caught an error");
logger_1.default.error(e);
this.exit(1);
}
this.exit(0);
});
}
}
exports.default = Repo;
Repo.description = "Bootstrap a project via a local .stack file and start the dev environment";
Repo.flags = {
help: command_1.flags.help({ char: "h" }),
branch: command_1.flags.string({
char: "b",
description: "Branch to use when looking for stack file, default is repo's default",
}),
overwrite: command_1.flags.boolean({
char: "o",
default: false,
description: "Overwrite the specified directory",
}),
path: command_1.flags.string({
char: "p",
description: "Path to look for stack file in repo",
}),
debug: command_1.flags.boolean({
char: "d",
default: false,
description: "Enable debug mode",
}),
common: command_1.flags.string({
char: "c",
description: "Select a common utility to use to start the project",
}),
start: command_1.flags.boolean({
char: "s",
default: true,
description: "Flag for starting the dev environment",
}),
};
Repo.args = [
{
name: "project",
description: "GitHub project (org/repo) to read the stack file from",
required: true,
},
{
name: "directory",
description: "Directory to install to, default is the project's repo name",
optional: true,
},
];