2021-02-17 01:49:07 +08:00
|
|
|
|
"use strict";
|
|
|
|
|
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());
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
|
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
|
|
|
};
|
|
|
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
|
|
exports.Cli = void 0;
|
2021-02-25 18:10:50 +08:00
|
|
|
|
const prompts_1 = __importDefault(require("prompts"));
|
|
|
|
|
const file_1 = require("./file");
|
|
|
|
|
const ejs_1 = __importDefault(require("ejs"));
|
|
|
|
|
const path_1 = require("path");
|
|
|
|
|
class Cli {
|
2021-02-17 01:49:07 +08:00
|
|
|
|
/**
|
|
|
|
|
* @constructor
|
|
|
|
|
* @protected
|
|
|
|
|
*/
|
2021-02-25 18:10:50 +08:00
|
|
|
|
constructor() {
|
2021-02-17 01:49:07 +08:00
|
|
|
|
this.RUN = path_1.join(path_1.resolve(process.cwd()), path_1.sep);
|
|
|
|
|
this.answers = null;
|
|
|
|
|
this.dir = path_1.join(path_1.resolve(__dirname));
|
|
|
|
|
this.PATH = this.dir.substring(0, this.dir.lastIndexOf("extend"));
|
|
|
|
|
this.TPL = path_1.join(this.PATH, "template/");
|
2021-02-25 18:10:50 +08:00
|
|
|
|
this.run().then().catch(err => console.log(err));
|
2021-02-17 01:49:07 +08:00
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* 自动指令中枢:
|
|
|
|
|
* @description 自动调用 CLI 过程中的5大阶段
|
|
|
|
|
*/
|
2021-02-25 18:10:50 +08:00
|
|
|
|
run() {
|
|
|
|
|
return __awaiter(this, void 0, void 0, function* () {
|
|
|
|
|
yield this.Initialize();
|
|
|
|
|
yield this.Prompting();
|
|
|
|
|
yield this.Writing();
|
|
|
|
|
yield this.Installing();
|
|
|
|
|
yield this.Ending();
|
2021-02-17 01:49:07 +08:00
|
|
|
|
});
|
2021-02-25 18:10:50 +08:00
|
|
|
|
}
|
|
|
|
|
Initialize() {
|
|
|
|
|
}
|
|
|
|
|
Prompting() {
|
|
|
|
|
}
|
|
|
|
|
Writing() {
|
|
|
|
|
}
|
|
|
|
|
Installing() {
|
|
|
|
|
}
|
|
|
|
|
Ending() {
|
|
|
|
|
}
|
2021-02-17 01:49:07 +08:00
|
|
|
|
// TODO: Copy Files
|
|
|
|
|
// PATH: 当前项目绝对路径
|
2021-02-25 18:10:50 +08:00
|
|
|
|
easyCopy(file) {
|
2021-02-17 01:49:07 +08:00
|
|
|
|
// @ts-ignore
|
|
|
|
|
return file_1.file.copy(path_1.join(this.TPL, file), path_1.join(this.RUN, this.answers.appName, file));
|
2021-02-25 18:10:50 +08:00
|
|
|
|
}
|
|
|
|
|
easyTpl(file) {
|
|
|
|
|
return __awaiter(this, void 0, void 0, function* () {
|
|
|
|
|
// @ts-ignore
|
|
|
|
|
const [compileContent] = yield Promise.all([ejs_1.default.renderFile(path_1.join(this.TPL, file), this.answers)]);
|
|
|
|
|
// @ts-ignore
|
|
|
|
|
return file_1.file.write(path_1.join(this.RUN, this.answers.appName, file), compileContent);
|
2021-02-17 01:49:07 +08:00
|
|
|
|
});
|
2021-02-25 18:10:50 +08:00
|
|
|
|
}
|
2021-02-17 01:49:07 +08:00
|
|
|
|
// 提问题,并传回问题答案
|
2021-02-25 18:10:50 +08:00
|
|
|
|
prompt(question) {
|
|
|
|
|
return __awaiter(this, void 0, void 0, function* () {
|
|
|
|
|
return this.answers = yield prompts_1.default(question);
|
2021-02-17 01:49:07 +08:00
|
|
|
|
});
|
2021-02-25 18:10:50 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2021-02-17 01:49:07 +08:00
|
|
|
|
exports.Cli = Cli;
|