UNPKG

quicksilver-cli

Version:
77 lines (76 loc) 4.28 kB
"use strict"; 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 field_1 = require("./field/field"); const GradleUtil = __importStar(require("../util/gradle")); const ProjectUtil = __importStar(require("../util/project")); const fs = __importStar(require("fs")); const path = __importStar(require("path")); const projectJson = require("../resources/project/project.json"); class NewCommand extends command_1.Command { async init() { await super.init(); let projectName = this.params.filter(param => /^[^-]/.test(param))[0]; const index = this.params.indexOf(projectName); projectName = await ProjectUtil.promptProject(projectName); if (index > -1) { this.params[index] = projectName; } this.rootProjectName = projectName; this.workspace = path.join(this.workspace, this.rootProjectName); if (ProjectUtil.existsGradleProject(this.workspace)) { return Promise.reject(`exists a gradle project named ${projectName}.`); } fs.mkdirSync(this.workspace, { recursive: true }); } async afterParse() { await super.afterParse(); this.args.group = await ProjectUtil.promptGroup(this.args.group); this.logger.info(`The group of root project is '${this.args.group}'.`); this.args.version = await ProjectUtil.promptVersion(this.args.version); this.logger.info(`The version of root project is '${this.args.version}'.`); this.args.nexus = projectJson.nexus; this.logger.info(`The url of remote nexus repository is '${this.args.nexus}'.`); this.args.quicksilver = await ProjectUtil.getQuicksilverDefaultVersion(); this.logger.info(`The dependent quicksilver version of the root project is '${this.args.quicksilver}'.`); this.args.tomcat = await ProjectUtil.promptTomcat(this.workspace, "./apache-tomcat"); this.logger.info(`The tomcat home of the root project is '${this.args.tomcat}'.`); this.args.port = await ProjectUtil.promptHttpPort(this.args.port); this.logger.info(`The run-sub project starts with port '${this.args.port}'.`); } async initLogger() { await super.initLogger(); this.logger.info(`The name of the root project is ${this.rootProjectName}.`); } async run() { const tomcatJson = { home: this.args.tomcat, httpPort: this.args.port }; ProjectUtil.writeTomcatConfigFile(this.workspace, tomcatJson); this.logger.info(`Generated ${ProjectUtil.tomcatConfigFile} for run-sub projects.`); ProjectUtil.copyEnvironmentConfigFileIfNotExists(this.workspace); this.logger.info(`Generated ${ProjectUtil.environmentConfigFile} for run-sub projects.`); await GradleUtil.init(this.workspace); const rootGradle = GradleUtil.getRootProjectGradle(this.args.nexus, this.args.quicksilver, this.args.group, this.args.version); fs.writeFileSync(path.join(this.workspace, "build.gradle"), rootGradle); await ProjectUtil.createBuildProjectIfNotExists(this.workspace); } } NewCommand.NAME = "new"; NewCommand.ALIAS = ["n"]; NewCommand.FIELDS = [ { name: "project", description: "The name of the root project.", type: field_1.FieldType.String, defaultIndex: 0, required: true, example: "world" }, { name: "group", description: "The group of the root project.", aliases: ["g", "group"], type: field_1.FieldType.String }, { name: "version", description: "The version of the root project.", aliases: ["v", "version"], type: field_1.FieldType.String }, { name: "port", description: "The run-sub project starts with the port.", aliases: ["p", "port"], type: field_1.FieldType.Number } ]; NewCommand.DESCRIPTION = "Create a root project with a tomcat and a build-sub project."; exports.NewCommand = NewCommand;