✨ 更新cli
- 更改注释 - 去除对api的依赖 - 增加可见性控制 - 更改为初始化时赋值
This commit is contained in:
parent
d1ef50c3c2
commit
c5298edeaf
@ -1,31 +1,31 @@
|
|||||||
import { Command } from "./api";
|
|
||||||
import prompts from "prompts";
|
import prompts from "prompts";
|
||||||
import { file as fs } from "./file";
|
import { file as fs } from "./file";
|
||||||
import ejs from "ejs";
|
import ejs from "ejs";
|
||||||
import { join, resolve, sep } from "path";
|
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;
|
protected answers: {} | null = null;
|
||||||
private dir = join(resolve(__dirname));
|
protected RUN: string; // RUN: 项目初始化目录
|
||||||
protected PATH: string = this.dir.substring(0, this.dir.lastIndexOf("extend"));
|
private dir: string; // dir: 项目运行目录
|
||||||
protected TPL: string = join(this.PATH, "template/");
|
protected PATH: string; // PATH: 项目根目录
|
||||||
|
protected TPL: string; // TPL: 模板目录
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @constructor
|
|
||||||
* @protected
|
|
||||||
*/
|
|
||||||
protected constructor() {
|
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大阶段
|
* @description 自动调用 CLI 过程中的5大阶段
|
||||||
*/
|
*/
|
||||||
async run() {
|
private async run() {
|
||||||
await this.Initialize();
|
await this.Initialize();
|
||||||
await this.Prompting();
|
await this.Prompting();
|
||||||
await this.Writing();
|
await this.Writing();
|
||||||
@ -33,23 +33,22 @@ abstract class Cli implements Command{
|
|||||||
await this.Ending();
|
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) {
|
protected easyCopy(file: string) {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
return fs.copy(join(this.TPL, file), join(this.RUN, this.answers.appName, file));
|
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 };
|
export { Cli };
|
||||||
|
Loading…
Reference in New Issue
Block a user