@zrhsh/wukong-cli 0.4.27 → 0.4.29
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 +16 -0
- package/dist/cli.js +165 -66
- package/dist/cli.js.map +1 -1
- package/package.json +13 -1
package/LICENSE
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
Copyright (c) 2026 武汉壹品慧生活技术有限公司. All rights reserved.
|
|
2
|
+
|
|
3
|
+
本软件为武汉壹品慧生活技术有限公司(以下简称"公司")的专有资产,
|
|
4
|
+
仅限公司内部授权人员在公司业务范围内使用。
|
|
5
|
+
|
|
6
|
+
未经公司书面许可,任何单位和个人不得:
|
|
7
|
+
|
|
8
|
+
1. 复制、传播、分发本软件或其任何部分;
|
|
9
|
+
2. 修改、改编、翻译本软件;
|
|
10
|
+
3. 将本软件用于公司业务范围之外的任何用途;
|
|
11
|
+
4. 对本软件进行反向工程、反编译或反汇编。
|
|
12
|
+
|
|
13
|
+
本软件按"现状"提供,不附带任何明示或暗示的担保。
|
|
14
|
+
|
|
15
|
+
This software is proprietary and confidential.
|
|
16
|
+
Unauthorized copying, distribution, modification, or use is strictly prohibited.
|
package/dist/cli.js
CHANGED
|
@@ -256,8 +256,7 @@ function loadConfig() {
|
|
|
256
256
|
}
|
|
257
257
|
try {
|
|
258
258
|
const content = readFileSync2(configPath, "utf-8");
|
|
259
|
-
|
|
260
|
-
return config;
|
|
259
|
+
return JSON.parse(content);
|
|
261
260
|
} catch (error2) {
|
|
262
261
|
console.warn(`Warning: Failed to load config from ${configPath}: ${error2}`);
|
|
263
262
|
return {};
|
|
@@ -298,22 +297,6 @@ function getMergedEnvironmentConfig(env) {
|
|
|
298
297
|
}
|
|
299
298
|
return defaultEnvConfig;
|
|
300
299
|
}
|
|
301
|
-
function getAllEnvironments() {
|
|
302
|
-
const config = loadConfig();
|
|
303
|
-
const result = { ...ENVIRONMENTS };
|
|
304
|
-
if (config.customEnvironments) {
|
|
305
|
-
for (const [name, customEnv] of Object.entries(config.customEnvironments)) {
|
|
306
|
-
result[name] = {
|
|
307
|
-
name,
|
|
308
|
-
displayName: customEnv.displayName || name,
|
|
309
|
-
authBaseUrl: customEnv.authBaseUrl,
|
|
310
|
-
apiBaseUrl: customEnv.apiBaseUrl,
|
|
311
|
-
clientId: customEnv.clientId
|
|
312
|
-
};
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
return result;
|
|
316
|
-
}
|
|
317
300
|
function getDefaultEnvironment() {
|
|
318
301
|
const envFromVar = process.env.WUKONG_CLI_ENV;
|
|
319
302
|
if (envFromVar && isValidEnvironment(envFromVar)) {
|
|
@@ -568,7 +551,7 @@ var init_ora_ui_callbacks = __esm({
|
|
|
568
551
|
});
|
|
569
552
|
|
|
570
553
|
// src/core/auth/keytar-adapter.ts
|
|
571
|
-
import { createRequire } from "module";
|
|
554
|
+
import { createRequire as createRequire2 } from "module";
|
|
572
555
|
function isKeytarAvailable() {
|
|
573
556
|
return keytarModule !== null;
|
|
574
557
|
}
|
|
@@ -590,15 +573,15 @@ async function deletePassword(service, account) {
|
|
|
590
573
|
}
|
|
591
574
|
return await keytarModule.deletePassword(service, account);
|
|
592
575
|
}
|
|
593
|
-
var
|
|
576
|
+
var require3, keytarModule;
|
|
594
577
|
var init_keytar_adapter = __esm({
|
|
595
578
|
"src/core/auth/keytar-adapter.ts"() {
|
|
596
579
|
"use strict";
|
|
597
580
|
init_esm_shims();
|
|
598
|
-
|
|
581
|
+
require3 = createRequire2(import.meta.url);
|
|
599
582
|
keytarModule = null;
|
|
600
583
|
try {
|
|
601
|
-
keytarModule =
|
|
584
|
+
keytarModule = require3("keytar");
|
|
602
585
|
} catch (error2) {
|
|
603
586
|
keytarModule = null;
|
|
604
587
|
}
|
|
@@ -795,9 +778,18 @@ var init_token_cache = __esm({
|
|
|
795
778
|
|
|
796
779
|
// src/cli.ts
|
|
797
780
|
init_esm_shims();
|
|
798
|
-
init_debug();
|
|
799
781
|
import { Command as Command6 } from "commander";
|
|
800
782
|
|
|
783
|
+
// src/version.ts
|
|
784
|
+
init_esm_shims();
|
|
785
|
+
import { createRequire } from "module";
|
|
786
|
+
var require2 = createRequire(import.meta.url);
|
|
787
|
+
var pkg = require2("../package.json");
|
|
788
|
+
var CLI_VERSION = pkg.version;
|
|
789
|
+
|
|
790
|
+
// src/cli.ts
|
|
791
|
+
init_debug();
|
|
792
|
+
|
|
801
793
|
// src/utils/version/index.ts
|
|
802
794
|
init_esm_shims();
|
|
803
795
|
|
|
@@ -809,6 +801,7 @@ init_esm_shims();
|
|
|
809
801
|
var VersionCache = class {
|
|
810
802
|
lastCheckTime = 0;
|
|
811
803
|
cachedVersion = null;
|
|
804
|
+
cachedHighlights = [];
|
|
812
805
|
checkInterval;
|
|
813
806
|
/**
|
|
814
807
|
* Constructor
|
|
@@ -832,17 +825,27 @@ var VersionCache = class {
|
|
|
832
825
|
}
|
|
833
826
|
/**
|
|
834
827
|
* Set cached version with timestamp
|
|
828
|
+
*
|
|
829
|
+
* @param highlights 该版本的更新要点,缺省为空数组
|
|
835
830
|
*/
|
|
836
|
-
set(version) {
|
|
831
|
+
set(version, highlights = []) {
|
|
837
832
|
this.cachedVersion = version;
|
|
833
|
+
this.cachedHighlights = highlights;
|
|
838
834
|
this.lastCheckTime = Date.now();
|
|
839
835
|
}
|
|
836
|
+
/**
|
|
837
|
+
* Get cached highlights
|
|
838
|
+
*/
|
|
839
|
+
getHighlights() {
|
|
840
|
+
return this.cachedHighlights;
|
|
841
|
+
}
|
|
840
842
|
/**
|
|
841
843
|
* Clear cache
|
|
842
844
|
*/
|
|
843
845
|
clear() {
|
|
844
846
|
this.lastCheckTime = 0;
|
|
845
847
|
this.cachedVersion = null;
|
|
848
|
+
this.cachedHighlights = [];
|
|
846
849
|
}
|
|
847
850
|
/**
|
|
848
851
|
* Get time since last check
|
|
@@ -861,6 +864,10 @@ var VersionCache = class {
|
|
|
861
864
|
get version() {
|
|
862
865
|
return this.cachedVersion;
|
|
863
866
|
}
|
|
867
|
+
/** Cached highlights */
|
|
868
|
+
get highlights() {
|
|
869
|
+
return this.cachedHighlights;
|
|
870
|
+
}
|
|
864
871
|
};
|
|
865
872
|
|
|
866
873
|
// src/utils/version/compare.ts
|
|
@@ -905,23 +912,28 @@ var VersionChecker = class {
|
|
|
905
912
|
return {
|
|
906
913
|
hasUpdate: compareVersions(cached, this.currentVersion) > 0,
|
|
907
914
|
currentVersion: this.currentVersion,
|
|
908
|
-
latestVersion: cached
|
|
915
|
+
latestVersion: cached,
|
|
916
|
+
latestHighlights: this.cache.getHighlights()
|
|
909
917
|
};
|
|
910
918
|
}
|
|
911
919
|
}
|
|
912
|
-
const
|
|
913
|
-
|
|
920
|
+
const release = this.provider.getLatestRelease ? await this.provider.getLatestRelease() : await this.provider.getLatestVersion().then(
|
|
921
|
+
(version) => version ? { version, highlights: [] } : null
|
|
922
|
+
);
|
|
923
|
+
if (!release) {
|
|
914
924
|
return {
|
|
915
925
|
hasUpdate: false,
|
|
916
926
|
currentVersion: this.currentVersion,
|
|
917
|
-
latestVersion: null
|
|
927
|
+
latestVersion: null,
|
|
928
|
+
latestHighlights: []
|
|
918
929
|
};
|
|
919
930
|
}
|
|
920
|
-
this.cache.set(
|
|
931
|
+
this.cache.set(release.version, release.highlights);
|
|
921
932
|
return {
|
|
922
|
-
hasUpdate: compareVersions(
|
|
933
|
+
hasUpdate: compareVersions(release.version, this.currentVersion) > 0,
|
|
923
934
|
currentVersion: this.currentVersion,
|
|
924
|
-
latestVersion
|
|
935
|
+
latestVersion: release.version,
|
|
936
|
+
latestHighlights: release.highlights
|
|
925
937
|
};
|
|
926
938
|
}
|
|
927
939
|
/**
|
|
@@ -931,7 +943,7 @@ var VersionChecker = class {
|
|
|
931
943
|
try {
|
|
932
944
|
const result = await this.checkForUpdate();
|
|
933
945
|
if (result.hasUpdate && notifier && result.latestVersion) {
|
|
934
|
-
notifier.notify(result.currentVersion, result.latestVersion);
|
|
946
|
+
notifier.notify(result.currentVersion, result.latestVersion, result.latestHighlights);
|
|
935
947
|
}
|
|
936
948
|
} catch (error2) {
|
|
937
949
|
}
|
|
@@ -941,6 +953,7 @@ var VersionChecker = class {
|
|
|
941
953
|
*/
|
|
942
954
|
clearCache() {
|
|
943
955
|
this.cache.clear();
|
|
956
|
+
this.provider.clearCache?.();
|
|
944
957
|
}
|
|
945
958
|
/**
|
|
946
959
|
* Get current cache info
|
|
@@ -955,17 +968,37 @@ var VersionChecker = class {
|
|
|
955
968
|
|
|
956
969
|
// src/utils/version/provider.ts
|
|
957
970
|
init_esm_shims();
|
|
958
|
-
|
|
971
|
+
function parseHighlights(value) {
|
|
972
|
+
if (!Array.isArray(value)) {
|
|
973
|
+
return [];
|
|
974
|
+
}
|
|
975
|
+
return value.filter((item) => typeof item === "string").map((item) => item.trim()).filter((item) => item.length > 0).slice(0, 5);
|
|
976
|
+
}
|
|
977
|
+
var NpmVersionProvider = class _NpmVersionProvider {
|
|
959
978
|
constructor(packageName, registryUrl) {
|
|
960
979
|
this.packageName = packageName;
|
|
961
980
|
this.registryUrl = registryUrl;
|
|
962
981
|
this.timeout = 5e3;
|
|
963
982
|
}
|
|
964
983
|
timeout;
|
|
984
|
+
cachedRelease = null;
|
|
985
|
+
cachedAt = 0;
|
|
986
|
+
/** 同一次进程内复用结果,避免 getLatestVersion / getLatestRelease 重复请求 */
|
|
987
|
+
static REUSE_MS = 6e4;
|
|
965
988
|
/**
|
|
966
989
|
* Get latest version from npm
|
|
967
990
|
*/
|
|
968
991
|
async getLatestVersion() {
|
|
992
|
+
const release = await this.getLatestRelease();
|
|
993
|
+
return release?.version ?? null;
|
|
994
|
+
}
|
|
995
|
+
/**
|
|
996
|
+
* 获取最新版本及其更新摘要
|
|
997
|
+
*/
|
|
998
|
+
async getLatestRelease() {
|
|
999
|
+
if (this.cachedRelease && Date.now() - this.cachedAt < _NpmVersionProvider.REUSE_MS) {
|
|
1000
|
+
return this.cachedRelease;
|
|
1001
|
+
}
|
|
969
1002
|
try {
|
|
970
1003
|
const controller = new AbortController();
|
|
971
1004
|
const timeoutId = setTimeout(() => controller.abort(), this.timeout);
|
|
@@ -977,11 +1010,28 @@ var NpmVersionProvider = class {
|
|
|
977
1010
|
return null;
|
|
978
1011
|
}
|
|
979
1012
|
const data = await response.json();
|
|
980
|
-
|
|
1013
|
+
const version = data["dist-tags"]?.latest;
|
|
1014
|
+
if (!version) {
|
|
1015
|
+
return null;
|
|
1016
|
+
}
|
|
1017
|
+
const highlights = parseHighlights(
|
|
1018
|
+
data.versions?.[version]?.wukongCli?.highlights ?? data.wukongCli?.highlights
|
|
1019
|
+
);
|
|
1020
|
+
const release = { version, highlights };
|
|
1021
|
+
this.cachedRelease = release;
|
|
1022
|
+
this.cachedAt = Date.now();
|
|
1023
|
+
return release;
|
|
981
1024
|
} catch (error2) {
|
|
982
1025
|
return null;
|
|
983
1026
|
}
|
|
984
1027
|
}
|
|
1028
|
+
/**
|
|
1029
|
+
* 清除进程内复用缓存
|
|
1030
|
+
*/
|
|
1031
|
+
clearCache() {
|
|
1032
|
+
this.cachedRelease = null;
|
|
1033
|
+
this.cachedAt = 0;
|
|
1034
|
+
}
|
|
985
1035
|
};
|
|
986
1036
|
|
|
987
1037
|
// src/utils/version/persistent-cache.ts
|
|
@@ -1002,6 +1052,7 @@ var PersistentVersionCache = class extends VersionCache {
|
|
|
1002
1052
|
if (typeof data.lastCheckTime === "number" && typeof data.version === "string") {
|
|
1003
1053
|
this.lastCheckTime = data.lastCheckTime;
|
|
1004
1054
|
this.cachedVersion = data.version;
|
|
1055
|
+
this.cachedHighlights = Array.isArray(data.highlights) ? data.highlights.filter((item) => typeof item === "string") : [];
|
|
1005
1056
|
}
|
|
1006
1057
|
} catch {
|
|
1007
1058
|
}
|
|
@@ -1011,14 +1062,15 @@ var PersistentVersionCache = class extends VersionCache {
|
|
|
1011
1062
|
mkdirSync(dirname(this.cacheFilePath), { recursive: true });
|
|
1012
1063
|
const data = {
|
|
1013
1064
|
lastCheckTime: this.lastCheckTime,
|
|
1014
|
-
version: this.cachedVersion ?? ""
|
|
1065
|
+
version: this.cachedVersion ?? "",
|
|
1066
|
+
highlights: this.cachedHighlights
|
|
1015
1067
|
};
|
|
1016
1068
|
writeFileSync(this.cacheFilePath, JSON.stringify(data), "utf-8");
|
|
1017
1069
|
} catch {
|
|
1018
1070
|
}
|
|
1019
1071
|
}
|
|
1020
|
-
set(version) {
|
|
1021
|
-
super.set(version);
|
|
1072
|
+
set(version, highlights = []) {
|
|
1073
|
+
super.set(version, highlights);
|
|
1022
1074
|
this.saveToFile();
|
|
1023
1075
|
}
|
|
1024
1076
|
clear() {
|
|
@@ -1034,10 +1086,24 @@ import { join } from "path";
|
|
|
1034
1086
|
// src/utils/version/notifier.ts
|
|
1035
1087
|
init_esm_shims();
|
|
1036
1088
|
import chalk2 from "chalk";
|
|
1089
|
+
var MAX_HIGHLIGHTS = 3;
|
|
1090
|
+
var SEPARATOR = "\u2500".repeat(58);
|
|
1037
1091
|
var ConsoleNotifier = class {
|
|
1038
|
-
notify(currentVersion, latestVersion) {
|
|
1039
|
-
const
|
|
1040
|
-
|
|
1092
|
+
notify(currentVersion, latestVersion, highlights = []) {
|
|
1093
|
+
const lines = [
|
|
1094
|
+
SEPARATOR,
|
|
1095
|
+
`New version available: ${currentVersion} \u2192 ${latestVersion}`
|
|
1096
|
+
];
|
|
1097
|
+
if (highlights.length > 0) {
|
|
1098
|
+
lines.push("\u672C\u6B21\u66F4\u65B0\uFF1A");
|
|
1099
|
+
for (const item of highlights.slice(0, MAX_HIGHLIGHTS)) {
|
|
1100
|
+
lines.push(` \u2022 ${item}`);
|
|
1101
|
+
}
|
|
1102
|
+
}
|
|
1103
|
+
lines.push("\u5347\u7EA7\uFF1Awukong-cli update");
|
|
1104
|
+
lines.push(" \u6216 npm i -g @zrhsh/wukong-cli@latest");
|
|
1105
|
+
lines.push(SEPARATOR);
|
|
1106
|
+
process.stderr.write(chalk2.yellow(lines.join("\n")) + "\n");
|
|
1041
1107
|
}
|
|
1042
1108
|
};
|
|
1043
1109
|
|
|
@@ -2098,16 +2164,18 @@ function getClient() {
|
|
|
2098
2164
|
}
|
|
2099
2165
|
|
|
2100
2166
|
// src/commands/auth.ts
|
|
2167
|
+
init_environments();
|
|
2101
2168
|
init_oceanet();
|
|
2102
|
-
|
|
2169
|
+
function resolveEnvContext() {
|
|
2170
|
+
const env = getCurrentEnvironment();
|
|
2171
|
+
setCurrentEnvironment(env);
|
|
2172
|
+
return { env, envConfig: ENVIRONMENTS[env] };
|
|
2173
|
+
}
|
|
2103
2174
|
var authCommands = new Command("auth").description("Authentication commands");
|
|
2104
2175
|
authCommands.command("login").description("Login using Device Authorization Flow").action(async () => {
|
|
2105
2176
|
try {
|
|
2106
|
-
const env =
|
|
2107
|
-
const allEnvs = getAllEnvironments();
|
|
2108
|
-
setCurrentEnvironment(env);
|
|
2177
|
+
const { env, envConfig } = resolveEnvContext();
|
|
2109
2178
|
const config = getOceanetConfig();
|
|
2110
|
-
const envConfig = allEnvs[env];
|
|
2111
2179
|
console.log("");
|
|
2112
2180
|
console.log(chalk5.bgBlue.white.bold(" Wukong CLI Login "));
|
|
2113
2181
|
console.log("");
|
|
@@ -2175,10 +2243,7 @@ authCommands.command("login").description("Login using Device Authorization Flow
|
|
|
2175
2243
|
}
|
|
2176
2244
|
});
|
|
2177
2245
|
authCommands.command("logout").description("Logout and clear saved tokens").action(async () => {
|
|
2178
|
-
const env =
|
|
2179
|
-
const allEnvs = getAllEnvironments();
|
|
2180
|
-
setCurrentEnvironment(env);
|
|
2181
|
-
const envConfig = allEnvs[env];
|
|
2246
|
+
const { env, envConfig } = resolveEnvContext();
|
|
2182
2247
|
try {
|
|
2183
2248
|
const accessToken = await getAccessToken();
|
|
2184
2249
|
const ystAccessToken = await getYstAccessToken();
|
|
@@ -2195,9 +2260,7 @@ authCommands.command("logout").description("Logout and clear saved tokens").acti
|
|
|
2195
2260
|
}
|
|
2196
2261
|
});
|
|
2197
2262
|
authCommands.command("refresh").description("Manually refresh access token").action(async () => {
|
|
2198
|
-
const env =
|
|
2199
|
-
const allEnvs = getAllEnvironments();
|
|
2200
|
-
const envConfig = allEnvs[env];
|
|
2263
|
+
const { env, envConfig } = resolveEnvContext();
|
|
2201
2264
|
try {
|
|
2202
2265
|
const config = getOceanetConfig();
|
|
2203
2266
|
const accessToken = await getAccessToken();
|
|
@@ -2243,10 +2306,7 @@ authCommands.command("refresh").description("Manually refresh access token").act
|
|
|
2243
2306
|
});
|
|
2244
2307
|
authCommands.command("status").description("Show authentication status").action(async () => {
|
|
2245
2308
|
console.log("");
|
|
2246
|
-
const env =
|
|
2247
|
-
const allEnvs = getAllEnvironments();
|
|
2248
|
-
setCurrentEnvironment(env);
|
|
2249
|
-
const envConfig = allEnvs[env];
|
|
2309
|
+
const { env, envConfig } = resolveEnvContext();
|
|
2250
2310
|
try {
|
|
2251
2311
|
const config = getOceanetConfig();
|
|
2252
2312
|
const accessToken = await getAccessToken();
|
|
@@ -2256,6 +2316,7 @@ authCommands.command("status").description("Show authentication status").action(
|
|
|
2256
2316
|
printEnvironmentInfo(env, envConfig.displayName);
|
|
2257
2317
|
console.log(chalk5.dim(`Run: wukong-cli auth login`));
|
|
2258
2318
|
console.log("");
|
|
2319
|
+
process.exitCode = 1;
|
|
2259
2320
|
return;
|
|
2260
2321
|
}
|
|
2261
2322
|
try {
|
|
@@ -2280,6 +2341,7 @@ authCommands.command("status").description("Show authentication status").action(
|
|
|
2280
2341
|
printEnvironmentInfo(env, envConfig.displayName);
|
|
2281
2342
|
console.log(chalk5.dim(`Run: wukong-cli auth login`));
|
|
2282
2343
|
console.log("");
|
|
2344
|
+
process.exitCode = 1;
|
|
2283
2345
|
}
|
|
2284
2346
|
} catch (error2) {
|
|
2285
2347
|
if (error2 instanceof ConfigFileError) {
|
|
@@ -2287,6 +2349,7 @@ authCommands.command("status").description("Show authentication status").action(
|
|
|
2287
2349
|
console.log("");
|
|
2288
2350
|
console.log(chalk5.red(error2.toUserMessage()));
|
|
2289
2351
|
console.log("");
|
|
2352
|
+
process.exitCode = 1;
|
|
2290
2353
|
return;
|
|
2291
2354
|
}
|
|
2292
2355
|
console.log(chalk5.yellow(`\u2717 Not authenticated`));
|
|
@@ -2294,14 +2357,12 @@ authCommands.command("status").description("Show authentication status").action(
|
|
|
2294
2357
|
printEnvironmentInfo(env, envConfig.displayName);
|
|
2295
2358
|
console.log(chalk5.dim(`Run: wukong-cli auth login`));
|
|
2296
2359
|
console.log("");
|
|
2360
|
+
process.exitCode = 1;
|
|
2297
2361
|
}
|
|
2298
2362
|
});
|
|
2299
2363
|
authCommands.command("token").description("Display current token structure and JWT payload claims").action(async () => {
|
|
2300
2364
|
console.log("");
|
|
2301
|
-
const env =
|
|
2302
|
-
const allEnvs = getAllEnvironments();
|
|
2303
|
-
setCurrentEnvironment(env);
|
|
2304
|
-
const envConfig = allEnvs[env];
|
|
2365
|
+
const { env, envConfig } = resolveEnvContext();
|
|
2305
2366
|
try {
|
|
2306
2367
|
let decodeJwt2 = function(token) {
|
|
2307
2368
|
try {
|
|
@@ -2494,8 +2555,37 @@ function detectPageQueryEnvelope(body) {
|
|
|
2494
2555
|
};
|
|
2495
2556
|
}
|
|
2496
2557
|
|
|
2558
|
+
// src/core/http/response-guard.ts
|
|
2559
|
+
init_esm_shims();
|
|
2560
|
+
var AUTH_ERROR_CODES = [401, 403, 9913, 9914];
|
|
2561
|
+
var LOGIN_HINT = "Run: wukong-cli auth login";
|
|
2562
|
+
function isAuthErrorCode(code) {
|
|
2563
|
+
return AUTH_ERROR_CODES.includes(code);
|
|
2564
|
+
}
|
|
2565
|
+
function withLoginHint(message) {
|
|
2566
|
+
if (message.includes(LOGIN_HINT)) {
|
|
2567
|
+
return message;
|
|
2568
|
+
}
|
|
2569
|
+
return `${message}
|
|
2570
|
+
Hint: \u767B\u5F55\u6001\u53EF\u80FD\u5DF2\u5931\u6548\uFF0C\u8BF7\u91CD\u65B0\u767B\u5F55\u3002${LOGIN_HINT}`;
|
|
2571
|
+
}
|
|
2572
|
+
function looksLikeHtml(value) {
|
|
2573
|
+
if (typeof value !== "string") {
|
|
2574
|
+
return false;
|
|
2575
|
+
}
|
|
2576
|
+
const head = value.trimStart().slice(0, 64).toLowerCase();
|
|
2577
|
+
return head.startsWith("<!doctype html") || head.startsWith("<html");
|
|
2578
|
+
}
|
|
2579
|
+
function describeHtmlResponse() {
|
|
2580
|
+
return [
|
|
2581
|
+
"\u63A5\u53E3\u8FD4\u56DE\u7684\u662F HTML \u9875\u9762\uFF0C\u4E0D\u662F JSON\u3002",
|
|
2582
|
+
"\u5E38\u89C1\u539F\u56E0\uFF1A\u767B\u5F55\u6001\u5931\u6548\u88AB\u91CD\u5B9A\u5411\u5230\u767B\u5F55\u9875\u3001\u63A5\u53E3\u8DEF\u5F84\u9519\u8BEF\u3001base URL \u6307\u5411\u4E86\u524D\u7AEF\u7AD9\u70B9\u3002",
|
|
2583
|
+
`\u8BF7\u5148\u6267\u884C wukong-cli auth status \u786E\u8BA4\u767B\u5F55\u6001\uFF0C\u5FC5\u8981\u65F6 ${LOGIN_HINT}`
|
|
2584
|
+
].join("\n");
|
|
2585
|
+
}
|
|
2586
|
+
|
|
2497
2587
|
// src/commands/http.ts
|
|
2498
|
-
function fail(message, jsonMode, errorCode = null) {
|
|
2588
|
+
function fail(message, jsonMode, errorCode = null, exitCode = 1) {
|
|
2499
2589
|
if (jsonMode) {
|
|
2500
2590
|
process.stderr.write(
|
|
2501
2591
|
JSON.stringify({ error: { code: errorCode, message } }, null, 2) + "\n"
|
|
@@ -2503,7 +2593,7 @@ function fail(message, jsonMode, errorCode = null) {
|
|
|
2503
2593
|
} else {
|
|
2504
2594
|
console.error(chalk6.red(message));
|
|
2505
2595
|
}
|
|
2506
|
-
process.exit(
|
|
2596
|
+
process.exit(exitCode);
|
|
2507
2597
|
}
|
|
2508
2598
|
function fixGitBashPath(url) {
|
|
2509
2599
|
if (url.includes(":") && !url.startsWith("http")) {
|
|
@@ -2644,7 +2734,12 @@ function handleError(error2, jsonMode) {
|
|
|
2644
2734
|
${error2.toUserMessage()}`, jsonMode);
|
|
2645
2735
|
}
|
|
2646
2736
|
if (error2 instanceof ApiError) {
|
|
2647
|
-
|
|
2737
|
+
const message = `API Error (code: ${error2.code}): ${error2.message}`;
|
|
2738
|
+
return fail(
|
|
2739
|
+
isAuthErrorCode(error2.code) ? withLoginHint(message) : message,
|
|
2740
|
+
jsonMode,
|
|
2741
|
+
error2.code
|
|
2742
|
+
);
|
|
2648
2743
|
}
|
|
2649
2744
|
return fail(error2 instanceof Error ? error2.message : String(error2), jsonMode);
|
|
2650
2745
|
}
|
|
@@ -2675,6 +2770,10 @@ async function executeRequest(method, url, options) {
|
|
|
2675
2770
|
};
|
|
2676
2771
|
warnOnPageQueryEnvelope(context);
|
|
2677
2772
|
const result = context.fullUrl.includes("/yst-") ? await sendWithYstToken(context) : await sendWithMainToken(context);
|
|
2773
|
+
if (looksLikeHtml(result.data)) {
|
|
2774
|
+
spinner.fail("Unexpected HTML response");
|
|
2775
|
+
fail(describeHtmlResponse(), jsonMode, null, 2);
|
|
2776
|
+
}
|
|
2678
2777
|
spinner.succeed(`Response received (${result.duration}ms)`);
|
|
2679
2778
|
renderResult(result, jsonMode);
|
|
2680
2779
|
} catch (error2) {
|
|
@@ -3182,7 +3281,7 @@ async function runUpdateCommand({
|
|
|
3182
3281
|
}
|
|
3183
3282
|
var updateCommand = new Command5("update").description("Update wukong-cli to the latest npm version").action(async () => {
|
|
3184
3283
|
const exitCode = await runUpdateCommand({
|
|
3185
|
-
currentVersion:
|
|
3284
|
+
currentVersion: CLI_VERSION,
|
|
3186
3285
|
versionProvider: new NpmVersionProvider(
|
|
3187
3286
|
"@zrhsh/wukong-cli",
|
|
3188
3287
|
"https://registry.npmjs.org"
|
|
@@ -3197,7 +3296,7 @@ var updateCommand = new Command5("update").description("Update wukong-cli to the
|
|
|
3197
3296
|
|
|
3198
3297
|
// src/cli.ts
|
|
3199
3298
|
var program = new Command6();
|
|
3200
|
-
program.name("wukong-cli").description("Wukong CLI - TypeScript implementation").version(
|
|
3299
|
+
program.name("wukong-cli").description("Wukong CLI - TypeScript implementation").version(CLI_VERSION).option("--debug", "Enable debug mode (show HTTP requests)").hook("preAction", (thisCommand) => {
|
|
3201
3300
|
const options = thisCommand.opts();
|
|
3202
3301
|
if (options.debug === true) {
|
|
3203
3302
|
setDebugMode(true, true);
|
|
@@ -3216,7 +3315,7 @@ if (process.argv.length === 2) {
|
|
|
3216
3315
|
program.parse();
|
|
3217
3316
|
setImmediate(() => {
|
|
3218
3317
|
try {
|
|
3219
|
-
const versionChecker = getVersionChecker(
|
|
3318
|
+
const versionChecker = getVersionChecker(CLI_VERSION);
|
|
3220
3319
|
const notifier = new ConsoleNotifier();
|
|
3221
3320
|
versionChecker.checkInBackground(notifier).catch(() => {
|
|
3222
3321
|
});
|