@vectorx/cloud-toolkit 0.0.0-beta-20251112071234
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 +1 -0
- package/lib/agent.kit.js +275 -0
- package/lib/config/api.config.js +12 -0
- package/lib/config/index.js +17 -0
- package/lib/container/container.js +11 -0
- package/lib/container/identifiers.js +7 -0
- package/lib/container/index.js +31 -0
- package/lib/container/types.js +2 -0
- package/lib/index.js +30 -0
- package/lib/services/auth-service.js +148 -0
- package/lib/services/index.js +18 -0
- package/lib/services/upload-service.js +192 -0
- package/lib/utils/config-merger.js +54 -0
- package/lib/utils/cos-uploader.js +104 -0
- package/lib/utils/env-helper.js +4 -0
- package/lib/utils/helper.js +66 -0
- package/lib/utils/loading.js +68 -0
- package/lib/utils/logger.js +89 -0
- package/lib/utils/open-browser.js +24 -0
- package/lib/utils/openChrome.applescript +78 -0
- package/lib/utils/output.js +37 -0
- package/lib/utils/port-finder.js +55 -0
- package/lib/utils/project-validator.js +124 -0
- package/lib/utils/request.js +77 -0
- package/lib/utils/to-hump.js +5 -0
- package/lib/utils/tracker/device.js +85 -0
- package/lib/utils/tracker/index.js +134 -0
- package/lib/utils/tracker/tracker.js +2 -0
- package/package.json +55 -0
- package/types/agent.kit.d.ts +70 -0
- package/types/config/api.config.d.ts +2 -0
- package/types/config/index.d.ts +1 -0
- package/types/container/container.d.ts +3 -0
- package/types/container/identifiers.d.ts +6 -0
- package/types/container/index.d.ts +9 -0
- package/types/container/types.d.ts +19 -0
- package/types/index.d.ts +13 -0
- package/types/services/auth-service.d.ts +22 -0
- package/types/services/index.d.ts +2 -0
- package/types/services/upload-service.d.ts +95 -0
- package/types/utils/config-merger.d.ts +1 -0
- package/types/utils/cos-uploader.d.ts +41 -0
- package/types/utils/env-helper.d.ts +1 -0
- package/types/utils/helper.d.ts +6 -0
- package/types/utils/loading.d.ts +18 -0
- package/types/utils/logger.d.ts +24 -0
- package/types/utils/open-browser.d.ts +2 -0
- package/types/utils/output.d.ts +1 -0
- package/types/utils/port-finder.d.ts +2 -0
- package/types/utils/project-validator.d.ts +10 -0
- package/types/utils/request.d.ts +25 -0
- package/types/utils/to-hump.d.ts +1 -0
- package/types/utils/tracker/device.d.ts +4 -0
- package/types/utils/tracker/index.d.ts +27 -0
- package/types/utils/tracker/tracker.d.ts +22 -0
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
12
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
13
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
14
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
15
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
16
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
17
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
21
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
22
|
+
};
|
|
23
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
+
exports.UploadService = void 0;
|
|
25
|
+
const fs_1 = __importDefault(require("fs"));
|
|
26
|
+
const path_1 = __importDefault(require("path"));
|
|
27
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
28
|
+
const inversify_1 = require("inversify");
|
|
29
|
+
const config_1 = require("../config");
|
|
30
|
+
const container_1 = require("../container");
|
|
31
|
+
const cos_uploader_1 = require("../utils/cos-uploader");
|
|
32
|
+
const env_helper_1 = require("../utils/env-helper");
|
|
33
|
+
const logger_1 = require("../utils/logger");
|
|
34
|
+
const request_1 = require("../utils/request");
|
|
35
|
+
let UploadService = class UploadService {
|
|
36
|
+
constructor() {
|
|
37
|
+
this.authService = container_1.container.get(container_1.SERVICE_IDENTIFIERS.AuthService);
|
|
38
|
+
}
|
|
39
|
+
getCloudBaseSecretToken() {
|
|
40
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
41
|
+
if (env_helper_1.isIDE) {
|
|
42
|
+
return "";
|
|
43
|
+
}
|
|
44
|
+
const loginInfo = yield this.authService.getLoginInfo();
|
|
45
|
+
if (!loginInfo) {
|
|
46
|
+
throw new Error("未登录,请先登录");
|
|
47
|
+
}
|
|
48
|
+
return loginInfo.cli_token;
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
getToken() {
|
|
52
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
53
|
+
try {
|
|
54
|
+
let params = {};
|
|
55
|
+
if (!env_helper_1.isIDE) {
|
|
56
|
+
const loginInfo = yield this.authService.getLoginInfo();
|
|
57
|
+
if (!loginInfo) {
|
|
58
|
+
throw new Error("未登录,请先登录");
|
|
59
|
+
}
|
|
60
|
+
params = {
|
|
61
|
+
secret_id: loginInfo.secret_id,
|
|
62
|
+
cli_token: loginInfo.cli_token,
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
const response = yield request_1.request.fetch({
|
|
66
|
+
url: `${(0, config_1.getBaseUrl)()}/api/eros/mp/red/code/agent_pkg/upload/permit`,
|
|
67
|
+
headers: {
|
|
68
|
+
"Content-Type": "application/json",
|
|
69
|
+
},
|
|
70
|
+
method: "GET",
|
|
71
|
+
data: {
|
|
72
|
+
params,
|
|
73
|
+
},
|
|
74
|
+
});
|
|
75
|
+
if (response.data.code === 0) {
|
|
76
|
+
return response.data.data;
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
throw new Error(response.data.msg);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
catch (error) {
|
|
83
|
+
throw new Error(`获取上传Token失败: ${(error === null || error === void 0 ? void 0 : error.message) || error}`);
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
buildPreCheck(params) {
|
|
88
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
89
|
+
try {
|
|
90
|
+
let query = {};
|
|
91
|
+
if (!env_helper_1.isIDE) {
|
|
92
|
+
const loginInfo = yield this.authService.getLoginInfo();
|
|
93
|
+
if (!loginInfo) {
|
|
94
|
+
throw new Error("未登录,请先登录");
|
|
95
|
+
}
|
|
96
|
+
query = {
|
|
97
|
+
secret_id: loginInfo.secret_id,
|
|
98
|
+
cli_token: loginInfo.cli_token,
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
const res = yield request_1.request.fetch({
|
|
102
|
+
method: "POST",
|
|
103
|
+
url: `${(0, config_1.getBaseUrl)()}/api/eros/mp/red/code/agent_pkg/develop/upload_pre_check`,
|
|
104
|
+
headers: {},
|
|
105
|
+
data: {
|
|
106
|
+
query,
|
|
107
|
+
body: params,
|
|
108
|
+
},
|
|
109
|
+
});
|
|
110
|
+
return res.data;
|
|
111
|
+
}
|
|
112
|
+
catch (error) {
|
|
113
|
+
throw new Error(`上传预检失败: ${(error === null || error === void 0 ? void 0 : error.message) || error}`);
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
deploy(params) {
|
|
118
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
119
|
+
if (!env_helper_1.isIDE && !this.authService.hasLogin()) {
|
|
120
|
+
throw new Error("未登录,请先登录");
|
|
121
|
+
}
|
|
122
|
+
const uploader = new cos_uploader_1.Uploader({
|
|
123
|
+
bizName: "fe",
|
|
124
|
+
scene: "fe-platform",
|
|
125
|
+
getToken: () => this.getToken(),
|
|
126
|
+
});
|
|
127
|
+
const filePath = path_1.default.resolve(params.targetPath);
|
|
128
|
+
const file = fs_1.default.readFileSync(filePath);
|
|
129
|
+
const fileName = `miniapp-agent-${params.agentId}-${params.version}.zip`;
|
|
130
|
+
const stats = fs_1.default.statSync(filePath);
|
|
131
|
+
const response = yield uploader.post({
|
|
132
|
+
Body: file,
|
|
133
|
+
fileInfo: {
|
|
134
|
+
name: fileName,
|
|
135
|
+
type: "application/octet-stream",
|
|
136
|
+
size: stats.size,
|
|
137
|
+
},
|
|
138
|
+
FilePath: filePath,
|
|
139
|
+
});
|
|
140
|
+
logger_1.logger.breakLine();
|
|
141
|
+
logger_1.logger.info(chalk_1.default.green(`资源包上传成功: ${response.previewUrl}`));
|
|
142
|
+
if (response.previewUrl) {
|
|
143
|
+
const res = yield this.uploadAgentPackage({
|
|
144
|
+
agent_id: params.agentId,
|
|
145
|
+
version: params.version,
|
|
146
|
+
desc: params.desc,
|
|
147
|
+
file_url: response.previewUrl,
|
|
148
|
+
cloud_type: response.cloudType,
|
|
149
|
+
});
|
|
150
|
+
if (res.code !== 0) {
|
|
151
|
+
throw new Error(`[${res.code}] ${res.msg}`);
|
|
152
|
+
}
|
|
153
|
+
return res;
|
|
154
|
+
}
|
|
155
|
+
else {
|
|
156
|
+
throw new Error(".zip 文件服务上传失败");
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
uploadAgentPackage(params) {
|
|
161
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
162
|
+
let query = {};
|
|
163
|
+
if (!env_helper_1.isIDE) {
|
|
164
|
+
const loginInfo = yield this.authService.getLoginInfo();
|
|
165
|
+
if (!loginInfo) {
|
|
166
|
+
throw new Error("未登录,请先登录");
|
|
167
|
+
}
|
|
168
|
+
query = {
|
|
169
|
+
secret_id: loginInfo.secret_id,
|
|
170
|
+
cli_token: loginInfo.cli_token,
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
const res = yield request_1.request.fetch({
|
|
174
|
+
method: "POST",
|
|
175
|
+
url: `${(0, config_1.getBaseUrl)()}/api/eros/mp/red/code/agent_pkg/develop/upload`,
|
|
176
|
+
headers: {
|
|
177
|
+
"Content-Type": "application/json",
|
|
178
|
+
},
|
|
179
|
+
data: {
|
|
180
|
+
query,
|
|
181
|
+
body: params,
|
|
182
|
+
},
|
|
183
|
+
});
|
|
184
|
+
return res.data;
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
};
|
|
188
|
+
exports.UploadService = UploadService;
|
|
189
|
+
exports.UploadService = UploadService = __decorate([
|
|
190
|
+
(0, inversify_1.injectable)(),
|
|
191
|
+
__metadata("design:paramtypes", [])
|
|
192
|
+
], UploadService);
|
|
@@ -0,0 +1,54 @@
|
|
|
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.mergeProjectConfigs = mergeProjectConfigs;
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
function mergeProjectConfigs(workDir) {
|
|
10
|
+
const projectConfigPath = path_1.default.join(workDir, "project.config.json");
|
|
11
|
+
const agentConfigPath = path_1.default.join(workDir, "agent-cloudbase-functions.json");
|
|
12
|
+
if (!fs_1.default.existsSync(projectConfigPath)) {
|
|
13
|
+
throw new Error(`project.config.json 文件不存在: ${projectConfigPath}`);
|
|
14
|
+
}
|
|
15
|
+
if (!fs_1.default.existsSync(agentConfigPath)) {
|
|
16
|
+
throw new Error(`agent-cloudbase-functions.json 文件不存在: ${agentConfigPath}`);
|
|
17
|
+
}
|
|
18
|
+
try {
|
|
19
|
+
const projectConfigContent = fs_1.default.readFileSync(projectConfigPath, "utf8");
|
|
20
|
+
const agentConfigContent = fs_1.default.readFileSync(agentConfigPath, "utf8");
|
|
21
|
+
const projectConfig = JSON.parse(projectConfigContent);
|
|
22
|
+
const agentConfig = JSON.parse(agentConfigContent);
|
|
23
|
+
let hasChanges = false;
|
|
24
|
+
if (projectConfig.agentId && projectConfig.agentId !== agentConfig.agentId) {
|
|
25
|
+
agentConfig.agentId = projectConfig.agentId;
|
|
26
|
+
hasChanges = true;
|
|
27
|
+
}
|
|
28
|
+
if (projectConfig.version && projectConfig.version !== agentConfig.version) {
|
|
29
|
+
agentConfig.version = projectConfig.version;
|
|
30
|
+
hasChanges = true;
|
|
31
|
+
}
|
|
32
|
+
if (projectConfig.desc && projectConfig.desc !== agentConfig.desc) {
|
|
33
|
+
agentConfig.desc = projectConfig.desc;
|
|
34
|
+
hasChanges = true;
|
|
35
|
+
}
|
|
36
|
+
if (hasChanges) {
|
|
37
|
+
const updatedContent = JSON.stringify(agentConfig, null, 2);
|
|
38
|
+
fs_1.default.writeFileSync(agentConfigPath, updatedContent, "utf8");
|
|
39
|
+
console.log("✅ 配置文件合并完成,已更新 agent-cloudbase-functions.json");
|
|
40
|
+
if (projectConfig.agentId) {
|
|
41
|
+
console.log(` agentId: ${projectConfig.agentId}`);
|
|
42
|
+
}
|
|
43
|
+
if (projectConfig.version) {
|
|
44
|
+
console.log(` version: ${projectConfig.version}`);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
catch (error) {
|
|
49
|
+
if (error instanceof SyntaxError) {
|
|
50
|
+
throw new Error(`配置文件格式错误,请检查 JSON 格式是否正确: ${error.message}`);
|
|
51
|
+
}
|
|
52
|
+
throw new Error(`合并配置文件时发生错误: ${error.message}`);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
+
var t = {};
|
|
4
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
+
t[p] = s[p];
|
|
6
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
+
t[p[i]] = s[p[i]];
|
|
10
|
+
}
|
|
11
|
+
return t;
|
|
12
|
+
};
|
|
13
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.Uploader = void 0;
|
|
18
|
+
const cos_nodejs_sdk_v5_1 = __importDefault(require("cos-nodejs-sdk-v5"));
|
|
19
|
+
const to_hump_1 = require("./to-hump");
|
|
20
|
+
class Uploader {
|
|
21
|
+
constructor(args) {
|
|
22
|
+
this.bizName = args.bizName;
|
|
23
|
+
this.scene = args.scene;
|
|
24
|
+
this.getToken = args.getToken;
|
|
25
|
+
this.enableResume = args.enableResume;
|
|
26
|
+
}
|
|
27
|
+
getPermit(file, fileInfo, fileFormat, persistentOps, persistentNotifyUrl) {
|
|
28
|
+
return this.getToken().then(({ uploadTempPermits, uploadLimitPolicy }) => {
|
|
29
|
+
const fileType = fileInfo.type;
|
|
30
|
+
const fileSize = fileInfo.size;
|
|
31
|
+
if (uploadLimitPolicy) {
|
|
32
|
+
const { fileTypes, maxSize } = uploadLimitPolicy;
|
|
33
|
+
if ((fileTypes === null || fileTypes === void 0 ? void 0 : fileTypes.length) &&
|
|
34
|
+
!fileTypes.reduce((a, c) => [...a, ...c.split("/")], []).some((f) => fileType.endsWith(f))) {
|
|
35
|
+
throw new Error(`文件类型 ${fileType} 不在可上传的文件类型 ${fileTypes.join(", ")} 中。`);
|
|
36
|
+
}
|
|
37
|
+
if (maxSize !== undefined && fileSize > maxSize) {
|
|
38
|
+
throw new Error(`文件尺寸(${fileSize / (1024 * 1024)} mb)超过最大尺寸(${maxSize / (1024 * 1024)} mb)。`);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
if (!(uploadTempPermits === null || uploadTempPermits === void 0 ? void 0 : uploadTempPermits.length)) {
|
|
42
|
+
throw new Error("token 获取失败。");
|
|
43
|
+
}
|
|
44
|
+
const [permit] = uploadTempPermits.sort((a, b) => b.qos - a.qos);
|
|
45
|
+
return permit;
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
post(options) {
|
|
49
|
+
const startTime = Date.now();
|
|
50
|
+
const { fileFormat, onInstanceCreated } = options, rest = __rest(options, ["fileFormat", "onInstanceCreated"]);
|
|
51
|
+
return this.getPermit(options.Body, options.fileInfo, fileFormat)
|
|
52
|
+
.then((permit) => {
|
|
53
|
+
const [fileId] = permit.fileIds;
|
|
54
|
+
const cosInitParams = {
|
|
55
|
+
Domain: permit.uploadAddr,
|
|
56
|
+
getAuthorization(_, callback) {
|
|
57
|
+
callback({
|
|
58
|
+
TmpSecretId: permit.secretId || "null",
|
|
59
|
+
TmpSecretKey: permit.secretKey || "null",
|
|
60
|
+
SecurityToken: permit.token,
|
|
61
|
+
StartTime: Math.floor(startTime / 1000),
|
|
62
|
+
ExpiredTime: Math.floor(permit.expireTime / 1000),
|
|
63
|
+
});
|
|
64
|
+
},
|
|
65
|
+
};
|
|
66
|
+
if (permit.bucket === "unknown") {
|
|
67
|
+
cosInitParams.AppId = "1251524319";
|
|
68
|
+
}
|
|
69
|
+
const cos = new cos_nodejs_sdk_v5_1.default(cosInitParams);
|
|
70
|
+
if (onInstanceCreated) {
|
|
71
|
+
onInstanceCreated(cos);
|
|
72
|
+
}
|
|
73
|
+
return cos
|
|
74
|
+
.uploadFile(Object.assign({ Bucket: permit.bucket, Region: permit.region, Key: fileId }, rest))
|
|
75
|
+
.then((resp) => {
|
|
76
|
+
const payload = Object.assign(Object.assign({}, resp), { bizName: this.bizName, scene: this.scene, cloudType: permit.cloudType, fileId, sliceSize: rest.SliceSize || 1048576, isSlice: options.fileInfo.size > (rest.SliceSize || 1048576), tokenFail: false });
|
|
77
|
+
if (permit.cdnDomain) {
|
|
78
|
+
const cdnLink = `${permit.cdnDomain}/${fileId}`;
|
|
79
|
+
payload.cdnDomain = permit.cdnDomain;
|
|
80
|
+
payload.url = cdnLink;
|
|
81
|
+
payload.previewUrl = cdnLink;
|
|
82
|
+
payload.staticUrl = cdnLink;
|
|
83
|
+
}
|
|
84
|
+
if (resp === null || resp === void 0 ? void 0 : resp.headers) {
|
|
85
|
+
Object.keys(resp.headers).forEach((v) => {
|
|
86
|
+
var _a;
|
|
87
|
+
if (v.startsWith("x-ros-")) {
|
|
88
|
+
const key = (0, to_hump_1.toHump)(v.split("x-ros-")[1]);
|
|
89
|
+
payload[key] = (_a = resp.headers) === null || _a === void 0 ? void 0 : _a[v];
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
return payload;
|
|
94
|
+
})
|
|
95
|
+
.catch((e) => {
|
|
96
|
+
throw e;
|
|
97
|
+
});
|
|
98
|
+
})
|
|
99
|
+
.catch((e) => {
|
|
100
|
+
throw e;
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
exports.Uploader = Uploader;
|
|
@@ -0,0 +1,66 @@
|
|
|
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 __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.toHump = exports.getFixedFormatTime = void 0;
|
|
16
|
+
exports.getNonce = getNonce;
|
|
17
|
+
exports.getMd5 = getMd5;
|
|
18
|
+
exports.guid = guid;
|
|
19
|
+
exports.retry = retry;
|
|
20
|
+
const crypto_1 = __importDefault(require("crypto"));
|
|
21
|
+
const dayjs_1 = __importDefault(require("dayjs"));
|
|
22
|
+
const uuid_1 = require("uuid");
|
|
23
|
+
const getFixedFormatTime = (format, timeDistance = 0) => {
|
|
24
|
+
const current = (0, dayjs_1.default)();
|
|
25
|
+
const time = current.add(timeDistance, "millisecond").format(format);
|
|
26
|
+
return time;
|
|
27
|
+
};
|
|
28
|
+
exports.getFixedFormatTime = getFixedFormatTime;
|
|
29
|
+
function getNonce() {
|
|
30
|
+
return "xxxxxxxxxxxxxxxx".replace(/[xy]/g, (c) => {
|
|
31
|
+
const r = (Math.random() * 16) | 0;
|
|
32
|
+
const v = c === "x" ? r : (r & 0x3) | 0x8;
|
|
33
|
+
return v.toString(16);
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
function getMd5(str) {
|
|
37
|
+
const hash = crypto_1.default.createHash("md5");
|
|
38
|
+
hash.update(str);
|
|
39
|
+
const md5 = hash.digest("hex");
|
|
40
|
+
return md5;
|
|
41
|
+
}
|
|
42
|
+
function guid() {
|
|
43
|
+
return (0, uuid_1.v4)();
|
|
44
|
+
}
|
|
45
|
+
function retry(fn_1) {
|
|
46
|
+
return __awaiter(this, arguments, void 0, function* (fn, maxRetries = 5, delay = 0) {
|
|
47
|
+
let lastError;
|
|
48
|
+
for (let i = 0; i < maxRetries; i++) {
|
|
49
|
+
try {
|
|
50
|
+
if (delay > 0 && i > 0) {
|
|
51
|
+
yield new Promise((resolve) => setTimeout(resolve, delay));
|
|
52
|
+
}
|
|
53
|
+
return yield fn();
|
|
54
|
+
}
|
|
55
|
+
catch (error) {
|
|
56
|
+
lastError = error;
|
|
57
|
+
if (i === maxRetries - 1) {
|
|
58
|
+
throw lastError;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
throw lastError;
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
const toHump = (str) => str.replace(/\-(\w)/g, (letter) => letter[1].toUpperCase());
|
|
66
|
+
exports.toHump = toHump;
|
|
@@ -0,0 +1,68 @@
|
|
|
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 __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.execWithLoading = exports.loadingFactory = void 0;
|
|
16
|
+
const ora_1 = __importDefault(require("ora"));
|
|
17
|
+
class Loading {
|
|
18
|
+
constructor() {
|
|
19
|
+
process.on(EVENT.PROCESS_EXIT, this.stop.bind(this));
|
|
20
|
+
process.on(EVENT.PROCESS_ERROR, this.stop.bind(this));
|
|
21
|
+
this.spinner = (0, ora_1.default)({
|
|
22
|
+
discardStdin: false,
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
set text(text) {
|
|
26
|
+
this.spinner.text = text;
|
|
27
|
+
}
|
|
28
|
+
start(text) {
|
|
29
|
+
this.spinner = this.spinner.start(text);
|
|
30
|
+
}
|
|
31
|
+
stop() {
|
|
32
|
+
if (this.spinner) {
|
|
33
|
+
this.spinner = this.spinner.stop();
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
succeed(text) {
|
|
37
|
+
if (this.spinner) {
|
|
38
|
+
this.spinner = this.spinner.succeed(text);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
fail(text) {
|
|
42
|
+
if (this.spinner) {
|
|
43
|
+
this.spinner = this.spinner.fail(text);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
const loadingFactory = () => {
|
|
48
|
+
return new Loading();
|
|
49
|
+
};
|
|
50
|
+
exports.loadingFactory = loadingFactory;
|
|
51
|
+
const execWithLoading = (task_1, ...args_1) => __awaiter(void 0, [task_1, ...args_1], void 0, function* (task, options = {}) {
|
|
52
|
+
const { startTip, successTip, failTip } = options;
|
|
53
|
+
const loading = (0, exports.loadingFactory)();
|
|
54
|
+
const flush = (text) => {
|
|
55
|
+
loading.text = text;
|
|
56
|
+
};
|
|
57
|
+
try {
|
|
58
|
+
loading.start(startTip || "执行中...");
|
|
59
|
+
const res = yield task(flush);
|
|
60
|
+
successTip ? loading.succeed(successTip) : loading.stop();
|
|
61
|
+
return res;
|
|
62
|
+
}
|
|
63
|
+
catch (e) {
|
|
64
|
+
failTip ? loading.fail(failTip) : loading.stop();
|
|
65
|
+
throw e;
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
exports.execWithLoading = execWithLoading;
|
|
@@ -0,0 +1,89 @@
|
|
|
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 __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.logger = exports.Logger = void 0;
|
|
16
|
+
const console_1 = require("console");
|
|
17
|
+
const util_1 = require("util");
|
|
18
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
19
|
+
const log_symbols_1 = __importDefault(require("log-symbols"));
|
|
20
|
+
const ora_1 = __importDefault(require("ora"));
|
|
21
|
+
const terminal_link_1 = __importDefault(require("terminal-link"));
|
|
22
|
+
class Logger {
|
|
23
|
+
constructor(options = {}) {
|
|
24
|
+
this.c = {
|
|
25
|
+
_times: new Map(),
|
|
26
|
+
log(a, ...args) {
|
|
27
|
+
this.debug((0, util_1.format)(a, ...args));
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
const { verbose } = options;
|
|
31
|
+
this.verboseEnabled = verbose || false;
|
|
32
|
+
}
|
|
33
|
+
breakLine() {
|
|
34
|
+
console.log();
|
|
35
|
+
}
|
|
36
|
+
log(...args) {
|
|
37
|
+
console.log(`▶️ ${chalk_1.default.gray(`[${new Date().toLocaleString()}]`)} ${args.join(" ")}`);
|
|
38
|
+
}
|
|
39
|
+
info(msg) {
|
|
40
|
+
console.log(`▶️ ${chalk_1.default.gray(`[${new Date().toLocaleString()}]`)} ${log_symbols_1.default.info} ${msg}`);
|
|
41
|
+
}
|
|
42
|
+
success(msg) {
|
|
43
|
+
console.log(`▶️ ${chalk_1.default.gray(`[${new Date().toLocaleString()}]`)}${log_symbols_1.default.success} ${msg}`);
|
|
44
|
+
}
|
|
45
|
+
warn(msg) {
|
|
46
|
+
console.log(`▶️ ${chalk_1.default.gray(`[${new Date().toLocaleString()}]`)}${log_symbols_1.default.warning} ${msg}`);
|
|
47
|
+
}
|
|
48
|
+
error(msg) {
|
|
49
|
+
console.log(`▶️ ${chalk_1.default.red(`[${new Date().toLocaleString()}]`)}${log_symbols_1.default.error} ${msg}`);
|
|
50
|
+
}
|
|
51
|
+
verbose(...args) {
|
|
52
|
+
if (this.verboseEnabled) {
|
|
53
|
+
const msg = args.join(" ▶️ ");
|
|
54
|
+
console.log(`${chalk_1.default.bold("[debug]")} ${chalk_1.default.gray(`[${new Date().toLocaleString()}]`)} ${msg}`);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
debug(...args) {
|
|
58
|
+
return this.verbose(...args);
|
|
59
|
+
}
|
|
60
|
+
genClickableLink(link) {
|
|
61
|
+
if (terminal_link_1.default.isSupported) {
|
|
62
|
+
const clickablelink = (0, terminal_link_1.default)(link, link);
|
|
63
|
+
return chalk_1.default.bold.cyan(clickablelink);
|
|
64
|
+
}
|
|
65
|
+
return chalk_1.default.bold.underline.cyan(link);
|
|
66
|
+
}
|
|
67
|
+
printClickableLink(link) {
|
|
68
|
+
const clickLink = this.genClickableLink(link);
|
|
69
|
+
this.info(clickLink);
|
|
70
|
+
}
|
|
71
|
+
time(label, fn) {
|
|
72
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
73
|
+
const promise = typeof fn === "function" ? fn() : fn;
|
|
74
|
+
if (this.verboseEnabled) {
|
|
75
|
+
this.c.log(label);
|
|
76
|
+
console_1.Console.prototype.time.call(this.c, label);
|
|
77
|
+
const r = yield promise;
|
|
78
|
+
console_1.Console.prototype.timeEnd.call(this.c, label);
|
|
79
|
+
return r;
|
|
80
|
+
}
|
|
81
|
+
return promise;
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
spinner(text, color = "cyan") {
|
|
85
|
+
return (0, ora_1.default)({ text, color }).start();
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
exports.Logger = Logger;
|
|
89
|
+
exports.logger = new Logger();
|
|
@@ -0,0 +1,24 @@
|
|
|
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.openBrowser = void 0;
|
|
7
|
+
const child_process_1 = require("child_process");
|
|
8
|
+
const open_1 = __importDefault(require("open"));
|
|
9
|
+
const openBrowser = (host, port) => {
|
|
10
|
+
const url = `http://${host}:${port}`;
|
|
11
|
+
try {
|
|
12
|
+
(0, child_process_1.execSync)(`osascript ${__dirname}/openChrome.applescript ${encodeURI(url)}`, {
|
|
13
|
+
stdio: "ignore",
|
|
14
|
+
});
|
|
15
|
+
return true;
|
|
16
|
+
}
|
|
17
|
+
catch (error) {
|
|
18
|
+
console.log("error", error);
|
|
19
|
+
(0, open_1.default)(url, {
|
|
20
|
+
app: ["google chrome", "--new-window", "--app", "--disable-extensions", "--disable-popup-blocking"],
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
exports.openBrowser = openBrowser;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
property targetTab: null
|
|
2
|
+
property targetTabIndex: -1
|
|
3
|
+
property targetWindow: null
|
|
4
|
+
|
|
5
|
+
on run argv
|
|
6
|
+
set theURL to item 1 of argv
|
|
7
|
+
|
|
8
|
+
with timeout of 2 seconds
|
|
9
|
+
tell application "Chrome"
|
|
10
|
+
|
|
11
|
+
if (count every window) = 0 then
|
|
12
|
+
make new window
|
|
13
|
+
end if
|
|
14
|
+
|
|
15
|
+
-- 1: Looking for tab running debugger
|
|
16
|
+
-- then, Reload debugging tab if found
|
|
17
|
+
-- then return
|
|
18
|
+
set found to my lookupTabWithUrl(theURL)
|
|
19
|
+
if found then
|
|
20
|
+
set targetWindow's active tab index to targetTabIndex
|
|
21
|
+
tell targetTab to reload
|
|
22
|
+
tell targetWindow to activate
|
|
23
|
+
set index of targetWindow to 1
|
|
24
|
+
return
|
|
25
|
+
end if
|
|
26
|
+
|
|
27
|
+
-- 2: Looking for Empty tab
|
|
28
|
+
-- In case debugging tab was not found
|
|
29
|
+
-- We try to find an empty tab instead
|
|
30
|
+
set found to my lookupTabWithUrl("chrome://newtab/")
|
|
31
|
+
if found then
|
|
32
|
+
set targetWindow's active tab index to targetTabIndex
|
|
33
|
+
set URL of targetTab to theURL
|
|
34
|
+
tell targetWindow to activate
|
|
35
|
+
return
|
|
36
|
+
end if
|
|
37
|
+
|
|
38
|
+
-- 3: Create new tab
|
|
39
|
+
-- both debugging and empty tab were not found
|
|
40
|
+
-- make a new tab with url
|
|
41
|
+
tell window 1
|
|
42
|
+
activate
|
|
43
|
+
make new tab with properties {URL:theURL}
|
|
44
|
+
end tell
|
|
45
|
+
end tell
|
|
46
|
+
end timeout
|
|
47
|
+
end run
|
|
48
|
+
|
|
49
|
+
-- Function:
|
|
50
|
+
-- Lookup tab with given url
|
|
51
|
+
-- if found, store tab, index, and window in properties
|
|
52
|
+
-- (properties were declared on top of file)
|
|
53
|
+
on lookupTabWithUrl(lookupUrl)
|
|
54
|
+
tell application "Chrome"
|
|
55
|
+
-- Find a tab with the given url
|
|
56
|
+
set found to false
|
|
57
|
+
set theTabIndex to -1
|
|
58
|
+
repeat with theWindow in every window
|
|
59
|
+
set theTabIndex to 0
|
|
60
|
+
repeat with theTab in every tab of theWindow
|
|
61
|
+
set theTabIndex to theTabIndex + 1
|
|
62
|
+
if (theTab's URL as string) contains lookupUrl then
|
|
63
|
+
-- assign tab, tab index, and window to properties
|
|
64
|
+
set targetTab to theTab
|
|
65
|
+
set targetTabIndex to theTabIndex
|
|
66
|
+
set targetWindow to theWindow
|
|
67
|
+
set found to true
|
|
68
|
+
exit repeat
|
|
69
|
+
end if
|
|
70
|
+
end repeat
|
|
71
|
+
|
|
72
|
+
if found then
|
|
73
|
+
exit repeat
|
|
74
|
+
end if
|
|
75
|
+
end repeat
|
|
76
|
+
end tell
|
|
77
|
+
return found
|
|
78
|
+
end lookupTabWithUrl
|