@qingtian/qtcli 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/README.md +193 -0
- package/dist/bin/cli.js +11 -0
- package/dist/package.json +209 -0
- package/dist/qt.conf.js +101 -0
- package/dist/src/App.js +10 -0
- package/dist/src/commands/build.js +74 -0
- package/dist/src/commands/dev.js +68 -0
- package/dist/src/commands/index.js +83 -0
- package/dist/src/commands/init.js +128 -0
- package/dist/src/cores/context.js +123 -0
- package/dist/src/index.js +29 -0
- package/dist/src/processEnv/index.js +23 -0
- package/dist/src/processEnv/injector.js +39 -0
- package/dist/src/processEnv/loader.js +201 -0
- package/dist/src/processEnv/manager.js +122 -0
- package/dist/src/processEnv/types.js +2 -0
- package/dist/src/proxys/build/index.js +225 -0
- package/dist/src/proxys/dev/index.js +284 -0
- package/dist/src/proxys/init/index.js +90 -0
- package/dist/src/servers/server.js +46 -0
- package/dist/src/types/baseInterface.js +46 -0
- package/dist/src/types/contextModel.js +21 -0
- package/dist/src/utils/childProcess.js +134 -0
- package/dist/src/utils/env.js +56 -0
- package/dist/src/utils/fileUtils.js +121 -0
- package/dist/src/utils/format.js +23 -0
- package/dist/src/utils/formatOutput.js +242 -0
- package/dist/src/utils/logger.js +70 -0
- package/dist/src/utils/printer.js +148 -0
- package/dist/src/utils/sleep.js +11 -0
- package/dist/src/utils/url.js +42 -0
- package/dist/src/webpack/npm/es.js +127 -0
- package/dist/src/webpack/npm/index.js +100 -0
- package/dist/src/webpack/npm/lib.js +128 -0
- package/dist/src/webpack/npm/webpack.base.js +221 -0
- package/dist/src/webpack/npm/webpack.prod.js +76 -0
- package/dist/src/webpack/plugins/DonePlugin.js +14 -0
- package/dist/src/webpack/plugins/FileListPlugin.js +28 -0
- package/dist/src/webpack/plugins/InjectScriptPlugin.js +33 -0
- package/dist/src/webpack/web/index.js +130 -0
- package/dist/src/webpack/web/webpack.analy.js +10 -0
- package/dist/src/webpack/web/webpack.base.js +419 -0
- package/dist/src/webpack/web/webpack.dev.js +38 -0
- package/dist/src/webpack/web/webpack.prod.js +82 -0
- package/package.json +209 -0
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.ProcessEnvManager = void 0;
|
|
15
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
16
|
+
var loader_1 = require("./loader");
|
|
17
|
+
var ProcessEnvManager = /** @class */ (function () {
|
|
18
|
+
function ProcessEnvManager() {
|
|
19
|
+
this.clientEnv = null;
|
|
20
|
+
this.initialized = false;
|
|
21
|
+
this.loader = loader_1.ProcessEnvLoader.getInstance();
|
|
22
|
+
this.options = this.getDefaultOptions();
|
|
23
|
+
}
|
|
24
|
+
ProcessEnvManager.getInstance = function () {
|
|
25
|
+
if (!ProcessEnvManager.instance) {
|
|
26
|
+
ProcessEnvManager.instance = new ProcessEnvManager();
|
|
27
|
+
}
|
|
28
|
+
return ProcessEnvManager.instance;
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* 获取客户端环境变量
|
|
32
|
+
*/
|
|
33
|
+
ProcessEnvManager.prototype.getClientEnvironment = function () {
|
|
34
|
+
if (!this.initialized) {
|
|
35
|
+
// 如果环境变量未初始化,尝试使用默认值初始化
|
|
36
|
+
var env = process.env.NODE_ENV || 'development';
|
|
37
|
+
this.initialize(env, process.cwd(), process.env.PUBLIC_URL || '');
|
|
38
|
+
}
|
|
39
|
+
if (!this.clientEnv) {
|
|
40
|
+
throw new Error('客户端环境变量未初始化');
|
|
41
|
+
}
|
|
42
|
+
return this.clientEnv;
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* 检查当前环境
|
|
46
|
+
*/
|
|
47
|
+
ProcessEnvManager.prototype.isDevelopment = function () {
|
|
48
|
+
return this.options.NODE_ENV === 'development';
|
|
49
|
+
};
|
|
50
|
+
ProcessEnvManager.prototype.isProduction = function () {
|
|
51
|
+
return this.options.NODE_ENV === 'production';
|
|
52
|
+
};
|
|
53
|
+
ProcessEnvManager.prototype.isTest = function () {
|
|
54
|
+
return this.options.NODE_ENV === 'test';
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* 获取配置选项
|
|
58
|
+
*/
|
|
59
|
+
ProcessEnvManager.prototype.getOptions = function () {
|
|
60
|
+
return this.options;
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* 获取 API URL
|
|
64
|
+
*/
|
|
65
|
+
ProcessEnvManager.prototype.getApiUrl = function () {
|
|
66
|
+
return this.options.API_URL;
|
|
67
|
+
};
|
|
68
|
+
/**
|
|
69
|
+
* 获取 API 超时时间
|
|
70
|
+
*/
|
|
71
|
+
ProcessEnvManager.prototype.getApiTimeout = function () {
|
|
72
|
+
return this.options.API_TIMEOUT;
|
|
73
|
+
};
|
|
74
|
+
/**
|
|
75
|
+
* 初始化环境变量
|
|
76
|
+
*/
|
|
77
|
+
ProcessEnvManager.prototype.initialize = function (env, rootDir, publicUrl) {
|
|
78
|
+
// 加载环境变量文件
|
|
79
|
+
this.loader.loadEnvFiles(env, rootDir);
|
|
80
|
+
// 合并环境变量
|
|
81
|
+
this.loader.mergeEnvs();
|
|
82
|
+
// 更新配置选项
|
|
83
|
+
this.updateOptionsFromEnv();
|
|
84
|
+
// 获取客户端环境变量
|
|
85
|
+
this.clientEnv = this.loader.getClientEnvironment(publicUrl);
|
|
86
|
+
this.initialized = true;
|
|
87
|
+
};
|
|
88
|
+
/**
|
|
89
|
+
* 获取默认配置选项
|
|
90
|
+
*/
|
|
91
|
+
ProcessEnvManager.prototype.getDefaultOptions = function () {
|
|
92
|
+
return {
|
|
93
|
+
API_URL: '',
|
|
94
|
+
API_TIMEOUT: 30000,
|
|
95
|
+
NODE_ENV: 'development',
|
|
96
|
+
VERSION: '1.0.0',
|
|
97
|
+
BUILD_TIME: new Date().toISOString(),
|
|
98
|
+
DEBUG: false,
|
|
99
|
+
PUBLIC_URL: '',
|
|
100
|
+
};
|
|
101
|
+
};
|
|
102
|
+
/**
|
|
103
|
+
* 从环境变量更新配置选项
|
|
104
|
+
*/
|
|
105
|
+
ProcessEnvManager.prototype.updateOptionsFromEnv = function () {
|
|
106
|
+
var env = this.loader.getMergedEnv();
|
|
107
|
+
var oldOptions = __assign({}, this.options);
|
|
108
|
+
// 将环境变量转换为大写加下划线的形式
|
|
109
|
+
var envOptions = {};
|
|
110
|
+
Object.entries(env).forEach(function (_a) {
|
|
111
|
+
var key = _a[0], value = _a[1];
|
|
112
|
+
// 将键名转换为大写加下划线的形式
|
|
113
|
+
var upperKey = key.toUpperCase().replace(/[^A-Z0-9]/g, '_');
|
|
114
|
+
envOptions[upperKey] = value;
|
|
115
|
+
});
|
|
116
|
+
// 更新配置选项
|
|
117
|
+
this.options = __assign(__assign({}, this.options), envOptions);
|
|
118
|
+
// console.log(oldOptions, this.options);
|
|
119
|
+
};
|
|
120
|
+
return ProcessEnvManager;
|
|
121
|
+
}());
|
|
122
|
+
exports.ProcessEnvManager = ProcessEnvManager;
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (_) try {
|
|
18
|
+
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;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
|
+
};
|
|
41
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
+
var cli_progress_1 = __importDefault(require("cli-progress"));
|
|
43
|
+
var colors_1 = __importDefault(require("colors"));
|
|
44
|
+
var commander_1 = require("commander");
|
|
45
|
+
var path_1 = __importDefault(require("path"));
|
|
46
|
+
var childProcess_1 = require("../../utils/childProcess");
|
|
47
|
+
var formatOutput_1 = require("../../utils/formatOutput");
|
|
48
|
+
var bar1 = new cli_progress_1.default.SingleBar({
|
|
49
|
+
format: "\u2502 ".concat(colors_1.default.blue('○'), " \u7F16\u8BD1\u8FDB\u5EA6 {percentage}%"),
|
|
50
|
+
barCompleteChar: '=',
|
|
51
|
+
barIncompleteChar: '-',
|
|
52
|
+
barsize: 80,
|
|
53
|
+
hideCursor: true,
|
|
54
|
+
}, cli_progress_1.default.Presets.shades_classic);
|
|
55
|
+
function outList(list) {
|
|
56
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
57
|
+
var _a, _b;
|
|
58
|
+
return __generator(this, function (_c) {
|
|
59
|
+
switch (_c.label) {
|
|
60
|
+
case 0:
|
|
61
|
+
_b = (_a = console).log;
|
|
62
|
+
return [4 /*yield*/, formatOutput_1.formatOutput.buildFiles(list.map(function (_a) {
|
|
63
|
+
var filename = _a.filename, size = _a.size;
|
|
64
|
+
return ({
|
|
65
|
+
name: filename,
|
|
66
|
+
size: size.toString(),
|
|
67
|
+
});
|
|
68
|
+
}))];
|
|
69
|
+
case 1:
|
|
70
|
+
_b.apply(_a, [_c.sent()]);
|
|
71
|
+
return [2 /*return*/];
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
function outResult(_a) {
|
|
77
|
+
var time = _a.time, errors = _a.errors, warings = _a.warings;
|
|
78
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
79
|
+
var _b, _c;
|
|
80
|
+
return __generator(this, function (_d) {
|
|
81
|
+
switch (_d.label) {
|
|
82
|
+
case 0:
|
|
83
|
+
_c = (_b = console).log;
|
|
84
|
+
return [4 /*yield*/, formatOutput_1.formatOutput.build({
|
|
85
|
+
files: [],
|
|
86
|
+
time: time,
|
|
87
|
+
errors: (errors === null || errors === void 0 ? void 0 : errors.length) || 0,
|
|
88
|
+
warnings: (warings === null || warings === void 0 ? void 0 : warings.length) || 0,
|
|
89
|
+
buildErrors: errors,
|
|
90
|
+
buildWarnings: warings,
|
|
91
|
+
})];
|
|
92
|
+
case 1:
|
|
93
|
+
_c.apply(_b, [_d.sent()]);
|
|
94
|
+
return [2 /*return*/];
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
var fun = function (opts) { return __awaiter(void 0, void 0, void 0, function () {
|
|
100
|
+
var _a, target, analy, env;
|
|
101
|
+
return __generator(this, function (_b) {
|
|
102
|
+
_a = opts.argsCmd, target = _a.target, analy = _a.analy, env = _a.env;
|
|
103
|
+
console.log((0, formatOutput_1.formatNode)({
|
|
104
|
+
type: 'process',
|
|
105
|
+
title: '构建开始',
|
|
106
|
+
content: '正在构建项目...',
|
|
107
|
+
}));
|
|
108
|
+
return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(void 0, void 0, void 0, function () {
|
|
109
|
+
var isComplete_1, isEnd_1, isList_1, isBuild_1, list_1, port_1, time_1, errors_1, warings_1, ptime_1;
|
|
110
|
+
var _a;
|
|
111
|
+
return __generator(this, function (_b) {
|
|
112
|
+
try {
|
|
113
|
+
isComplete_1 = false;
|
|
114
|
+
isEnd_1 = false;
|
|
115
|
+
isList_1 = false;
|
|
116
|
+
isBuild_1 = false;
|
|
117
|
+
list_1 = [];
|
|
118
|
+
port_1 = 0;
|
|
119
|
+
time_1 = 0;
|
|
120
|
+
errors_1 = [];
|
|
121
|
+
warings_1 = [];
|
|
122
|
+
ptime_1 = new Date().getTime();
|
|
123
|
+
bar1.start(100, 0);
|
|
124
|
+
(0, childProcess_1.forkPromise)("".concat(path_1.default.resolve(__dirname, "../../webpack/".concat(target === 'npm' ? 'npm' : 'web', "/index"))), ["".concat(opts.cmd), "".concat(JSON.stringify(opts.argsCmd))], {
|
|
125
|
+
cwd: path_1.default.resolve(process.cwd(), './'),
|
|
126
|
+
silent: !((_a = commander_1.program.optsWithGlobals()) === null || _a === void 0 ? void 0 : _a.debug),
|
|
127
|
+
}, function (m) { return __awaiter(void 0, void 0, void 0, function () {
|
|
128
|
+
var content, _a, buildTime, buildErrors, buildWarnings;
|
|
129
|
+
var _b;
|
|
130
|
+
return __generator(this, function (_c) {
|
|
131
|
+
switch (_c.label) {
|
|
132
|
+
case 0:
|
|
133
|
+
if (!((m === null || m === void 0 ? void 0 : m.type) === 'listEnd')) return [3 /*break*/, 2];
|
|
134
|
+
list_1 = (m === null || m === void 0 ? void 0 : m.data) || [];
|
|
135
|
+
if (!isComplete_1) return [3 /*break*/, 2];
|
|
136
|
+
return [4 /*yield*/, outList(list_1)];
|
|
137
|
+
case 1:
|
|
138
|
+
_c.sent();
|
|
139
|
+
isList_1 = true;
|
|
140
|
+
_c.label = 2;
|
|
141
|
+
case 2:
|
|
142
|
+
if ((m === null || m === void 0 ? void 0 : m.type) === 'DonePlugin') {
|
|
143
|
+
content = m === null || m === void 0 ? void 0 : m.data;
|
|
144
|
+
port_1 = content === null || content === void 0 ? void 0 : content.port;
|
|
145
|
+
time_1 = new Date().getTime() - ptime_1;
|
|
146
|
+
if (isComplete_1) {
|
|
147
|
+
isEnd_1 = true;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
if (!((m === null || m === void 0 ? void 0 : m.type) === 'progress')) return [3 /*break*/, 5];
|
|
151
|
+
bar1.update(Math.floor((m === null || m === void 0 ? void 0 : m.data) * 100));
|
|
152
|
+
if (!(Math.floor((m === null || m === void 0 ? void 0 : m.data) * 100) >= 100)) return [3 /*break*/, 5];
|
|
153
|
+
bar1.stop();
|
|
154
|
+
isComplete_1 = true;
|
|
155
|
+
if (!!isList_1) return [3 /*break*/, 4];
|
|
156
|
+
return [4 /*yield*/, outList(list_1)];
|
|
157
|
+
case 3:
|
|
158
|
+
_c.sent();
|
|
159
|
+
_c.label = 4;
|
|
160
|
+
case 4:
|
|
161
|
+
if (!isEnd_1) {
|
|
162
|
+
}
|
|
163
|
+
_c.label = 5;
|
|
164
|
+
case 5:
|
|
165
|
+
if (!((m === null || m === void 0 ? void 0 : m.type) === 'buildSuccess')) return [3 /*break*/, 7];
|
|
166
|
+
isBuild_1 = true;
|
|
167
|
+
_a = (m === null || m === void 0 ? void 0 : m.data) || {}, buildTime = _a.time, buildErrors = _a.errors, buildWarnings = _a.warings;
|
|
168
|
+
time_1 = buildTime;
|
|
169
|
+
errors_1 = buildErrors;
|
|
170
|
+
warings_1 = buildWarnings;
|
|
171
|
+
return [4 /*yield*/, outResult({ time: time_1, errors: errors_1, warings: warings_1 })];
|
|
172
|
+
case 6:
|
|
173
|
+
_c.sent();
|
|
174
|
+
if (errors_1 === null || errors_1 === void 0 ? void 0 : errors_1.length) {
|
|
175
|
+
reject();
|
|
176
|
+
}
|
|
177
|
+
else {
|
|
178
|
+
if (target === 'web') {
|
|
179
|
+
resolve(true);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
_c.label = 7;
|
|
183
|
+
case 7:
|
|
184
|
+
if ((m === null || m === void 0 ? void 0 : m.type) === 'beforeLibBuild' || (m === null || m === void 0 ? void 0 : m.type) === 'beforeEsBuild') {
|
|
185
|
+
console.log((0, formatOutput_1.formatNode)({
|
|
186
|
+
type: 'process',
|
|
187
|
+
title: '模块构建',
|
|
188
|
+
content: "\u5F00\u59CB\u6784\u5EFA".concat((m === null || m === void 0 ? void 0 : m.type) === 'beforeLibBuild' ? 'CommonJs' : 'EsModule', "\u6A21\u5757..."),
|
|
189
|
+
}));
|
|
190
|
+
}
|
|
191
|
+
if ((m === null || m === void 0 ? void 0 : m.type) === 'afterLibBuild' || (m === null || m === void 0 ? void 0 : m.type) === 'afterEsBuild') {
|
|
192
|
+
console.log((0, formatOutput_1.formatNode)({
|
|
193
|
+
type: 'process',
|
|
194
|
+
title: '模块构建完成',
|
|
195
|
+
content: "\u6210\u529F\u6784\u5EFA".concat((m === null || m === void 0 ? void 0 : m.type) === 'afterLibBuild' ? 'CommonJs' : 'EsModule', "\u6A21\u5757\uFF0C\u8017\u65F6: ").concat((((_b = m === null || m === void 0 ? void 0 : m.data) === null || _b === void 0 ? void 0 : _b.time) / 1000).toFixed(2), "s"),
|
|
196
|
+
status: 'success',
|
|
197
|
+
}));
|
|
198
|
+
if ((m === null || m === void 0 ? void 0 : m.type) === 'afterEsBuild') {
|
|
199
|
+
resolve(true);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
if ((m === null || m === void 0 ? void 0 : m.type) === 'buildFaild') {
|
|
203
|
+
console.log((0, formatOutput_1.formatNode)({
|
|
204
|
+
type: 'process',
|
|
205
|
+
title: '构建失败',
|
|
206
|
+
content: '构建过程发生错误',
|
|
207
|
+
status: 'error',
|
|
208
|
+
}));
|
|
209
|
+
isBuild_1 = true;
|
|
210
|
+
reject(22);
|
|
211
|
+
}
|
|
212
|
+
return [2 /*return*/];
|
|
213
|
+
}
|
|
214
|
+
});
|
|
215
|
+
}); });
|
|
216
|
+
}
|
|
217
|
+
catch (err) {
|
|
218
|
+
reject(err);
|
|
219
|
+
}
|
|
220
|
+
return [2 /*return*/];
|
|
221
|
+
});
|
|
222
|
+
}); })];
|
|
223
|
+
});
|
|
224
|
+
}); };
|
|
225
|
+
exports.default = fun;
|
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (_) try {
|
|
18
|
+
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;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
|
+
};
|
|
41
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
43
|
+
/* eslint-disable @typescript-eslint/no-shadow */
|
|
44
|
+
var cli_progress_1 = __importDefault(require("cli-progress"));
|
|
45
|
+
var colors_1 = __importDefault(require("colors"));
|
|
46
|
+
var commander_1 = require("commander");
|
|
47
|
+
var eslint_1 = require("eslint");
|
|
48
|
+
var path_1 = __importDefault(require("path"));
|
|
49
|
+
var childProcess_1 = require("../../utils/childProcess");
|
|
50
|
+
var formatOutput_1 = require("../../utils/formatOutput");
|
|
51
|
+
var logger_1 = require("../../utils/logger");
|
|
52
|
+
var bar1 = new cli_progress_1.default.SingleBar({
|
|
53
|
+
format: "\u2502 ".concat(colors_1.default.blue('○'), " \u7F16\u8BD1\u8FDB\u5EA6 {percentage}%"),
|
|
54
|
+
barCompleteChar: '=',
|
|
55
|
+
barIncompleteChar: '-',
|
|
56
|
+
barsize: 80,
|
|
57
|
+
hideCursor: true,
|
|
58
|
+
}, cli_progress_1.default.Presets.shades_classic);
|
|
59
|
+
function outList(list) {
|
|
60
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
61
|
+
var _a, _b;
|
|
62
|
+
return __generator(this, function (_c) {
|
|
63
|
+
switch (_c.label) {
|
|
64
|
+
case 0:
|
|
65
|
+
_b = (_a = console).log;
|
|
66
|
+
return [4 /*yield*/, formatOutput_1.formatOutput.buildFiles(list.map(function (_a) {
|
|
67
|
+
var filename = _a.filename, size = _a.size;
|
|
68
|
+
return ({
|
|
69
|
+
name: filename,
|
|
70
|
+
size: size.toString(),
|
|
71
|
+
});
|
|
72
|
+
}))];
|
|
73
|
+
case 1:
|
|
74
|
+
_b.apply(_a, [_c.sent()]);
|
|
75
|
+
return [2 /*return*/];
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
function outResult(_a) {
|
|
81
|
+
var _b;
|
|
82
|
+
var time = _a.time, port = _a.port, errors = _a.errors, warings = _a.warings, opts = _a.opts, devServerOptions = _a.devServerOptions, isInit = _a.isInit;
|
|
83
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
84
|
+
var _c, _d, lint, ptime, results, errorCount, warningCount, eslintTime, _e, _f, _g, _h, err_1;
|
|
85
|
+
return __generator(this, function (_j) {
|
|
86
|
+
switch (_j.label) {
|
|
87
|
+
case 0:
|
|
88
|
+
_d = (_c = console).log;
|
|
89
|
+
return [4 /*yield*/, formatOutput_1.formatOutput.build({
|
|
90
|
+
files: [],
|
|
91
|
+
time: time,
|
|
92
|
+
errors: (errors === null || errors === void 0 ? void 0 : errors.length) || 0,
|
|
93
|
+
warnings: (warings === null || warings === void 0 ? void 0 : warings.length) || 0,
|
|
94
|
+
buildErrors: errors,
|
|
95
|
+
buildWarnings: warings,
|
|
96
|
+
})];
|
|
97
|
+
case 1:
|
|
98
|
+
_d.apply(_c, [_j.sent()]);
|
|
99
|
+
lint = new eslint_1.ESLint({
|
|
100
|
+
useEslintrc: true,
|
|
101
|
+
errorOnUnmatchedPattern: true,
|
|
102
|
+
overrideConfig: {
|
|
103
|
+
parserOptions: {
|
|
104
|
+
warnOnUnsupportedTypeScriptVersion: false,
|
|
105
|
+
},
|
|
106
|
+
},
|
|
107
|
+
});
|
|
108
|
+
_j.label = 2;
|
|
109
|
+
case 2:
|
|
110
|
+
_j.trys.push([2, 7, , 8]);
|
|
111
|
+
console.log((0, formatOutput_1.formatNode)({
|
|
112
|
+
type: 'process',
|
|
113
|
+
title: 'ESLint检查',
|
|
114
|
+
content: 'ESLint开始执行...',
|
|
115
|
+
}));
|
|
116
|
+
ptime = new Date().getTime();
|
|
117
|
+
return [4 /*yield*/, lint.lintFiles('./src')];
|
|
118
|
+
case 3:
|
|
119
|
+
results = _j.sent();
|
|
120
|
+
errorCount = results.reduce(function (sum, result) { return sum + result.errorCount; }, 0);
|
|
121
|
+
warningCount = results.reduce(function (sum, result) { return sum + result.warningCount; }, 0);
|
|
122
|
+
eslintTime = new Date().getTime() - ptime;
|
|
123
|
+
_f = (_e = console).log;
|
|
124
|
+
return [4 /*yield*/, formatOutput_1.formatOutput.eslint({
|
|
125
|
+
results: results.map(function (result) { return ({
|
|
126
|
+
filePath: result.filePath,
|
|
127
|
+
messages: result.messages.map(function (message) { return ({
|
|
128
|
+
ruleId: message.ruleId || undefined,
|
|
129
|
+
severity: message.severity,
|
|
130
|
+
message: message.message,
|
|
131
|
+
line: message.line,
|
|
132
|
+
column: message.column,
|
|
133
|
+
}); }),
|
|
134
|
+
}); }),
|
|
135
|
+
errorCount: errorCount,
|
|
136
|
+
warningCount: warningCount,
|
|
137
|
+
time: eslintTime,
|
|
138
|
+
})];
|
|
139
|
+
case 4:
|
|
140
|
+
_f.apply(_e, [_j.sent()]);
|
|
141
|
+
if (!port) return [3 /*break*/, 6];
|
|
142
|
+
console.log((0, formatOutput_1.formatNode)({
|
|
143
|
+
type: 'process',
|
|
144
|
+
title: '启动服务',
|
|
145
|
+
content: '正在启动开发服务器...',
|
|
146
|
+
}));
|
|
147
|
+
_h = (_g = console).log;
|
|
148
|
+
return [4 /*yield*/, formatOutput_1.formatOutput.service({
|
|
149
|
+
name: '开发服务器',
|
|
150
|
+
port: port.toString(),
|
|
151
|
+
url: "".concat((_b = devServerOptions === null || devServerOptions === void 0 ? void 0 : devServerOptions.server) === null || _b === void 0 ? void 0 : _b.type, "://").concat(devServerOptions.host, ":").concat(devServerOptions.port),
|
|
152
|
+
buildStats: {
|
|
153
|
+
errors: (errors === null || errors === void 0 ? void 0 : errors.length) || 0,
|
|
154
|
+
warnings: (warings === null || warings === void 0 ? void 0 : warings.length) || 0,
|
|
155
|
+
time: time,
|
|
156
|
+
},
|
|
157
|
+
eslintStats: {
|
|
158
|
+
errors: errorCount,
|
|
159
|
+
warnings: warningCount,
|
|
160
|
+
time: eslintTime,
|
|
161
|
+
},
|
|
162
|
+
})];
|
|
163
|
+
case 5:
|
|
164
|
+
_h.apply(_g, [_j.sent()]);
|
|
165
|
+
if (isInit) {
|
|
166
|
+
console.log((0, formatOutput_1.formatNode)({
|
|
167
|
+
type: 'complete',
|
|
168
|
+
title: "\u6267\u884C\u70ED\u66F4\u65B0\u6210\u529F ".concat(colors_1.default.green("".concat(((new Date().getTime() - ptime) / 1000).toFixed(2), "s"))),
|
|
169
|
+
status: 'success',
|
|
170
|
+
}));
|
|
171
|
+
}
|
|
172
|
+
_j.label = 6;
|
|
173
|
+
case 6: return [3 /*break*/, 8];
|
|
174
|
+
case 7:
|
|
175
|
+
err_1 = _j.sent();
|
|
176
|
+
console.log(err_1);
|
|
177
|
+
return [3 /*break*/, 8];
|
|
178
|
+
case 8: return [2 /*return*/];
|
|
179
|
+
}
|
|
180
|
+
});
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
var fun = function (opts) { return __awaiter(void 0, void 0, void 0, function () {
|
|
184
|
+
var target;
|
|
185
|
+
return __generator(this, function (_a) {
|
|
186
|
+
target = opts.argsCmd.target;
|
|
187
|
+
// console.log(
|
|
188
|
+
// formatNode({
|
|
189
|
+
// type: 'process',
|
|
190
|
+
// title: '构建开始',
|
|
191
|
+
// content: '正在构建项目...',
|
|
192
|
+
// }),
|
|
193
|
+
// );
|
|
194
|
+
return [2 /*return*/, new Promise(function (resolve, reject) {
|
|
195
|
+
var _a;
|
|
196
|
+
try {
|
|
197
|
+
var isComplete_1 = false;
|
|
198
|
+
var isCompiled_1 = false;
|
|
199
|
+
var isEnd_1 = false;
|
|
200
|
+
var isList_1 = false;
|
|
201
|
+
var isInit_1 = false;
|
|
202
|
+
var list_1 = [];
|
|
203
|
+
var port_1 = 0;
|
|
204
|
+
var time_1 = 0;
|
|
205
|
+
var errors_1 = [];
|
|
206
|
+
var warings_1 = [];
|
|
207
|
+
var devServerOptions_1 = {};
|
|
208
|
+
(0, childProcess_1.forkPromise)("".concat(path_1.default.resolve(__dirname, "../../webpack/".concat(target === 'npm' ? 'npm' : 'web', "/index"))), ["".concat(opts.cmd), "".concat(JSON.stringify(opts.argsCmd))], {
|
|
209
|
+
cwd: path_1.default.resolve(process.cwd(), './'),
|
|
210
|
+
silent: !((_a = commander_1.program.optsWithGlobals()) === null || _a === void 0 ? void 0 : _a.debug),
|
|
211
|
+
}, function (m) { return __awaiter(void 0, void 0, void 0, function () {
|
|
212
|
+
var content;
|
|
213
|
+
return __generator(this, function (_a) {
|
|
214
|
+
switch (_a.label) {
|
|
215
|
+
case 0:
|
|
216
|
+
if ((m === null || m === void 0 ? void 0 : m.type) === 'compile') {
|
|
217
|
+
isList_1 = false;
|
|
218
|
+
isEnd_1 = false;
|
|
219
|
+
isComplete_1 = false;
|
|
220
|
+
isCompiled_1 = true;
|
|
221
|
+
if (isInit_1) {
|
|
222
|
+
(0, logger_1.logStart)();
|
|
223
|
+
}
|
|
224
|
+
console.log((0, formatOutput_1.formatNode)({
|
|
225
|
+
type: 'process',
|
|
226
|
+
title: '构建开始',
|
|
227
|
+
content: '正在构建项目...',
|
|
228
|
+
}));
|
|
229
|
+
bar1.start(100, 0);
|
|
230
|
+
}
|
|
231
|
+
if ((m === null || m === void 0 ? void 0 : m.type) === 'listEnd') {
|
|
232
|
+
list_1 = (m === null || m === void 0 ? void 0 : m.data) || [];
|
|
233
|
+
if (isComplete_1 && isCompiled_1 && !isList_1) {
|
|
234
|
+
outList(list_1);
|
|
235
|
+
isList_1 = true;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
if (!((m === null || m === void 0 ? void 0 : m.type) === 'DonePlugin')) return [3 /*break*/, 2];
|
|
239
|
+
content = m === null || m === void 0 ? void 0 : m.data;
|
|
240
|
+
port_1 = content === null || content === void 0 ? void 0 : content.port;
|
|
241
|
+
time_1 = content === null || content === void 0 ? void 0 : content.time;
|
|
242
|
+
errors_1 = content === null || content === void 0 ? void 0 : content.errors;
|
|
243
|
+
warings_1 = content === null || content === void 0 ? void 0 : content.warings;
|
|
244
|
+
devServerOptions_1 = content === null || content === void 0 ? void 0 : content.devServerOptions;
|
|
245
|
+
if (!(isComplete_1 && isCompiled_1 && !isEnd_1)) return [3 /*break*/, 2];
|
|
246
|
+
return [4 /*yield*/, outResult({ time: time_1, port: port_1, errors: errors_1, warings: warings_1, opts: opts, devServerOptions: devServerOptions_1, isInit: isInit_1 })];
|
|
247
|
+
case 1:
|
|
248
|
+
_a.sent();
|
|
249
|
+
isEnd_1 = true;
|
|
250
|
+
isInit_1 = true;
|
|
251
|
+
resolve(true);
|
|
252
|
+
_a.label = 2;
|
|
253
|
+
case 2:
|
|
254
|
+
if (!((m === null || m === void 0 ? void 0 : m.type) === 'progress')) return [3 /*break*/, 4];
|
|
255
|
+
if (!isCompiled_1)
|
|
256
|
+
return [2 /*return*/];
|
|
257
|
+
bar1.update(Math.floor((m === null || m === void 0 ? void 0 : m.data) * 100));
|
|
258
|
+
if (!((m === null || m === void 0 ? void 0 : m.data) * 100 >= 100)) return [3 /*break*/, 4];
|
|
259
|
+
bar1.stop();
|
|
260
|
+
isComplete_1 = true;
|
|
261
|
+
if (!isList_1) {
|
|
262
|
+
outList(list_1);
|
|
263
|
+
isList_1 = true;
|
|
264
|
+
}
|
|
265
|
+
if (!!isEnd_1) return [3 /*break*/, 4];
|
|
266
|
+
return [4 /*yield*/, outResult({ time: time_1, port: port_1, errors: errors_1, warings: warings_1, opts: opts, devServerOptions: devServerOptions_1, isInit: isInit_1 })];
|
|
267
|
+
case 3:
|
|
268
|
+
_a.sent();
|
|
269
|
+
isEnd_1 = true;
|
|
270
|
+
isInit_1 = true;
|
|
271
|
+
resolve(true);
|
|
272
|
+
_a.label = 4;
|
|
273
|
+
case 4: return [2 /*return*/];
|
|
274
|
+
}
|
|
275
|
+
});
|
|
276
|
+
}); });
|
|
277
|
+
}
|
|
278
|
+
catch (err) {
|
|
279
|
+
reject(err);
|
|
280
|
+
}
|
|
281
|
+
})];
|
|
282
|
+
});
|
|
283
|
+
}); };
|
|
284
|
+
exports.default = fun;
|