From c5298edeaf546991d767cd63998f5e66bd24f2c3 Mon Sep 17 00:00:00 2001 From: Titor Date: Wed, 3 Mar 2021 14:28:19 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20=E6=9B=B4=E6=96=B0cli?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 更改注释 - 去除对api的依赖 - 增加可见性控制 - 更改为初始化时赋值 --- extend/cli.ts | 53 +++++++++++++++++++++++++-------------------------- 1 file changed, 26 insertions(+), 27 deletions(-) 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 };