coda-cli 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +9 -0
- package/README.md +76 -0
- package/package.json +45 -0
- package/src/bin/index.js +4 -0
- package/src/bin/index.ts +2 -0
- package/src/cli-api/cmd.js +86 -0
- package/src/cli-api/cmd.ts +104 -0
- package/src/cli-api/data.js +135 -0
- package/src/cli-api/data.ts +146 -0
- package/src/cli-api/date.js +23 -0
- package/src/cli-api/date.ts +22 -0
- package/src/cli-api/event.js +6 -0
- package/src/cli-api/event.ts +6 -0
- package/src/cli-api/fs.js +236 -0
- package/src/cli-api/fs.ts +213 -0
- package/src/cli-api/git.js +328 -0
- package/src/cli-api/git.ts +397 -0
- package/src/cli-api/index.js +22 -0
- package/src/cli-api/index.ts +10 -0
- package/src/cli-api/packages.js +69 -0
- package/src/cli-api/packages.ts +73 -0
- package/src/cli-api/request.js +55 -0
- package/src/cli-api/request.ts +67 -0
- package/src/cli-core/cli.js +135 -0
- package/src/cli-core/cli.ts +145 -0
- package/src/cli-core/index.js +51 -0
- package/src/cli-core/index.ts +58 -0
- package/src/cli-core/queue.js +60 -0
- package/src/cli-core/queue.ts +68 -0
- package/src/cli-core/watcher.js +31 -0
- package/src/cli-core/watcher.ts +31 -0
- package/src/config/commands.json +20 -0
- package/src/generator/cmd-create/index.js +170 -0
- package/src/generator/cmd-create/index.ts +164 -0
- package/src/generator/cmd-create/tmpl/index.js +39 -0
- package/src/generator/cmd-create/tmpl/index.ts +46 -0
- package/src/generator/cmd-delete/index.js +129 -0
- package/src/generator/cmd-delete/index.ts +122 -0
- package/src/generator/startup.js +253 -0
- package/src/generator/startup.ts +225 -0
- package/src/service/lang.js +73 -0
- package/src/service/lang.ts +71 -0
- package/src/service/util.js +120 -0
- package/src/service/util.ts +91 -0
- package/src/types/index.js +2 -0
- package/src/types/index.ts +29 -0
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.event = exports.request = exports.packages = exports.git = exports.fs = exports.date = exports.data = exports.childProcess = void 0;
|
|
7
|
+
const cmd_1 = require("./cmd");
|
|
8
|
+
Object.defineProperty(exports, "childProcess", { enumerable: true, get: function () { return cmd_1.childProcess; } });
|
|
9
|
+
const data_1 = __importDefault(require("./data"));
|
|
10
|
+
exports.data = data_1.default;
|
|
11
|
+
const date_1 = __importDefault(require("./date"));
|
|
12
|
+
exports.date = date_1.default;
|
|
13
|
+
const fs_1 = __importDefault(require("./fs"));
|
|
14
|
+
exports.fs = fs_1.default;
|
|
15
|
+
const git_1 = __importDefault(require("./git"));
|
|
16
|
+
exports.git = git_1.default;
|
|
17
|
+
const packages_1 = __importDefault(require("./packages"));
|
|
18
|
+
exports.packages = packages_1.default;
|
|
19
|
+
const request_1 = __importDefault(require("./request"));
|
|
20
|
+
exports.request = request_1.default;
|
|
21
|
+
const event_1 = __importDefault(require("./event"));
|
|
22
|
+
exports.event = event_1.default;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import {childProcess} from './cmd';
|
|
2
|
+
import data from './data';
|
|
3
|
+
import date from './date';
|
|
4
|
+
import fs from './fs';
|
|
5
|
+
import git from './git';
|
|
6
|
+
import packages from './packages';
|
|
7
|
+
import request from './request';
|
|
8
|
+
import event from './event';
|
|
9
|
+
|
|
10
|
+
export {childProcess, data, date, fs, git, packages, request, event};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.Packages = void 0;
|
|
7
|
+
const npm_check_updates_1 = __importDefault(require("npm-check-updates"));
|
|
8
|
+
const semver_1 = __importDefault(require("semver"));
|
|
9
|
+
const request_1 = __importDefault(require("./request"));
|
|
10
|
+
exports.Packages = {
|
|
11
|
+
/**
|
|
12
|
+
* 更新 npm 包
|
|
13
|
+
* @param path package.json 文件路径
|
|
14
|
+
* @param reject 排除不需要更新的包(支持字符串或字符串数组)
|
|
15
|
+
* @returns 返回更新后的依赖配置对象
|
|
16
|
+
*/
|
|
17
|
+
async update(path, reject) {
|
|
18
|
+
const upgraded = await (0, npm_check_updates_1.default)({
|
|
19
|
+
packageFile: path,
|
|
20
|
+
upgrade: true,
|
|
21
|
+
install: 'always',
|
|
22
|
+
reject: reject,
|
|
23
|
+
});
|
|
24
|
+
return upgraded;
|
|
25
|
+
},
|
|
26
|
+
/**
|
|
27
|
+
* 检查 CLI 版本
|
|
28
|
+
* @param url CLI 发布的仓库/地址
|
|
29
|
+
* @param localVersion 安装在 npm 全局目录下的本地 CLI 版本
|
|
30
|
+
* @returns 若有新版本则返回包含名称和新版本号的对象,否则返回空对象
|
|
31
|
+
*/
|
|
32
|
+
async checkVersion(url, localVersion) {
|
|
33
|
+
let response = await request_1.default.ajax(url, 'get');
|
|
34
|
+
if (response.status === 'success') {
|
|
35
|
+
let remoteVersion = response.data['version']
|
|
36
|
+
? response.data['version']
|
|
37
|
+
: response.data['dist-tags']['latest'];
|
|
38
|
+
let res = semver_1.default.lt(localVersion, remoteVersion);
|
|
39
|
+
if (res) {
|
|
40
|
+
return {
|
|
41
|
+
name: response.data.name,
|
|
42
|
+
version: remoteVersion,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
return {};
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
return {};
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
/**
|
|
54
|
+
* 查询 npm 包的最新版本
|
|
55
|
+
* @param url npm 仓库地址
|
|
56
|
+
* @param defaultVersion 网络错误时使用的默认版本号
|
|
57
|
+
* @returns 返回版本号字符串
|
|
58
|
+
*/
|
|
59
|
+
async getLatestVersion(url, defaultVersion) {
|
|
60
|
+
let data = await request_1.default.ajax(url, 'get');
|
|
61
|
+
if (data.status === 'success') {
|
|
62
|
+
return data.data['version'];
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
return defaultVersion;
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
};
|
|
69
|
+
exports.default = exports.Packages;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import ncu from 'npm-check-updates';
|
|
2
|
+
import semver from 'semver';
|
|
3
|
+
import Request from './request';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* 版本检查结果接口
|
|
7
|
+
*/
|
|
8
|
+
export interface VersionInfo {
|
|
9
|
+
name?: string;
|
|
10
|
+
version?: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export const Packages = {
|
|
14
|
+
/**
|
|
15
|
+
* 更新 npm 包
|
|
16
|
+
* @param path package.json 文件路径
|
|
17
|
+
* @param reject 排除不需要更新的包(支持字符串或字符串数组)
|
|
18
|
+
* @returns 返回更新后的依赖配置对象
|
|
19
|
+
*/
|
|
20
|
+
async update(path: string, reject?: string | string[]): Promise<any> {
|
|
21
|
+
const upgraded = await ncu({
|
|
22
|
+
packageFile: path,
|
|
23
|
+
upgrade: true,
|
|
24
|
+
install: 'always',
|
|
25
|
+
reject: reject,
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
return upgraded;
|
|
29
|
+
},
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* 检查 CLI 版本
|
|
33
|
+
* @param url CLI 发布的仓库/地址
|
|
34
|
+
* @param localVersion 安装在 npm 全局目录下的本地 CLI 版本
|
|
35
|
+
* @returns 若有新版本则返回包含名称和新版本号的对象,否则返回空对象
|
|
36
|
+
*/
|
|
37
|
+
async checkVersion(url: string, localVersion: string): Promise<VersionInfo> {
|
|
38
|
+
let response = await Request.ajax(url, 'get');
|
|
39
|
+
if (response.status === 'success') {
|
|
40
|
+
let remoteVersion = response.data['version']
|
|
41
|
+
? response.data['version']
|
|
42
|
+
: response.data['dist-tags']['latest'];
|
|
43
|
+
let res = semver.lt(localVersion, remoteVersion);
|
|
44
|
+
if (res) {
|
|
45
|
+
return {
|
|
46
|
+
name: response.data.name,
|
|
47
|
+
version: remoteVersion,
|
|
48
|
+
};
|
|
49
|
+
} else {
|
|
50
|
+
return {};
|
|
51
|
+
}
|
|
52
|
+
} else {
|
|
53
|
+
return {};
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* 查询 npm 包的最新版本
|
|
59
|
+
* @param url npm 仓库地址
|
|
60
|
+
* @param defaultVersion 网络错误时使用的默认版本号
|
|
61
|
+
* @returns 返回版本号字符串
|
|
62
|
+
*/
|
|
63
|
+
async getLatestVersion(url: string, defaultVersion: string): Promise<string> {
|
|
64
|
+
let data = await Request.ajax(url, 'get');
|
|
65
|
+
if (data.status === 'success') {
|
|
66
|
+
return data.data['version'];
|
|
67
|
+
} else {
|
|
68
|
+
return defaultVersion;
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
export default Packages;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.Request = void 0;
|
|
7
|
+
const axios_1 = __importDefault(require("axios"));
|
|
8
|
+
exports.Request = {
|
|
9
|
+
/**
|
|
10
|
+
* HTTP 请求方法
|
|
11
|
+
* @param url 请求链接
|
|
12
|
+
* @param method HTTP 请求方法 (如 GET, POST 等)
|
|
13
|
+
* @param params 请求参数
|
|
14
|
+
* @param headers 请求头
|
|
15
|
+
* @param timeout 超时时间(毫秒)
|
|
16
|
+
* @returns 返回包含状态和数据的 Promise 对象
|
|
17
|
+
*/
|
|
18
|
+
ajax(url, method, params, headers, timeout) {
|
|
19
|
+
const config = {
|
|
20
|
+
url: url,
|
|
21
|
+
method: method,
|
|
22
|
+
};
|
|
23
|
+
if (params) {
|
|
24
|
+
config.data = params;
|
|
25
|
+
}
|
|
26
|
+
if (headers) {
|
|
27
|
+
config.headers = headers;
|
|
28
|
+
}
|
|
29
|
+
axios_1.default.defaults.timeout = timeout ? timeout : 10000;
|
|
30
|
+
return new Promise(resolve => {
|
|
31
|
+
(0, axios_1.default)(config)
|
|
32
|
+
.then(response => {
|
|
33
|
+
if (response.status === 200) {
|
|
34
|
+
resolve({
|
|
35
|
+
status: 'success',
|
|
36
|
+
data: response.data,
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
resolve({
|
|
41
|
+
status: 'error',
|
|
42
|
+
data: response.data?.message || '未知错误',
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
})
|
|
46
|
+
.catch(error => {
|
|
47
|
+
resolve({
|
|
48
|
+
status: 'error',
|
|
49
|
+
data: error.message,
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
exports.default = exports.Request;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import axios, {Method, AxiosRequestConfig} from 'axios';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 请求结果接口
|
|
5
|
+
*/
|
|
6
|
+
export interface AjaxResult {
|
|
7
|
+
status: 'success' | 'error';
|
|
8
|
+
data: any;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export const Request = {
|
|
12
|
+
/**
|
|
13
|
+
* HTTP 请求方法
|
|
14
|
+
* @param url 请求链接
|
|
15
|
+
* @param method HTTP 请求方法 (如 GET, POST 等)
|
|
16
|
+
* @param params 请求参数
|
|
17
|
+
* @param headers 请求头
|
|
18
|
+
* @param timeout 超时时间(毫秒)
|
|
19
|
+
* @returns 返回包含状态和数据的 Promise 对象
|
|
20
|
+
*/
|
|
21
|
+
ajax(
|
|
22
|
+
url: string,
|
|
23
|
+
method: Method | string,
|
|
24
|
+
params?: any,
|
|
25
|
+
headers?: Record<string, any>,
|
|
26
|
+
timeout?: number,
|
|
27
|
+
): Promise<AjaxResult> {
|
|
28
|
+
const config: AxiosRequestConfig = {
|
|
29
|
+
url: url,
|
|
30
|
+
method: method,
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
if (params) {
|
|
34
|
+
config.data = params;
|
|
35
|
+
}
|
|
36
|
+
if (headers) {
|
|
37
|
+
config.headers = headers;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
axios.defaults.timeout = timeout ? timeout : 10000;
|
|
41
|
+
|
|
42
|
+
return new Promise(resolve => {
|
|
43
|
+
axios(config)
|
|
44
|
+
.then(response => {
|
|
45
|
+
if (response.status === 200) {
|
|
46
|
+
resolve({
|
|
47
|
+
status: 'success',
|
|
48
|
+
data: response.data,
|
|
49
|
+
});
|
|
50
|
+
} else {
|
|
51
|
+
resolve({
|
|
52
|
+
status: 'error',
|
|
53
|
+
data: response.data?.message || '未知错误',
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
})
|
|
57
|
+
.catch(error => {
|
|
58
|
+
resolve({
|
|
59
|
+
status: 'error',
|
|
60
|
+
data: error.message,
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
},
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
export default Request;
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.cli = cli;
|
|
7
|
+
const ora_1 = __importDefault(require("ora"));
|
|
8
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
9
|
+
const inquirer_1 = __importDefault(require("inquirer"));
|
|
10
|
+
/**
|
|
11
|
+
* CLI 交互与日志工具函数
|
|
12
|
+
*/
|
|
13
|
+
function cli() {
|
|
14
|
+
const spinner = (0, ora_1.default)({
|
|
15
|
+
interval: 70,
|
|
16
|
+
});
|
|
17
|
+
function clean() {
|
|
18
|
+
spinner.stop();
|
|
19
|
+
spinner.text = '';
|
|
20
|
+
}
|
|
21
|
+
return {
|
|
22
|
+
/**
|
|
23
|
+
* 为 CLI 提示添加交互问题
|
|
24
|
+
* @param questions 使用 inquirer 配置,请参阅文档 https://www.npmjs.com/package/inquirer
|
|
25
|
+
* @returns 返回 Promise 对象
|
|
26
|
+
*/
|
|
27
|
+
addQuestions(questions) {
|
|
28
|
+
return Promise.resolve(inquirer_1.default.prompt(questions));
|
|
29
|
+
},
|
|
30
|
+
/**
|
|
31
|
+
* 加载中动画方法集合
|
|
32
|
+
*/
|
|
33
|
+
loading: {
|
|
34
|
+
/**
|
|
35
|
+
* 开始加载动画
|
|
36
|
+
* @param text 提示文本
|
|
37
|
+
*/
|
|
38
|
+
start(text) {
|
|
39
|
+
clean();
|
|
40
|
+
spinner.start(`${text}\n`);
|
|
41
|
+
},
|
|
42
|
+
/**
|
|
43
|
+
* 显示成功状态
|
|
44
|
+
* @param text 提示文本
|
|
45
|
+
*/
|
|
46
|
+
succeed(text) {
|
|
47
|
+
clean();
|
|
48
|
+
spinner.succeed(text);
|
|
49
|
+
},
|
|
50
|
+
/**
|
|
51
|
+
* 显示失败状态
|
|
52
|
+
* @param text 提示文本
|
|
53
|
+
*/
|
|
54
|
+
fail(text) {
|
|
55
|
+
clean();
|
|
56
|
+
spinner.fail(text);
|
|
57
|
+
},
|
|
58
|
+
/**
|
|
59
|
+
* 显示警告状态
|
|
60
|
+
* @param text 提示文本
|
|
61
|
+
*/
|
|
62
|
+
warn(text) {
|
|
63
|
+
clean();
|
|
64
|
+
spinner.warn(text);
|
|
65
|
+
},
|
|
66
|
+
/**
|
|
67
|
+
* 显示信息状态
|
|
68
|
+
* @param text 提示文本
|
|
69
|
+
*/
|
|
70
|
+
info(text) {
|
|
71
|
+
clean();
|
|
72
|
+
spinner.info(text);
|
|
73
|
+
},
|
|
74
|
+
/**
|
|
75
|
+
* 清除加载状态
|
|
76
|
+
*/
|
|
77
|
+
clean,
|
|
78
|
+
},
|
|
79
|
+
/**
|
|
80
|
+
* 控制台日志输出方法集合
|
|
81
|
+
*/
|
|
82
|
+
log: {
|
|
83
|
+
/**
|
|
84
|
+
* 输出普通信息日志
|
|
85
|
+
* @param msg 消息文本
|
|
86
|
+
* @param datas 附加数据
|
|
87
|
+
*/
|
|
88
|
+
info(msg, ...datas) {
|
|
89
|
+
console.log(chalk_1.default.gray.bold(msg, ...datas));
|
|
90
|
+
},
|
|
91
|
+
/**
|
|
92
|
+
* 输出成功日志
|
|
93
|
+
* @param msg 消息文本
|
|
94
|
+
* @param datas 附加数据
|
|
95
|
+
*/
|
|
96
|
+
success(msg, ...datas) {
|
|
97
|
+
console.log(chalk_1.default.green.bold(msg, ...datas));
|
|
98
|
+
},
|
|
99
|
+
/**
|
|
100
|
+
* 输出错误日志
|
|
101
|
+
* @param msg 消息文本
|
|
102
|
+
* @param datas 附加数据
|
|
103
|
+
*/
|
|
104
|
+
error(msg, ...datas) {
|
|
105
|
+
console.log(chalk_1.default.red.bold(msg, ...datas));
|
|
106
|
+
},
|
|
107
|
+
/**
|
|
108
|
+
* 输出警告日志
|
|
109
|
+
* @param msg 消息文本
|
|
110
|
+
* @param datas 附加数据
|
|
111
|
+
*/
|
|
112
|
+
warn(msg, ...datas) {
|
|
113
|
+
console.log(chalk_1.default.hex('#FF8880').bold(msg, ...datas));
|
|
114
|
+
},
|
|
115
|
+
/**
|
|
116
|
+
* 深度打印 JSON 对象
|
|
117
|
+
* @param obj JSON 对象
|
|
118
|
+
*/
|
|
119
|
+
printObject(obj) {
|
|
120
|
+
console.dir(obj, { depth: null });
|
|
121
|
+
},
|
|
122
|
+
/**
|
|
123
|
+
* 仅在调试模式下打印。如果使用此方法,需设置 process.env['DEBUG_ENV'] = 'true'
|
|
124
|
+
* @param msg 消息文本
|
|
125
|
+
* @param datas 附加数据
|
|
126
|
+
*/
|
|
127
|
+
debug(msg, ...datas) {
|
|
128
|
+
if (process.env['DEBUG_ENV'] === 'true') {
|
|
129
|
+
console.log(chalk_1.default.blue.bold(msg, ...datas));
|
|
130
|
+
}
|
|
131
|
+
},
|
|
132
|
+
},
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
exports.default = cli;
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import ora from 'ora';
|
|
2
|
+
import chalk from 'chalk';
|
|
3
|
+
import inquirer, {Answers, PromptSession} from 'inquirer';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* CLI 交互与日志工具函数
|
|
7
|
+
*/
|
|
8
|
+
export function cli() {
|
|
9
|
+
const spinner = ora({
|
|
10
|
+
interval: 70,
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
function clean(): void {
|
|
14
|
+
spinner.stop();
|
|
15
|
+
spinner.text = '';
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return {
|
|
19
|
+
/**
|
|
20
|
+
* 为 CLI 提示添加交互问题
|
|
21
|
+
* @param questions 使用 inquirer 配置,请参阅文档 https://www.npmjs.com/package/inquirer
|
|
22
|
+
* @returns 返回 Promise 对象
|
|
23
|
+
*/
|
|
24
|
+
addQuestions(questions: PromptSession): Promise<Answers> {
|
|
25
|
+
return Promise.resolve(inquirer.prompt(questions));
|
|
26
|
+
},
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* 加载中动画方法集合
|
|
30
|
+
*/
|
|
31
|
+
loading: {
|
|
32
|
+
/**
|
|
33
|
+
* 开始加载动画
|
|
34
|
+
* @param text 提示文本
|
|
35
|
+
*/
|
|
36
|
+
start(text: string): void {
|
|
37
|
+
clean();
|
|
38
|
+
spinner.start(`${text}\n`);
|
|
39
|
+
},
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* 显示成功状态
|
|
43
|
+
* @param text 提示文本
|
|
44
|
+
*/
|
|
45
|
+
succeed(text: string): void {
|
|
46
|
+
clean();
|
|
47
|
+
spinner.succeed(text);
|
|
48
|
+
},
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* 显示失败状态
|
|
52
|
+
* @param text 提示文本
|
|
53
|
+
*/
|
|
54
|
+
fail(text: string): void {
|
|
55
|
+
clean();
|
|
56
|
+
spinner.fail(text);
|
|
57
|
+
},
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* 显示警告状态
|
|
61
|
+
* @param text 提示文本
|
|
62
|
+
*/
|
|
63
|
+
warn(text: string): void {
|
|
64
|
+
clean();
|
|
65
|
+
spinner.warn(text);
|
|
66
|
+
},
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* 显示信息状态
|
|
70
|
+
* @param text 提示文本
|
|
71
|
+
*/
|
|
72
|
+
info(text: string): void {
|
|
73
|
+
clean();
|
|
74
|
+
spinner.info(text);
|
|
75
|
+
},
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* 清除加载状态
|
|
79
|
+
*/
|
|
80
|
+
clean,
|
|
81
|
+
},
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* 控制台日志输出方法集合
|
|
85
|
+
*/
|
|
86
|
+
log: {
|
|
87
|
+
/**
|
|
88
|
+
* 输出普通信息日志
|
|
89
|
+
* @param msg 消息文本
|
|
90
|
+
* @param datas 附加数据
|
|
91
|
+
*/
|
|
92
|
+
info(msg: string, ...datas: any[]): void {
|
|
93
|
+
console.log(chalk.gray.bold(msg, ...datas));
|
|
94
|
+
},
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* 输出成功日志
|
|
98
|
+
* @param msg 消息文本
|
|
99
|
+
* @param datas 附加数据
|
|
100
|
+
*/
|
|
101
|
+
success(msg: string, ...datas: any[]): void {
|
|
102
|
+
console.log(chalk.green.bold(msg, ...datas));
|
|
103
|
+
},
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* 输出错误日志
|
|
107
|
+
* @param msg 消息文本
|
|
108
|
+
* @param datas 附加数据
|
|
109
|
+
*/
|
|
110
|
+
error(msg: string, ...datas: any[]): void {
|
|
111
|
+
console.log(chalk.red.bold(msg, ...datas));
|
|
112
|
+
},
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* 输出警告日志
|
|
116
|
+
* @param msg 消息文本
|
|
117
|
+
* @param datas 附加数据
|
|
118
|
+
*/
|
|
119
|
+
warn(msg: string, ...datas: any[]): void {
|
|
120
|
+
console.log(chalk.hex('#FF8880').bold(msg, ...datas));
|
|
121
|
+
},
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* 深度打印 JSON 对象
|
|
125
|
+
* @param obj JSON 对象
|
|
126
|
+
*/
|
|
127
|
+
printObject(obj: any): void {
|
|
128
|
+
console.dir(obj, {depth: null});
|
|
129
|
+
},
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* 仅在调试模式下打印。如果使用此方法,需设置 process.env['DEBUG_ENV'] = 'true'
|
|
133
|
+
* @param msg 消息文本
|
|
134
|
+
* @param datas 附加数据
|
|
135
|
+
*/
|
|
136
|
+
debug(msg: string, ...datas: any[]): void {
|
|
137
|
+
if (process.env['DEBUG_ENV'] === 'true') {
|
|
138
|
+
console.log(chalk.blue.bold(msg, ...datas));
|
|
139
|
+
}
|
|
140
|
+
},
|
|
141
|
+
},
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
export default cli;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.Publish = exports.Subscribe = exports.ChildProcess = exports.CLI = exports.Wait = exports.Base = void 0;
|
|
7
|
+
const cli_1 = __importDefault(require("./cli"));
|
|
8
|
+
const queue_1 = __importDefault(require("./queue"));
|
|
9
|
+
const cli_api_1 = require("../cli-api");
|
|
10
|
+
Object.defineProperty(exports, "ChildProcess", { enumerable: true, get: function () { return cli_api_1.childProcess; } });
|
|
11
|
+
const watcher_1 = require("./watcher");
|
|
12
|
+
Object.defineProperty(exports, "Subscribe", { enumerable: true, get: function () { return watcher_1.Subscribe; } });
|
|
13
|
+
Object.defineProperty(exports, "Publish", { enumerable: true, get: function () { return watcher_1.Publish; } });
|
|
14
|
+
const lang_1 = require("../service/lang");
|
|
15
|
+
// 默认的生命周期阶段数组
|
|
16
|
+
const defaultLifecycle = ['init', 'prompt', 'default', 'writing', 'install', 'end'];
|
|
17
|
+
const Wait = (0, queue_1.default)();
|
|
18
|
+
exports.Wait = Wait;
|
|
19
|
+
const CLI = (0, cli_1.default)();
|
|
20
|
+
exports.CLI = CLI;
|
|
21
|
+
// 开始显示核心启动加载提示
|
|
22
|
+
CLI.loading.start(lang_1.Lang.BUILDIN.CORE_STRTUP);
|
|
23
|
+
const Base = {
|
|
24
|
+
// 状态对象
|
|
25
|
+
state: {},
|
|
26
|
+
/**
|
|
27
|
+
* 扩展并注册运行时生命周期任务
|
|
28
|
+
* @param runtimeLifecycle 运行时生命周期对象
|
|
29
|
+
*/
|
|
30
|
+
extends(runtimeLifecycle) {
|
|
31
|
+
defaultLifecycle.forEach(task => {
|
|
32
|
+
if (Object.prototype.hasOwnProperty.call(runtimeLifecycle, task)) {
|
|
33
|
+
const taskFn = runtimeLifecycle[task];
|
|
34
|
+
if (taskFn) {
|
|
35
|
+
Wait.enqueue(taskFn);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
CLI.loading.succeed(lang_1.Lang.BUILDIN.CORE_STRTUP_DONE);
|
|
40
|
+
Wait.next();
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
exports.Base = Base;
|
|
44
|
+
exports.default = {
|
|
45
|
+
Base,
|
|
46
|
+
Wait,
|
|
47
|
+
CLI,
|
|
48
|
+
ChildProcess: cli_api_1.childProcess,
|
|
49
|
+
Subscribe: watcher_1.Subscribe,
|
|
50
|
+
Publish: watcher_1.Publish,
|
|
51
|
+
};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import cli from './cli';
|
|
2
|
+
import queue from './queue';
|
|
3
|
+
import {childProcess as ChildProcess} from '../cli-api';
|
|
4
|
+
import {Subscribe, Publish} from './watcher';
|
|
5
|
+
import {Lang} from '../service/lang';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* 生命周期任务函数类型
|
|
9
|
+
*/
|
|
10
|
+
type LifecycleTask = () => void;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* 运行时生命周期配置接口
|
|
14
|
+
*/
|
|
15
|
+
type RuntimeLifecycle = Partial<Record<string, LifecycleTask>>;
|
|
16
|
+
|
|
17
|
+
// 默认的生命周期阶段数组
|
|
18
|
+
const defaultLifecycle = ['init', 'prompt', 'default', 'writing', 'install', 'end'];
|
|
19
|
+
|
|
20
|
+
const Wait = queue();
|
|
21
|
+
const CLI = cli();
|
|
22
|
+
|
|
23
|
+
// 开始显示核心启动加载提示
|
|
24
|
+
CLI.loading.start(Lang.BUILDIN.CORE_STRTUP);
|
|
25
|
+
|
|
26
|
+
const Base = {
|
|
27
|
+
// 状态对象
|
|
28
|
+
state: {} as Record<string, any>,
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* 扩展并注册运行时生命周期任务
|
|
32
|
+
* @param runtimeLifecycle 运行时生命周期对象
|
|
33
|
+
*/
|
|
34
|
+
extends(runtimeLifecycle: RuntimeLifecycle): void {
|
|
35
|
+
defaultLifecycle.forEach(task => {
|
|
36
|
+
if (Object.prototype.hasOwnProperty.call(runtimeLifecycle, task)) {
|
|
37
|
+
const taskFn = runtimeLifecycle[task];
|
|
38
|
+
if (taskFn) {
|
|
39
|
+
Wait.enqueue(taskFn);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
CLI.loading.succeed(Lang.BUILDIN.CORE_STRTUP_DONE);
|
|
45
|
+
Wait.next();
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
export {Base, Wait, CLI, ChildProcess, Subscribe, Publish};
|
|
50
|
+
|
|
51
|
+
export default {
|
|
52
|
+
Base,
|
|
53
|
+
Wait,
|
|
54
|
+
CLI,
|
|
55
|
+
ChildProcess,
|
|
56
|
+
Subscribe,
|
|
57
|
+
Publish,
|
|
58
|
+
};
|