diff --git a/extend/cli.ts b/extend/cli.ts index 6fd9329..e37e9f7 100644 --- a/extend/cli.ts +++ b/extend/cli.ts @@ -1,31 +1,31 @@ -import { Command } from "./api"; import prompts from "prompts"; import { file as fs } from "./file"; import ejs from "ejs"; import { join, resolve, sep } from "path"; +abstract class Cli { - -abstract class Cli implements Command{ - protected RUN: string = join(resolve(process.cwd()), sep); protected answers: {} | null = null; - private dir = join(resolve(__dirname)); - protected PATH: string = this.dir.substring(0, this.dir.lastIndexOf("extend")); - protected TPL: string = join(this.PATH, "template/"); + protected RUN: string; // RUN: 项目初始化目录 + private dir: string; // dir: 项目运行目录 + protected PATH: string; // PATH: 项目根目录 + protected TPL: string; // TPL: 模板目录 + - /** - * @constructor - * @protected - */ protected constructor() { - this.run().then().catch(err => console.log(err)); + this.RUN = join(resolve(process.cwd()), sep); + let dir = this.dir = join(resolve(__dirname)); + let path = this.PATH = this.dir.substring(0, dir.lastIndexOf("extend")); + this.TPL = join(path, "template/"); + + this.run().catch(err => console.log(err)); } - /** + /* * 自动指令中枢: * @description 自动调用 CLI 过程中的5大阶段 */ - async run() { + private async run() { await this.Initialize(); await this.Prompting(); await this.Writing(); @@ -33,23 +33,22 @@ abstract class Cli implements Command{ await this.Ending(); } - Initialize() { - } + // ---------------------------------------------------------------------- + // 5 大阶段 + protected Initialize() {} - Prompting() { - } + protected Prompting() {} - Writing() { - } + protected Writing() {} - Installing() { - } + protected Installing() {} + + protected Ending() {} + + // 5 大阶段 + // ---------------------------------------------------------------------- - Ending() { - } - // TODO: Copy Files - // PATH: 当前项目绝对路径 protected easyCopy(file: string) { // @ts-ignore return fs.copy(join(this.TPL, file), join(this.RUN, this.answers.appName, file)); @@ -69,4 +68,4 @@ abstract class Cli implements Command{ } -export { Cli }; \ No newline at end of file +export { Cli };