quicksilver-cli
Version:
Cli tool for Quicksilver
69 lines (68 loc) • 3.31 kB
JavaScript
;
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
const command_1 = require("./command");
const TomcatUtil = __importStar(require("../util/tomcat"));
const field_1 = require("./field/field");
const GradleUtil = __importStar(require("../util/gradle"));
const ProjectUtil = __importStar(require("../util/project"));
const prompt_1 = require("../util/prompt");
const colors = require("colors");
const path = require("path");
class RunCommand extends command_1.Command {
async init() {
await super.init();
await ProjectUtil.validateGradleProject(this.workspace, this.cacheKeyWorkspace);
}
async afterParse() {
await super.afterParse();
const runNames = ProjectUtil.getRunNames(this.workspace);
if (runNames.length == 0) {
return Promise.reject(`Not exists a run-sub projects in ${this.rootProjectName}.\n Try to run: ` + colors.bold.green(`qs create --run`));
}
this.args.name = await prompt_1.prompt({
question: `Please input a run project name from [${runNames.join(",")}].`,
value: (this.args.name || ""),
validators: [{ message: "A invalid run-sub project name '${value}'.", predictor: value => runNames.includes(value) }]
});
this.projectName = `${this.rootProjectName}-run` + (this.args.name == "" ? "" : `-${this.args.name}`);
this.projectPath = path.join(this.workspace, this.projectName);
this.logger.info(`The name of run-sub project is ${this.projectName}.`);
}
async run() {
await ProjectUtil.createBuildProjectIfNotExists(this.workspace);
const tomcatHome = await this.prepareTomcat();
await GradleUtil.build(this.workspace);
await TomcatUtil.copyWar(this.projectPath, tomcatHome);
await TomcatUtil.runCatalina(this.workspace, tomcatHome);
}
async prepareTomcat() {
const tomcat = await ProjectUtil.initTomcatInfo(this.workspace);
await TomcatUtil.addCommentsToLoggingEncoding(tomcat.home);
await TomcatUtil.modifyPort(tomcat.home, tomcat.httpPort);
await TomcatUtil.addCommentToAjpConnector(tomcat.home);
await TomcatUtil.shutdown(tomcat.home);
await TomcatUtil.clearAppDir(tomcat.home);
return tomcat.home;
}
async validate() {
await super.validate();
const existRunProject = ProjectUtil.existsSubGradleProject(this.projectPath);
if (!existRunProject) {
return Promise.reject(`Not exists run-sub Project with path '${this.projectPath}'.`);
}
}
}
RunCommand.NAME = "run";
RunCommand.ALIAS = ["r"];
RunCommand.FIELDS = [
{ name: "name", description: "The name of run-sub project.", type: field_1.FieldType.String, defaultIndex: 0 }
];
RunCommand.DESCRIPTION = "Before Running a run-sub project, you can modify tomcat.json and environment according to your computer.";
exports.RunCommand = RunCommand;