@workclaw/cli 1.0.25 → 1.0.27
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.
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import * as fsSync from "node:fs";
|
|
2
1
|
import { readFileSync } from "node:fs";
|
|
3
2
|
import path, { resolve, dirname } from "node:path";
|
|
4
3
|
import process$1 from "node:process";
|
|
@@ -4138,74 +4137,6 @@ class LocalInstaller {
|
|
|
4138
4137
|
}
|
|
4139
4138
|
debugLog("[验证配置] 配置验证通过");
|
|
4140
4139
|
}
|
|
4141
|
-
async installDependencies(targetPath) {
|
|
4142
|
-
this.spinner.prefixText = this.prefixText;
|
|
4143
|
-
this.spinner.text = `${chalk.cyan("安装依赖")} ${chalk.dim("→")} ${chalk.yellow("正在安装...")}`;
|
|
4144
|
-
const checkDependencies = () => {
|
|
4145
|
-
try {
|
|
4146
|
-
const nodeModulesPath = path.join(targetPath, "node_modules");
|
|
4147
|
-
const packageJsonPath = path.join(targetPath, "package.json");
|
|
4148
|
-
try {
|
|
4149
|
-
fsSync.accessSync(nodeModulesPath);
|
|
4150
|
-
} catch {
|
|
4151
|
-
return false;
|
|
4152
|
-
}
|
|
4153
|
-
const packageJson = JSON.parse(fsSync.readFileSync(packageJsonPath, "utf-8"));
|
|
4154
|
-
const dependencies = Object.keys(packageJson.dependencies || {});
|
|
4155
|
-
for (const dep of dependencies) {
|
|
4156
|
-
const depPath = path.join(nodeModulesPath, dep);
|
|
4157
|
-
if (!fsSync.existsSync(depPath)) {
|
|
4158
|
-
debugLog(`[依赖检查] 缺少依赖: ${dep}`);
|
|
4159
|
-
return false;
|
|
4160
|
-
}
|
|
4161
|
-
}
|
|
4162
|
-
return true;
|
|
4163
|
-
} catch {
|
|
4164
|
-
return false;
|
|
4165
|
-
}
|
|
4166
|
-
};
|
|
4167
|
-
const runInstall = () => {
|
|
4168
|
-
try {
|
|
4169
|
-
debugLog("[安装依赖] 执行 npm install");
|
|
4170
|
-
execSync("npm install --production", {
|
|
4171
|
-
cwd: targetPath,
|
|
4172
|
-
stdio: "pipe",
|
|
4173
|
-
timeout: 12e4
|
|
4174
|
-
});
|
|
4175
|
-
debugLog("[安装依赖] npm install 执行成功");
|
|
4176
|
-
return true;
|
|
4177
|
-
} catch (error) {
|
|
4178
|
-
const errorMsg = error.stderr?.toString() || error.message || "未知错误";
|
|
4179
|
-
debugLog(`[安装依赖] npm install 失败: ${errorMsg}`);
|
|
4180
|
-
return false;
|
|
4181
|
-
}
|
|
4182
|
-
};
|
|
4183
|
-
if (checkDependencies()) {
|
|
4184
|
-
debugLog("[安装依赖] 依赖检查通过");
|
|
4185
|
-
this.prefixText += chalk.green(`✓ 依赖检查通过
|
|
4186
|
-
`);
|
|
4187
|
-
return;
|
|
4188
|
-
}
|
|
4189
|
-
debugLog("[安装依赖] 依赖检查失败,尝试重新安装...");
|
|
4190
|
-
if (runInstall()) {
|
|
4191
|
-
if (checkDependencies()) {
|
|
4192
|
-
this.prefixText += chalk.green(`✓ 依赖安装成功
|
|
4193
|
-
`);
|
|
4194
|
-
return;
|
|
4195
|
-
}
|
|
4196
|
-
}
|
|
4197
|
-
debugLog("[安装依赖] 第一次安装失败,尝试完整安装...");
|
|
4198
|
-
if (runInstall()) {
|
|
4199
|
-
if (checkDependencies()) {
|
|
4200
|
-
this.prefixText += chalk.green(`✓ 依赖安装成功
|
|
4201
|
-
`);
|
|
4202
|
-
return;
|
|
4203
|
-
}
|
|
4204
|
-
}
|
|
4205
|
-
this.prefixText += chalk.red(`✗ 依赖安装失败
|
|
4206
|
-
`);
|
|
4207
|
-
throw new AppError$1(ERROR_CODES$1.NPM_INSTALL_FAILED, "插件依赖安装失败,请检查网络和 npm 配置");
|
|
4208
|
-
}
|
|
4209
4140
|
async install() {
|
|
4210
4141
|
try {
|
|
4211
4142
|
debugLog("[安装开始]");
|
|
@@ -4226,8 +4157,8 @@ class LocalInstaller {
|
|
|
4226
4157
|
debugLog(`[路径配置] target=${paths.target}`);
|
|
4227
4158
|
debugLog(`[路径配置] config=${paths.config}`);
|
|
4228
4159
|
debugLog(`[路径配置] workspace=${paths.workspace}`);
|
|
4229
|
-
await this.doLogin(env);
|
|
4230
|
-
const boundConfig = await this.doFetchBoundConfig(env);
|
|
4160
|
+
const token = await this.doLogin(env);
|
|
4161
|
+
const boundConfig = await this.doFetchBoundConfig(env, token);
|
|
4231
4162
|
await this.doCleanOldFiles(paths.target);
|
|
4232
4163
|
await this.doDownloadFromNpm(paths);
|
|
4233
4164
|
await this.doUpdateConfig(paths, boundConfig, env);
|
|
@@ -4251,16 +4182,15 @@ class LocalInstaller {
|
|
|
4251
4182
|
}
|
|
4252
4183
|
debugLog("[用户登录] 密码加密成功");
|
|
4253
4184
|
debugLog("[用户登录] 调用登录接口...");
|
|
4254
|
-
await login(this.config.phone, encryptedPassword, env);
|
|
4185
|
+
const token = await login(this.config.phone, encryptedPassword, env);
|
|
4255
4186
|
this.prefixText += chalk.green(`✓ 用户登录成功
|
|
4256
4187
|
`);
|
|
4257
4188
|
debugLog("[用户登录] 登录成功");
|
|
4189
|
+
return token;
|
|
4258
4190
|
}
|
|
4259
|
-
async doFetchBoundConfig(env) {
|
|
4191
|
+
async doFetchBoundConfig(env, token) {
|
|
4260
4192
|
this.spinner.prefixText = this.prefixText;
|
|
4261
4193
|
this.spinner.text = `${chalk.cyan("获取配置")} ${chalk.dim("→")} ${chalk.yellow("正在获取绑定配置...")}`;
|
|
4262
|
-
debugLog("[获取配置] 获取 token...");
|
|
4263
|
-
const token = await login(this.config.phone, rsaEncrypt(this.config.userPass), env);
|
|
4264
4194
|
debugLog("[获取配置] 调用绑定配置接口...");
|
|
4265
4195
|
const boundConfig = await fetchBoundConfig(token, this.config.phone, env);
|
|
4266
4196
|
debugLog(`[获取配置] agentId=${boundConfig.agentId}, appKey=${boundConfig.appKey?.slice(0, 8)}...`);
|
|
@@ -4350,7 +4280,26 @@ class LocalInstaller {
|
|
|
4350
4280
|
throw new AppError$1(ERROR_CODES$1.NPM_INSTALL_FAILED, "插件解压后未找到 package.json");
|
|
4351
4281
|
}
|
|
4352
4282
|
debugLog("[下载插件] 插件解压成功");
|
|
4353
|
-
|
|
4283
|
+
this.spinner.prefixText = this.prefixText;
|
|
4284
|
+
this.spinner.text = `${chalk.cyan("下载插件")} ${chalk.dim("→")} ${chalk.yellow("安装依赖")}`;
|
|
4285
|
+
debugLog("[下载插件] 执行 npm install 安装生产环境依赖");
|
|
4286
|
+
try {
|
|
4287
|
+
execSync("npm install --omit=dev --ignore-scripts", {
|
|
4288
|
+
cwd: paths.target,
|
|
4289
|
+
stdio: "pipe",
|
|
4290
|
+
timeout: 12e4
|
|
4291
|
+
});
|
|
4292
|
+
debugLog("[下载插件] npm install 执行成功");
|
|
4293
|
+
} catch (error) {
|
|
4294
|
+
const stderr = error.stderr?.toString() || "";
|
|
4295
|
+
const stdout = error.stdout?.toString() || "";
|
|
4296
|
+
const combinedOutput = stderr + stdout;
|
|
4297
|
+
if (combinedOutput.includes("npm warn") || combinedOutput.includes("deprecated")) {
|
|
4298
|
+
debugLog("[下载插件] npm install 有警告但可能成功,继续流程");
|
|
4299
|
+
} else {
|
|
4300
|
+
debugLog(`[下载插件] npm install 失败: ${combinedOutput}`);
|
|
4301
|
+
}
|
|
4302
|
+
}
|
|
4354
4303
|
this.prefixText += chalk.green(`✓ 插件下载完成
|
|
4355
4304
|
`);
|
|
4356
4305
|
try {
|
|
@@ -4527,14 +4476,9 @@ class LocalInstaller {
|
|
|
4527
4476
|
allowInsecureTls: true,
|
|
4528
4477
|
// 允许原始 JSON 载荷
|
|
4529
4478
|
allowRawJsonPayload: true,
|
|
4530
|
-
// 用户 ID
|
|
4531
|
-
userId: boundConfig.userId,
|
|
4532
4479
|
accounts: {
|
|
4533
4480
|
// 账户配置(agentId 从服务器获取)
|
|
4534
|
-
default: {
|
|
4535
|
-
enabled: true,
|
|
4536
|
-
agentId: boundConfig.agentId
|
|
4537
|
-
}
|
|
4481
|
+
default: { enabled: true, agentId: boundConfig.agentId }
|
|
4538
4482
|
}
|
|
4539
4483
|
}
|
|
4540
4484
|
},
|
|
@@ -4609,7 +4553,6 @@ class LocalInstaller {
|
|
|
4609
4553
|
installPath: paths.target
|
|
4610
4554
|
}
|
|
4611
4555
|
},
|
|
4612
|
-
// 插件加载路径(本地开发或自定义安装位置)
|
|
4613
4556
|
load: {
|
|
4614
4557
|
paths: [paths.target]
|
|
4615
4558
|
},
|
|
@@ -4832,74 +4775,6 @@ class BoxInstaller {
|
|
|
4832
4775
|
}
|
|
4833
4776
|
debugLog("[验证配置] 配置检查通过");
|
|
4834
4777
|
}
|
|
4835
|
-
async installDependencies(targetPath) {
|
|
4836
|
-
this.spinner.prefixText = this.prefixText;
|
|
4837
|
-
this.spinner.text = `${chalk.cyan("安装依赖")} ${chalk.dim("→")} ${chalk.yellow("正在安装...")}`;
|
|
4838
|
-
const checkDependencies = () => {
|
|
4839
|
-
try {
|
|
4840
|
-
const nodeModulesPath = path.join(targetPath, "node_modules");
|
|
4841
|
-
const packageJsonPath = path.join(targetPath, "package.json");
|
|
4842
|
-
try {
|
|
4843
|
-
fsSync.accessSync(nodeModulesPath);
|
|
4844
|
-
} catch {
|
|
4845
|
-
return false;
|
|
4846
|
-
}
|
|
4847
|
-
const packageJson = JSON.parse(fsSync.readFileSync(packageJsonPath, "utf-8"));
|
|
4848
|
-
const dependencies = Object.keys(packageJson.dependencies || {});
|
|
4849
|
-
for (const dep of dependencies) {
|
|
4850
|
-
const depPath = path.join(nodeModulesPath, dep);
|
|
4851
|
-
if (!fsSync.existsSync(depPath)) {
|
|
4852
|
-
debugLog(`[依赖检查] 缺少依赖: ${dep}`);
|
|
4853
|
-
return false;
|
|
4854
|
-
}
|
|
4855
|
-
}
|
|
4856
|
-
return true;
|
|
4857
|
-
} catch {
|
|
4858
|
-
return false;
|
|
4859
|
-
}
|
|
4860
|
-
};
|
|
4861
|
-
const runInstall = () => {
|
|
4862
|
-
try {
|
|
4863
|
-
debugLog("[安装依赖] 执行 npm install");
|
|
4864
|
-
execSync("npm install --production", {
|
|
4865
|
-
cwd: targetPath,
|
|
4866
|
-
stdio: "pipe",
|
|
4867
|
-
timeout: 12e4
|
|
4868
|
-
});
|
|
4869
|
-
debugLog("[安装依赖] npm install 执行成功");
|
|
4870
|
-
return true;
|
|
4871
|
-
} catch (error) {
|
|
4872
|
-
const errorMsg = error.stderr?.toString() || error.message || "未知错误";
|
|
4873
|
-
debugLog(`[安装依赖] npm install 失败: ${errorMsg}`);
|
|
4874
|
-
return false;
|
|
4875
|
-
}
|
|
4876
|
-
};
|
|
4877
|
-
if (checkDependencies()) {
|
|
4878
|
-
debugLog("[安装依赖] 依赖检查通过");
|
|
4879
|
-
this.prefixText += chalk.green(`✓ 依赖检查通过
|
|
4880
|
-
`);
|
|
4881
|
-
return;
|
|
4882
|
-
}
|
|
4883
|
-
debugLog("[安装依赖] 依赖检查失败,尝试重新安装...");
|
|
4884
|
-
if (runInstall()) {
|
|
4885
|
-
if (checkDependencies()) {
|
|
4886
|
-
this.prefixText += chalk.green(`✓ 依赖安装成功
|
|
4887
|
-
`);
|
|
4888
|
-
return;
|
|
4889
|
-
}
|
|
4890
|
-
}
|
|
4891
|
-
debugLog("[安装依赖] 第一次安装失败,尝试完整安装...");
|
|
4892
|
-
if (runInstall()) {
|
|
4893
|
-
if (checkDependencies()) {
|
|
4894
|
-
this.prefixText += chalk.green(`✓ 依赖安装成功
|
|
4895
|
-
`);
|
|
4896
|
-
return;
|
|
4897
|
-
}
|
|
4898
|
-
}
|
|
4899
|
-
this.prefixText += chalk.red(`✗ 依赖安装失败
|
|
4900
|
-
`);
|
|
4901
|
-
throw new AppError2(ERROR_CODES.NPM_INSTALL_FAILED, "插件依赖安装失败,请检查网络和 npm 配置");
|
|
4902
|
-
}
|
|
4903
4778
|
getPaths() {
|
|
4904
4779
|
const home = getHomeDir();
|
|
4905
4780
|
const openclawDir = path.join(home, ".openclaw");
|
|
@@ -5023,7 +4898,30 @@ class BoxInstaller {
|
|
|
5023
4898
|
debugLog(`[解压插件] 插件解压成功: ${paths.target}`);
|
|
5024
4899
|
this.prefixText += chalk.green(`✓ 插件解压成功
|
|
5025
4900
|
`);
|
|
5026
|
-
|
|
4901
|
+
this.spinner.prefixText = this.prefixText;
|
|
4902
|
+
this.spinner.text = `${chalk.cyan("安装依赖")} ${chalk.dim("→")} ${chalk.yellow("正在安装...")}`;
|
|
4903
|
+
debugLog("[安装依赖] 执行 npm install 安装生产环境依赖");
|
|
4904
|
+
try {
|
|
4905
|
+
execSync("npm install --omit=dev --ignore-scripts", {
|
|
4906
|
+
cwd: paths.target,
|
|
4907
|
+
stdio: "pipe",
|
|
4908
|
+
timeout: 12e4
|
|
4909
|
+
});
|
|
4910
|
+
debugLog("[安装依赖] npm install 执行成功");
|
|
4911
|
+
this.prefixText += chalk.green(`✓ 依赖安装成功
|
|
4912
|
+
`);
|
|
4913
|
+
} catch (error) {
|
|
4914
|
+
const stderr = error.stderr?.toString() || "";
|
|
4915
|
+
const stdout = error.stdout?.toString() || "";
|
|
4916
|
+
const combinedOutput = stderr + stdout;
|
|
4917
|
+
if (combinedOutput.includes("npm warn") || combinedOutput.includes("deprecated")) {
|
|
4918
|
+
debugLog("[安装依赖] npm install 有警告但可能成功,继续流程");
|
|
4919
|
+
this.prefixText += chalk.green(`✓ 依赖安装完成
|
|
4920
|
+
`);
|
|
4921
|
+
} else {
|
|
4922
|
+
debugLog(`[安装依赖] npm install 失败: ${combinedOutput}`);
|
|
4923
|
+
}
|
|
4924
|
+
}
|
|
5027
4925
|
await fs.rm(paths.temp, { recursive: true, force: true });
|
|
5028
4926
|
debugLog(`[解压插件] 清理临时文件成功`);
|
|
5029
4927
|
this.prefixText += chalk.green(`✓ 清理临时文件成功
|
package/dist/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@workclaw/cli",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.27",
|
|
5
5
|
"description": "WorkClaw CLI 工具 - 用于初始化和配置 WorkClaw 插件",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"keywords": [
|
|
@@ -38,4 +38,4 @@
|
|
|
38
38
|
"semver": "^7.7.1",
|
|
39
39
|
"tar": "^7.4.0"
|
|
40
40
|
}
|
|
41
|
-
}
|
|
41
|
+
}
|