2.0.1
- 降低最低node版本为12 - 增加入口文件 node 启动指令 - 修改ts编译为es5语法 - 修改版本号为2.0.1
This commit is contained in:
parent
d85bcf350a
commit
78536d9d23
@ -49,7 +49,9 @@ docker-compose up -d
|
|||||||
|
|
||||||
|
|
||||||
## 版本简述
|
## 版本简述
|
||||||
### 2.0.0 **`latest`**
|
### 2.0.1 **`latest`**
|
||||||
|
- 修复脚本缺少 node 启动行的问题
|
||||||
|
### 2.0.0
|
||||||
- 修复1.0版本中模板生成阶段缺失文件的问题
|
- 修复1.0版本中模板生成阶段缺失文件的问题
|
||||||
- 重构了结构代码,做了进一步的系统结构调整
|
- 重构了结构代码,做了进一步的系统结构调整
|
||||||
### 1.1.4
|
### 1.1.4
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
|
#! node
|
||||||
"use strict";
|
"use strict";
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
const koa_1 = require("./koa");
|
var koa_1 = require("./koa");
|
||||||
new koa_1.Koa();
|
new koa_1.Koa();
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
#! node
|
||||||
import { Koa } from "./koa";
|
import { Koa } from "./koa";
|
||||||
|
|
||||||
new Koa()
|
new Koa()
|
271
bin/koa.js
271
bin/koa.js
@ -1,4 +1,17 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
var __extends = (this && this.__extends) || (function () {
|
||||||
|
var extendStatics = function (d, b) {
|
||||||
|
extendStatics = Object.setPrototypeOf ||
|
||||||
|
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
||||||
|
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
||||||
|
return extendStatics(d, b);
|
||||||
|
};
|
||||||
|
return function (d, b) {
|
||||||
|
extendStatics(d, b);
|
||||||
|
function __() { this.constructor = d; }
|
||||||
|
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
||||||
|
};
|
||||||
|
})();
|
||||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||||
if (k2 === undefined) k2 = k;
|
if (k2 === undefined) k2 = k;
|
||||||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
||||||
@ -27,120 +40,182 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|||||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
var __generator = (this && this.__generator) || function (thisArg, body) {
|
||||||
|
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
||||||
|
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
||||||
|
function verb(n) { return function (v) { return step([n, v]); }; }
|
||||||
|
function step(op) {
|
||||||
|
if (f) throw new TypeError("Generator is already executing.");
|
||||||
|
while (_) try {
|
||||||
|
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
||||||
|
if (y = 0, t) op = [op[0] & 2, t.value];
|
||||||
|
switch (op[0]) {
|
||||||
|
case 0: case 1: t = op; break;
|
||||||
|
case 4: _.label++; return { value: op[1], done: false };
|
||||||
|
case 5: _.label++; y = op[1]; op = [0]; continue;
|
||||||
|
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
||||||
|
default:
|
||||||
|
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
||||||
|
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
||||||
|
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
||||||
|
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
||||||
|
if (t[2]) _.ops.pop();
|
||||||
|
_.trys.pop(); continue;
|
||||||
|
}
|
||||||
|
op = body.call(thisArg, _);
|
||||||
|
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
||||||
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
||||||
|
}
|
||||||
|
};
|
||||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||||
};
|
};
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
exports.Koa = void 0;
|
exports.Koa = void 0;
|
||||||
const cli_1 = require("../extend/cli");
|
var cli_1 = require("../extend/cli");
|
||||||
const os = __importStar(require("os"));
|
var os = __importStar(require("os"));
|
||||||
const console_1 = require("../extend/console");
|
var console_1 = require("../extend/console");
|
||||||
const child_process_1 = require("child_process");
|
var child_process_1 = require("child_process");
|
||||||
const ora_1 = __importDefault(require("ora"));
|
var ora_1 = __importDefault(require("ora"));
|
||||||
const path_1 = require("path");
|
var path_1 = require("path");
|
||||||
// Koa 命令行
|
// Koa 命令行
|
||||||
class Koa extends cli_1.Cli {
|
var Koa = /** @class */ (function (_super) {
|
||||||
constructor() {
|
__extends(Koa, _super);
|
||||||
super();
|
function Koa() {
|
||||||
this.command = ``;
|
var _this = _super.call(this) || this;
|
||||||
|
_this.command = "";
|
||||||
|
return _this;
|
||||||
}
|
}
|
||||||
// 初始化
|
// 初始化
|
||||||
Initialize() {
|
Koa.prototype.Initialize = function () {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function () {
|
||||||
console.log(console_1.info(`\n\r---------------- 🎨 KOA CLI ----------------`));
|
return __generator(this, function (_a) {
|
||||||
|
console.log(console_1.info("\n\r---------------- \uD83C\uDFA8 KOA CLI ----------------"));
|
||||||
|
return [2 /*return*/];
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
// 交互阶段
|
// 交互阶段
|
||||||
Prompting() {
|
Koa.prototype.Prompting = function () {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function () {
|
||||||
yield this.prompt([
|
return __generator(this, function (_a) {
|
||||||
{
|
switch (_a.label) {
|
||||||
name: "appName",
|
case 0: return [4 /*yield*/, this.prompt([
|
||||||
message: console_1.readonly("🎉App Name:"),
|
{
|
||||||
type: "text",
|
name: "appName",
|
||||||
validate: (values) => values.length <= 0 ? `Input your project name, Please !` : true,
|
message: console_1.readonly("🎉App Name:"),
|
||||||
},
|
type: "text",
|
||||||
{
|
validate: function (values) { return values.length <= 0 ? "Input your project name, Please !" : true; },
|
||||||
name: "pkgManager",
|
},
|
||||||
message: console_1.readonly("🎰Package Manager:"),
|
{
|
||||||
type: "toggle",
|
name: "pkgManager",
|
||||||
active: "Yarn",
|
message: console_1.readonly("🎰Package Manager:"),
|
||||||
inactive: "Npm",
|
type: "toggle",
|
||||||
initial: "Yarn",
|
active: "Yarn",
|
||||||
},
|
inactive: "Npm",
|
||||||
{
|
initial: "Yarn",
|
||||||
name: "author",
|
},
|
||||||
message: console_1.readonly("🥤Author Name:"),
|
{
|
||||||
type: "text",
|
name: "author",
|
||||||
initial: os.userInfo().username,
|
message: console_1.readonly("🥤Author Name:"),
|
||||||
},
|
type: "text",
|
||||||
]);
|
initial: os.userInfo().username,
|
||||||
|
},
|
||||||
|
])];
|
||||||
|
case 1:
|
||||||
|
_a.sent();
|
||||||
|
return [2 /*return*/];
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
// 项目初始化
|
// 项目初始化
|
||||||
Writing() {
|
Koa.prototype.Writing = function () {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function () {
|
||||||
console.log(console_1.info(`---------------- 🧩 WRITING ----------------`));
|
var files;
|
||||||
const files = {
|
var _this = this;
|
||||||
static: [
|
return __generator(this, function (_a) {
|
||||||
`controller/index.ts`,
|
console.log(console_1.info("---------------- \uD83E\uDDE9 WRITING ----------------"));
|
||||||
`extend/logger.ts`,
|
files = {
|
||||||
`extend/lucky.ts`,
|
static: [
|
||||||
`route/route.ts`,
|
"controller/index.ts",
|
||||||
`view/index.njk`,
|
"extend/logger.ts",
|
||||||
`tsconfig.json`,
|
"extend/lucky.ts",
|
||||||
`Dockerfile`,
|
"route/route.ts",
|
||||||
`app.ts`,
|
"view/index.njk",
|
||||||
],
|
"tsconfig.json",
|
||||||
tpl: [
|
"Dockerfile",
|
||||||
`docker-compose.yml`,
|
"app.ts",
|
||||||
`package.json`,
|
],
|
||||||
`LICENSE`,
|
tpl: [
|
||||||
],
|
"docker-compose.yml",
|
||||||
};
|
"package.json",
|
||||||
files.static.forEach(file => {
|
"LICENSE",
|
||||||
let notice = this.easyCopy(file);
|
],
|
||||||
if (notice)
|
};
|
||||||
console.log(console_1.success("+"), console_1.readonly(path_1.join(file)));
|
files.static.forEach(function (file) {
|
||||||
else
|
var notice = _this.easyCopy(file);
|
||||||
console.log(console_1.error("x"), console_1.error(path_1.join(file)));
|
if (notice)
|
||||||
});
|
console.log(console_1.success("+"), console_1.readonly(path_1.join(file)));
|
||||||
files.tpl.forEach(file => {
|
else
|
||||||
let notice = this.easyTpl(file);
|
console.log(console_1.error("x"), console_1.error(path_1.join(file)));
|
||||||
if (notice)
|
});
|
||||||
console.log(console_1.success("+"), console_1.readonly(path_1.join(file)));
|
files.tpl.forEach(function (file) {
|
||||||
else
|
var notice = _this.easyTpl(file);
|
||||||
console.log(console_1.error("x"), console_1.error(path_1.join(file)));
|
if (notice)
|
||||||
|
console.log(console_1.success("+"), console_1.readonly(path_1.join(file)));
|
||||||
|
else
|
||||||
|
console.log(console_1.error("x"), console_1.error(path_1.join(file)));
|
||||||
|
});
|
||||||
|
return [2 /*return*/];
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
// 依赖安装
|
// 依赖安装
|
||||||
Installing() {
|
Koa.prototype.Installing = function () {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function () {
|
||||||
console.log(console_1.info(`---------------- 🎰 INSTALL ----------------`));
|
return __generator(this, function (_a) {
|
||||||
if (this.answers.pkgManager) {
|
switch (_a.label) {
|
||||||
this.command += `cd ${this.answers.appName} && yarn install`;
|
case 0:
|
||||||
}
|
console.log(console_1.info("---------------- \uD83C\uDFB0 INSTALL ----------------"));
|
||||||
else {
|
if (this.answers.pkgManager) {
|
||||||
this.command += `cd ${this.answers.appName} && npm install`;
|
this.command += "cd " + this.answers.appName + " && yarn install";
|
||||||
}
|
}
|
||||||
yield this.easyInstall();
|
else {
|
||||||
});
|
this.command += "cd " + this.answers.appName + " && npm install";
|
||||||
}
|
}
|
||||||
// 安装
|
return [4 /*yield*/, this.easyInstall()];
|
||||||
easyInstall() {
|
case 1:
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
_a.sent();
|
||||||
let oraObj = ora_1.default();
|
return [2 /*return*/];
|
||||||
oraObj.start(console_1.readonly("Install..."));
|
|
||||||
yield child_process_1.exec(this.command, (res, stdout, stderr) => {
|
|
||||||
if (res == null) {
|
|
||||||
return oraObj.succeed(console_1.success("依赖安装完成...")).stop();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return oraObj.fail(console_1.error("依赖安装失败,请手动安装")).stop();
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
}
|
// 安装
|
||||||
|
Koa.prototype.easyInstall = function () {
|
||||||
|
return __awaiter(this, void 0, void 0, function () {
|
||||||
|
var oraObj;
|
||||||
|
return __generator(this, function (_a) {
|
||||||
|
switch (_a.label) {
|
||||||
|
case 0:
|
||||||
|
oraObj = ora_1.default();
|
||||||
|
oraObj.start(console_1.readonly("Install..."));
|
||||||
|
return [4 /*yield*/, child_process_1.exec(this.command, function (res, stdout, stderr) {
|
||||||
|
if (res == null) {
|
||||||
|
return oraObj.succeed(console_1.success("依赖安装完成...")).stop();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return oraObj.fail(console_1.error("依赖安装失败,请手动安装")).stop();
|
||||||
|
}
|
||||||
|
})];
|
||||||
|
case 1:
|
||||||
|
_a.sent();
|
||||||
|
return [2 /*return*/];
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
return Koa;
|
||||||
|
}(cli_1.Cli));
|
||||||
exports.Koa = Koa;
|
exports.Koa = Koa;
|
||||||
|
135
extend/cli.js
135
extend/cli.js
@ -8,70 +8,127 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|||||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
var __generator = (this && this.__generator) || function (thisArg, body) {
|
||||||
|
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
||||||
|
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
||||||
|
function verb(n) { return function (v) { return step([n, v]); }; }
|
||||||
|
function step(op) {
|
||||||
|
if (f) throw new TypeError("Generator is already executing.");
|
||||||
|
while (_) try {
|
||||||
|
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
||||||
|
if (y = 0, t) op = [op[0] & 2, t.value];
|
||||||
|
switch (op[0]) {
|
||||||
|
case 0: case 1: t = op; break;
|
||||||
|
case 4: _.label++; return { value: op[1], done: false };
|
||||||
|
case 5: _.label++; y = op[1]; op = [0]; continue;
|
||||||
|
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
||||||
|
default:
|
||||||
|
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
||||||
|
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
||||||
|
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
||||||
|
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
||||||
|
if (t[2]) _.ops.pop();
|
||||||
|
_.trys.pop(); continue;
|
||||||
|
}
|
||||||
|
op = body.call(thisArg, _);
|
||||||
|
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
||||||
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
||||||
|
}
|
||||||
|
};
|
||||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||||
};
|
};
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
exports.Cli = void 0;
|
exports.Cli = void 0;
|
||||||
const prompts_1 = __importDefault(require("prompts"));
|
var prompts_1 = __importDefault(require("prompts"));
|
||||||
const file_1 = require("./file");
|
var file_1 = require("./file");
|
||||||
const ejs_1 = __importDefault(require("ejs"));
|
var ejs_1 = __importDefault(require("ejs"));
|
||||||
const path_1 = require("path");
|
var path_1 = require("path");
|
||||||
class Cli {
|
var Cli = /** @class */ (function () {
|
||||||
/**
|
/**
|
||||||
* @constructor
|
* @constructor
|
||||||
* @protected
|
* @protected
|
||||||
*/
|
*/
|
||||||
constructor() {
|
function Cli() {
|
||||||
this.RUN = path_1.join(path_1.resolve(process.cwd()), path_1.sep);
|
this.RUN = path_1.join(path_1.resolve(process.cwd()), path_1.sep);
|
||||||
this.answers = null;
|
this.answers = null;
|
||||||
this.dir = path_1.join(path_1.resolve(__dirname));
|
this.dir = path_1.join(path_1.resolve(__dirname));
|
||||||
this.PATH = this.dir.substring(0, this.dir.lastIndexOf("extend"));
|
this.PATH = this.dir.substring(0, this.dir.lastIndexOf("extend"));
|
||||||
this.TPL = path_1.join(this.PATH, "template/");
|
this.TPL = path_1.join(this.PATH, "template/");
|
||||||
this.run().then().catch(err => console.log(err));
|
this.run().then().catch(function (err) { return console.log(err); });
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* 自动指令中枢:
|
* 自动指令中枢:
|
||||||
* @description 自动调用 CLI 过程中的5大阶段
|
* @description 自动调用 CLI 过程中的5大阶段
|
||||||
*/
|
*/
|
||||||
run() {
|
Cli.prototype.run = function () {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function () {
|
||||||
yield this.Initialize();
|
return __generator(this, function (_a) {
|
||||||
yield this.Prompting();
|
switch (_a.label) {
|
||||||
yield this.Writing();
|
case 0: return [4 /*yield*/, this.Initialize()];
|
||||||
yield this.Installing();
|
case 1:
|
||||||
yield this.Ending();
|
_a.sent();
|
||||||
|
return [4 /*yield*/, this.Prompting()];
|
||||||
|
case 2:
|
||||||
|
_a.sent();
|
||||||
|
return [4 /*yield*/, this.Writing()];
|
||||||
|
case 3:
|
||||||
|
_a.sent();
|
||||||
|
return [4 /*yield*/, this.Installing()];
|
||||||
|
case 4:
|
||||||
|
_a.sent();
|
||||||
|
return [4 /*yield*/, this.Ending()];
|
||||||
|
case 5:
|
||||||
|
_a.sent();
|
||||||
|
return [2 /*return*/];
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
Initialize() {
|
Cli.prototype.Initialize = function () {
|
||||||
}
|
};
|
||||||
Prompting() {
|
Cli.prototype.Prompting = function () {
|
||||||
}
|
};
|
||||||
Writing() {
|
Cli.prototype.Writing = function () {
|
||||||
}
|
};
|
||||||
Installing() {
|
Cli.prototype.Installing = function () {
|
||||||
}
|
};
|
||||||
Ending() {
|
Cli.prototype.Ending = function () {
|
||||||
}
|
};
|
||||||
// TODO: Copy Files
|
// TODO: Copy Files
|
||||||
// PATH: 当前项目绝对路径
|
// PATH: 当前项目绝对路径
|
||||||
easyCopy(file) {
|
Cli.prototype.easyCopy = function (file) {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
return file_1.file.copy(path_1.join(this.TPL, file), path_1.join(this.RUN, this.answers.appName, file));
|
return file_1.file.copy(path_1.join(this.TPL, file), path_1.join(this.RUN, this.answers.appName, file));
|
||||||
}
|
};
|
||||||
easyTpl(file) {
|
Cli.prototype.easyTpl = function (file) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function () {
|
||||||
// @ts-ignore
|
var compileContent;
|
||||||
const [compileContent] = yield Promise.all([ejs_1.default.renderFile(path_1.join(this.TPL, file), this.answers)]);
|
return __generator(this, function (_a) {
|
||||||
// @ts-ignore
|
switch (_a.label) {
|
||||||
return file_1.file.write(path_1.join(this.RUN, this.answers.appName, file), compileContent);
|
case 0: return [4 /*yield*/, Promise.all([ejs_1.default.renderFile(path_1.join(this.TPL, file), this.answers)])];
|
||||||
|
case 1:
|
||||||
|
compileContent = (_a.sent())[0];
|
||||||
|
// @ts-ignore
|
||||||
|
return [2 /*return*/, file_1.file.write(path_1.join(this.RUN, this.answers.appName, file), compileContent)];
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
// 提问题,并传回问题答案
|
// 提问题,并传回问题答案
|
||||||
prompt(question) {
|
Cli.prototype.prompt = function (question) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function () {
|
||||||
return this.answers = yield prompts_1.default(question);
|
var _a;
|
||||||
|
return __generator(this, function (_b) {
|
||||||
|
switch (_b.label) {
|
||||||
|
case 0:
|
||||||
|
_a = this;
|
||||||
|
return [4 /*yield*/, prompts_1.default(question)];
|
||||||
|
case 1: return [2 /*return*/, _a.answers = _b.sent()];
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
}
|
return Cli;
|
||||||
|
}());
|
||||||
exports.Cli = Cli;
|
exports.Cli = Cli;
|
||||||
|
@ -4,7 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|||||||
};
|
};
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
exports.readonly = exports.success = exports.error = exports.warning = exports.info = exports.log = void 0;
|
exports.readonly = exports.success = exports.error = exports.warning = exports.info = exports.log = void 0;
|
||||||
const chalk_1 = __importDefault(require("chalk"));
|
var chalk_1 = __importDefault(require("chalk"));
|
||||||
function log(information) {
|
function log(information) {
|
||||||
return chalk_1.default.white(information);
|
return chalk_1.default.white(information);
|
||||||
}
|
}
|
||||||
|
@ -1,13 +1,15 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
exports.file = void 0;
|
exports.file = void 0;
|
||||||
const fs_1 = require("fs");
|
var fs_1 = require("fs");
|
||||||
const path_1 = require("path");
|
var path_1 = require("path");
|
||||||
/**
|
/**
|
||||||
* 文件操作类
|
* 文件操作类
|
||||||
* @description 更加语义化的简便文件操作。
|
* @description 更加语义化的简便文件操作。
|
||||||
*/
|
*/
|
||||||
class file {
|
var file = /** @class */ (function () {
|
||||||
|
function file() {
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* 创建目录
|
* 创建目录
|
||||||
* @description 如果目录不存在,则自动创建目录,并返回结果
|
* @description 如果目录不存在,则自动创建目录,并返回结果
|
||||||
@ -16,26 +18,26 @@ class file {
|
|||||||
* @param {string} filePath 要操作(复制,剪切)的目录名(带文件名和后缀的完整目录)
|
* @param {string} filePath 要操作(复制,剪切)的目录名(带文件名和后缀的完整目录)
|
||||||
* @return {boolean} 操作状态
|
* @return {boolean} 操作状态
|
||||||
*/
|
*/
|
||||||
static createPath(filePath) {
|
file.createPath = function (filePath) {
|
||||||
// 获取完整目录(去除最后一位的文件字段)
|
// 获取完整目录(去除最后一位的文件字段)
|
||||||
let dir = filePath.substring(0, filePath.lastIndexOf(path_1.sep));
|
var dir = filePath.substring(0, filePath.lastIndexOf(path_1.sep));
|
||||||
if (dir == "" || dir == null)
|
if (dir == "" || dir == null)
|
||||||
dir = `.${path_1.sep}`; // 不写目录名 => 根目录
|
dir = "." + path_1.sep; // 不写目录名 => 根目录
|
||||||
// 文件夹不存在
|
// 文件夹不存在
|
||||||
if (!fs_1.existsSync(dir)) {
|
if (!fs_1.existsSync(dir)) {
|
||||||
let actionNotice = fs_1.mkdirSync(dir, { recursive: true });
|
var actionNotice = fs_1.mkdirSync(dir, { recursive: true });
|
||||||
return !!actionNotice;
|
return !!actionNotice;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
return true;
|
return true;
|
||||||
}
|
};
|
||||||
/**
|
/**
|
||||||
* 复制文件
|
* 复制文件
|
||||||
* @param {string} src 源文件地址
|
* @param {string} src 源文件地址
|
||||||
* @param {string} dest 文件去向地址
|
* @param {string} dest 文件去向地址
|
||||||
* @return {boolean} 操作状态
|
* @return {boolean} 操作状态
|
||||||
*/
|
*/
|
||||||
static copy(src, dest) {
|
file.copy = function (src, dest) {
|
||||||
if (!fs_1.existsSync(src)) {
|
if (!fs_1.existsSync(src)) {
|
||||||
// console.log("源文件不存在");
|
// console.log("源文件不存在");
|
||||||
return false;
|
return false;
|
||||||
@ -47,20 +49,22 @@ class file {
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
return false;
|
return false;
|
||||||
}
|
};
|
||||||
/***
|
/***
|
||||||
* 文件写入(保存文件)
|
* 文件写入(保存文件)
|
||||||
* @param {string} filePath 文件去向地址
|
* @param {string} filePath 文件去向地址
|
||||||
* @param data 写入数据
|
* @param data 写入数据
|
||||||
* @return {boolean} 操作状态
|
* @return {boolean} 操作状态
|
||||||
*/
|
*/
|
||||||
static write(filePath, data = "") {
|
file.write = function (filePath, data) {
|
||||||
|
if (data === void 0) { data = ""; }
|
||||||
if (file.createPath(filePath)) {
|
if (file.createPath(filePath)) {
|
||||||
fs_1.writeFileSync(filePath, data);
|
fs_1.writeFileSync(filePath, data);
|
||||||
return fs_1.existsSync(filePath);
|
return fs_1.existsSync(filePath);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
return false;
|
return false;
|
||||||
}
|
};
|
||||||
}
|
return file;
|
||||||
|
}());
|
||||||
exports.file = file;
|
exports.file = file;
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
{
|
{
|
||||||
"name": "koa-program",
|
"name": "koa-program",
|
||||||
"version": "2.0.0",
|
"version": "2.0.1",
|
||||||
"bin": {
|
"bin": {
|
||||||
"koa": "bin/index.js"
|
"koa": "bin/index.js"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">= 15"
|
"node": ">= 12"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"chalk": "^4.1.0",
|
"chalk": "^4.1.0",
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
/* Basic Options */
|
/* Basic Options */
|
||||||
// "incremental": true, /* Enable incremental compilation */
|
// "incremental": true, /* Enable incremental compilation */
|
||||||
"target": "ES6", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */
|
"target": "ES5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */
|
||||||
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */
|
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */
|
||||||
// "lib": [], /* Specify library files to be included in the compilation. */
|
// "lib": [], /* Specify library files to be included in the compilation. */
|
||||||
// "allowJs": true, /* Allow javascript files to be compiled. */
|
// "allowJs": true, /* Allow javascript files to be compiled. */
|
||||||
|
Loading…
Reference in New Issue
Block a user