@zrhsh/wukong-cli 0.4.9 → 0.4.10
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/dist/cli.js +364 -345
- package/dist/cli.js.map +1 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -3,12 +3,6 @@ var __defProp = Object.defineProperty;
|
|
|
3
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
7
|
-
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
8
|
-
}) : x)(function(x) {
|
|
9
|
-
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
10
|
-
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
11
|
-
});
|
|
12
6
|
var __esm = (fn, res) => function __init() {
|
|
13
7
|
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
14
8
|
};
|
|
@@ -95,217 +89,6 @@ var init_debug = __esm({
|
|
|
95
89
|
}
|
|
96
90
|
});
|
|
97
91
|
|
|
98
|
-
// src/utils/version/cache.ts
|
|
99
|
-
var VersionCache;
|
|
100
|
-
var init_cache = __esm({
|
|
101
|
-
"src/utils/version/cache.ts"() {
|
|
102
|
-
"use strict";
|
|
103
|
-
init_esm_shims();
|
|
104
|
-
VersionCache = class {
|
|
105
|
-
lastCheckTime = 0;
|
|
106
|
-
cachedVersion = null;
|
|
107
|
-
checkInterval;
|
|
108
|
-
/**
|
|
109
|
-
* Constructor
|
|
110
|
-
* @param checkInterval - Check interval in milliseconds (default: 24 hours)
|
|
111
|
-
*/
|
|
112
|
-
constructor(checkInterval = 24 * 60 * 60 * 1e3) {
|
|
113
|
-
this.checkInterval = checkInterval;
|
|
114
|
-
}
|
|
115
|
-
/**
|
|
116
|
-
* Check if a new version check should be performed
|
|
117
|
-
*/
|
|
118
|
-
shouldCheck() {
|
|
119
|
-
const now = Date.now();
|
|
120
|
-
return now - this.lastCheckTime >= this.checkInterval;
|
|
121
|
-
}
|
|
122
|
-
/**
|
|
123
|
-
* Get cached version
|
|
124
|
-
*/
|
|
125
|
-
get() {
|
|
126
|
-
return this.cachedVersion;
|
|
127
|
-
}
|
|
128
|
-
/**
|
|
129
|
-
* Set cached version with timestamp
|
|
130
|
-
*/
|
|
131
|
-
set(version) {
|
|
132
|
-
this.cachedVersion = version;
|
|
133
|
-
this.lastCheckTime = Date.now();
|
|
134
|
-
}
|
|
135
|
-
/**
|
|
136
|
-
* Clear cache
|
|
137
|
-
*/
|
|
138
|
-
clear() {
|
|
139
|
-
this.lastCheckTime = 0;
|
|
140
|
-
this.cachedVersion = null;
|
|
141
|
-
}
|
|
142
|
-
/**
|
|
143
|
-
* Get time since last check
|
|
144
|
-
*/
|
|
145
|
-
getTimeSinceLastCheck() {
|
|
146
|
-
if (this.lastCheckTime === 0) {
|
|
147
|
-
return 0;
|
|
148
|
-
}
|
|
149
|
-
return Date.now() - this.lastCheckTime;
|
|
150
|
-
}
|
|
151
|
-
/** Last check timestamp */
|
|
152
|
-
get lastCheck() {
|
|
153
|
-
return this.lastCheckTime;
|
|
154
|
-
}
|
|
155
|
-
/** Cached version string */
|
|
156
|
-
get version() {
|
|
157
|
-
return this.cachedVersion;
|
|
158
|
-
}
|
|
159
|
-
};
|
|
160
|
-
}
|
|
161
|
-
});
|
|
162
|
-
|
|
163
|
-
// src/utils/version/provider.ts
|
|
164
|
-
var provider_exports = {};
|
|
165
|
-
__export(provider_exports, {
|
|
166
|
-
NpmVersionProvider: () => NpmVersionProvider
|
|
167
|
-
});
|
|
168
|
-
var NpmVersionProvider;
|
|
169
|
-
var init_provider = __esm({
|
|
170
|
-
"src/utils/version/provider.ts"() {
|
|
171
|
-
"use strict";
|
|
172
|
-
init_esm_shims();
|
|
173
|
-
NpmVersionProvider = class {
|
|
174
|
-
constructor(packageName, registryUrl) {
|
|
175
|
-
this.packageName = packageName;
|
|
176
|
-
this.registryUrl = registryUrl;
|
|
177
|
-
this.timeout = 5e3;
|
|
178
|
-
}
|
|
179
|
-
timeout;
|
|
180
|
-
/**
|
|
181
|
-
* Get latest version from npm
|
|
182
|
-
*/
|
|
183
|
-
async getLatestVersion() {
|
|
184
|
-
try {
|
|
185
|
-
const controller = new AbortController();
|
|
186
|
-
const timeoutId = setTimeout(() => controller.abort(), this.timeout);
|
|
187
|
-
const response = await fetch(`${this.registryUrl}/${this.packageName}`, {
|
|
188
|
-
signal: controller.signal
|
|
189
|
-
});
|
|
190
|
-
clearTimeout(timeoutId);
|
|
191
|
-
if (!response.ok) {
|
|
192
|
-
return null;
|
|
193
|
-
}
|
|
194
|
-
const data = await response.json();
|
|
195
|
-
return data["dist-tags"]?.latest || null;
|
|
196
|
-
} catch (error) {
|
|
197
|
-
return null;
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
};
|
|
201
|
-
}
|
|
202
|
-
});
|
|
203
|
-
|
|
204
|
-
// src/utils/version/compare.ts
|
|
205
|
-
function compareVersions(v1, v2) {
|
|
206
|
-
const parts1 = v1.split(".").map(Number);
|
|
207
|
-
const parts2 = v2.split(".").map(Number);
|
|
208
|
-
for (let i = 0; i < Math.max(parts1.length, parts2.length); i++) {
|
|
209
|
-
const part1 = parts1[i] || 0;
|
|
210
|
-
const part2 = parts2[i] || 0;
|
|
211
|
-
if (part1 > part2) return 1;
|
|
212
|
-
if (part1 < part2) return -1;
|
|
213
|
-
}
|
|
214
|
-
return 0;
|
|
215
|
-
}
|
|
216
|
-
function describeVersionComparison(currentVersion, latestVersion) {
|
|
217
|
-
const comparison = compareVersions(currentVersion, latestVersion);
|
|
218
|
-
if (comparison > 0) {
|
|
219
|
-
return "current version is newer than latest";
|
|
220
|
-
}
|
|
221
|
-
if (comparison < 0) {
|
|
222
|
-
return "latest version is newer";
|
|
223
|
-
}
|
|
224
|
-
return "current version is equal to latest";
|
|
225
|
-
}
|
|
226
|
-
var init_compare = __esm({
|
|
227
|
-
"src/utils/version/compare.ts"() {
|
|
228
|
-
"use strict";
|
|
229
|
-
init_esm_shims();
|
|
230
|
-
}
|
|
231
|
-
});
|
|
232
|
-
|
|
233
|
-
// src/utils/version/checker.ts
|
|
234
|
-
var checker_exports = {};
|
|
235
|
-
__export(checker_exports, {
|
|
236
|
-
VersionChecker: () => VersionChecker
|
|
237
|
-
});
|
|
238
|
-
var VersionChecker;
|
|
239
|
-
var init_checker = __esm({
|
|
240
|
-
"src/utils/version/checker.ts"() {
|
|
241
|
-
"use strict";
|
|
242
|
-
init_esm_shims();
|
|
243
|
-
init_cache();
|
|
244
|
-
init_compare();
|
|
245
|
-
VersionChecker = class {
|
|
246
|
-
constructor(provider, currentVersion, cache) {
|
|
247
|
-
this.provider = provider;
|
|
248
|
-
this.currentVersion = currentVersion;
|
|
249
|
-
this.cache = cache || new VersionCache();
|
|
250
|
-
}
|
|
251
|
-
cache;
|
|
252
|
-
/**
|
|
253
|
-
* Check for update (cached or fresh)
|
|
254
|
-
*/
|
|
255
|
-
async checkForUpdate() {
|
|
256
|
-
if (!this.cache.shouldCheck()) {
|
|
257
|
-
const cached = this.cache.get();
|
|
258
|
-
if (cached) {
|
|
259
|
-
return {
|
|
260
|
-
hasUpdate: compareVersions(cached, this.currentVersion) > 0,
|
|
261
|
-
currentVersion: this.currentVersion,
|
|
262
|
-
latestVersion: cached
|
|
263
|
-
};
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
const latestVersion = await this.provider.getLatestVersion();
|
|
267
|
-
if (!latestVersion) {
|
|
268
|
-
return {
|
|
269
|
-
hasUpdate: false,
|
|
270
|
-
currentVersion: this.currentVersion,
|
|
271
|
-
latestVersion: null
|
|
272
|
-
};
|
|
273
|
-
}
|
|
274
|
-
this.cache.set(latestVersion);
|
|
275
|
-
return {
|
|
276
|
-
hasUpdate: compareVersions(latestVersion, this.currentVersion) > 0,
|
|
277
|
-
currentVersion: this.currentVersion,
|
|
278
|
-
latestVersion
|
|
279
|
-
};
|
|
280
|
-
}
|
|
281
|
-
/**
|
|
282
|
-
* Check in background (for async execution)
|
|
283
|
-
*/
|
|
284
|
-
async checkInBackground() {
|
|
285
|
-
try {
|
|
286
|
-
await this.checkForUpdate();
|
|
287
|
-
} catch (error) {
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
|
-
/**
|
|
291
|
-
* Clear cached data
|
|
292
|
-
*/
|
|
293
|
-
clearCache() {
|
|
294
|
-
this.cache.clear();
|
|
295
|
-
}
|
|
296
|
-
/**
|
|
297
|
-
* Get current cache info
|
|
298
|
-
*/
|
|
299
|
-
getCacheInfo() {
|
|
300
|
-
return {
|
|
301
|
-
lastCheckTime: this.cache.lastCheck,
|
|
302
|
-
cachedVersion: this.cache.version
|
|
303
|
-
};
|
|
304
|
-
}
|
|
305
|
-
};
|
|
306
|
-
}
|
|
307
|
-
});
|
|
308
|
-
|
|
309
92
|
// src/config/errors/config-file-error.ts
|
|
310
93
|
var ConfigFileError;
|
|
311
94
|
var init_config_file_error = __esm({
|
|
@@ -417,16 +200,16 @@ var init_environments = __esm({
|
|
|
417
200
|
});
|
|
418
201
|
|
|
419
202
|
// src/config/config-loader.ts
|
|
420
|
-
import { readFileSync, writeFileSync, existsSync, mkdirSync } from "fs";
|
|
421
|
-
import { join, dirname } from "path";
|
|
422
|
-
import { homedir } from "os";
|
|
203
|
+
import { readFileSync as readFileSync2, writeFileSync as writeFileSync2, existsSync, mkdirSync as mkdirSync2 } from "fs";
|
|
204
|
+
import { join as join2, dirname as dirname2 } from "path";
|
|
205
|
+
import { homedir as homedir2 } from "os";
|
|
423
206
|
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
424
207
|
function getUserConfigPath() {
|
|
425
208
|
return CONFIG_FILE_PATH;
|
|
426
209
|
}
|
|
427
210
|
function ensureConfigDir() {
|
|
428
211
|
if (!existsSync(CONFIG_DIR)) {
|
|
429
|
-
|
|
212
|
+
mkdirSync2(CONFIG_DIR, { recursive: true });
|
|
430
213
|
}
|
|
431
214
|
}
|
|
432
215
|
function createDefaultConfig() {
|
|
@@ -435,25 +218,25 @@ function createDefaultConfig() {
|
|
|
435
218
|
return;
|
|
436
219
|
}
|
|
437
220
|
try {
|
|
438
|
-
const templatePath =
|
|
221
|
+
const templatePath = join2(getProjectRoot(), "wukong-cli.json.template");
|
|
439
222
|
if (!existsSync(templatePath)) {
|
|
440
223
|
console.warn(`Warning: Template config not found: ${templatePath}`);
|
|
441
224
|
return;
|
|
442
225
|
}
|
|
443
|
-
const templateContent =
|
|
226
|
+
const templateContent = readFileSync2(templatePath, "utf-8");
|
|
444
227
|
const defaultConfig = JSON.parse(templateContent);
|
|
445
228
|
ensureConfigDir();
|
|
446
|
-
|
|
229
|
+
writeFileSync2(configPath, JSON.stringify(defaultConfig, null, 2), "utf-8");
|
|
447
230
|
} catch (error) {
|
|
448
231
|
}
|
|
449
232
|
}
|
|
450
233
|
function getProjectRoot() {
|
|
451
|
-
let currentDir =
|
|
452
|
-
while (currentDir !==
|
|
453
|
-
if (existsSync(
|
|
234
|
+
let currentDir = dirname2(fileURLToPath2(import.meta.url));
|
|
235
|
+
while (currentDir !== dirname2(currentDir)) {
|
|
236
|
+
if (existsSync(join2(currentDir, "package.json"))) {
|
|
454
237
|
return currentDir;
|
|
455
238
|
}
|
|
456
|
-
currentDir =
|
|
239
|
+
currentDir = dirname2(currentDir);
|
|
457
240
|
}
|
|
458
241
|
return process.cwd();
|
|
459
242
|
}
|
|
@@ -471,7 +254,7 @@ function loadConfig() {
|
|
|
471
254
|
return {};
|
|
472
255
|
}
|
|
473
256
|
try {
|
|
474
|
-
const content =
|
|
257
|
+
const content = readFileSync2(configPath, "utf-8");
|
|
475
258
|
const config = JSON.parse(content);
|
|
476
259
|
return config;
|
|
477
260
|
} catch (error) {
|
|
@@ -548,8 +331,8 @@ var init_config_loader = __esm({
|
|
|
548
331
|
init_esm_shims();
|
|
549
332
|
init_environments();
|
|
550
333
|
init_config_file_error();
|
|
551
|
-
CONFIG_DIR =
|
|
552
|
-
CONFIG_FILE_PATH =
|
|
334
|
+
CONFIG_DIR = join2(homedir2(), ".wukong-cli");
|
|
335
|
+
CONFIG_FILE_PATH = join2(CONFIG_DIR, "wukong-cli.json");
|
|
553
336
|
}
|
|
554
337
|
});
|
|
555
338
|
|
|
@@ -800,9 +583,9 @@ var init_keytar_adapter = __esm({
|
|
|
800
583
|
});
|
|
801
584
|
|
|
802
585
|
// src/providers/file-credential-store.ts
|
|
803
|
-
import { writeFileSync as
|
|
804
|
-
import { join as
|
|
805
|
-
import { homedir as
|
|
586
|
+
import { writeFileSync as writeFileSync3, readFileSync as readFileSync3, unlinkSync, existsSync as existsSync2, mkdirSync as mkdirSync3 } from "fs";
|
|
587
|
+
import { join as join3 } from "path";
|
|
588
|
+
import { homedir as homedir3 } from "os";
|
|
806
589
|
var FileCredentialStore;
|
|
807
590
|
var init_file_credential_store = __esm({
|
|
808
591
|
"src/providers/file-credential-store.ts"() {
|
|
@@ -811,21 +594,21 @@ var init_file_credential_store = __esm({
|
|
|
811
594
|
FileCredentialStore = class {
|
|
812
595
|
configDir;
|
|
813
596
|
constructor() {
|
|
814
|
-
this.configDir =
|
|
597
|
+
this.configDir = join3(homedir3(), ".wukong-cli");
|
|
815
598
|
this.ensureConfigDir();
|
|
816
599
|
}
|
|
817
600
|
ensureConfigDir() {
|
|
818
601
|
if (!existsSync2(this.configDir)) {
|
|
819
|
-
|
|
602
|
+
mkdirSync3(this.configDir, { recursive: true, mode: 448 });
|
|
820
603
|
}
|
|
821
604
|
}
|
|
822
605
|
getTokenPath(service, account) {
|
|
823
606
|
const filename = `${service}_${account}.token`;
|
|
824
|
-
return
|
|
607
|
+
return join3(this.configDir, filename);
|
|
825
608
|
}
|
|
826
609
|
async setPassword(service, account, password) {
|
|
827
610
|
const filePath = this.getTokenPath(service, account);
|
|
828
|
-
|
|
611
|
+
writeFileSync3(filePath, password, { mode: 384 });
|
|
829
612
|
}
|
|
830
613
|
async getPassword(service, account) {
|
|
831
614
|
const filePath = this.getTokenPath(service, account);
|
|
@@ -833,7 +616,7 @@ var init_file_credential_store = __esm({
|
|
|
833
616
|
return null;
|
|
834
617
|
}
|
|
835
618
|
try {
|
|
836
|
-
return
|
|
619
|
+
return readFileSync3(filePath, "utf-8");
|
|
837
620
|
} catch {
|
|
838
621
|
return null;
|
|
839
622
|
}
|
|
@@ -982,27 +765,262 @@ import { Command as Command5 } from "commander";
|
|
|
982
765
|
|
|
983
766
|
// src/utils/version/index.ts
|
|
984
767
|
init_esm_shims();
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
768
|
+
|
|
769
|
+
// src/utils/version/checker.ts
|
|
770
|
+
init_esm_shims();
|
|
771
|
+
|
|
772
|
+
// src/utils/version/cache.ts
|
|
773
|
+
init_esm_shims();
|
|
774
|
+
var VersionCache = class {
|
|
775
|
+
lastCheckTime = 0;
|
|
776
|
+
cachedVersion = null;
|
|
777
|
+
checkInterval;
|
|
778
|
+
/**
|
|
779
|
+
* Constructor
|
|
780
|
+
* @param checkInterval - Check interval in milliseconds (default: 24 hours)
|
|
781
|
+
*/
|
|
782
|
+
constructor(checkInterval = 24 * 60 * 60 * 1e3) {
|
|
783
|
+
this.checkInterval = checkInterval;
|
|
784
|
+
}
|
|
785
|
+
/**
|
|
786
|
+
* Check if a new version check should be performed
|
|
787
|
+
*/
|
|
788
|
+
shouldCheck() {
|
|
789
|
+
const now = Date.now();
|
|
790
|
+
return now - this.lastCheckTime >= this.checkInterval;
|
|
791
|
+
}
|
|
792
|
+
/**
|
|
793
|
+
* Get cached version
|
|
794
|
+
*/
|
|
795
|
+
get() {
|
|
796
|
+
return this.cachedVersion;
|
|
797
|
+
}
|
|
798
|
+
/**
|
|
799
|
+
* Set cached version with timestamp
|
|
800
|
+
*/
|
|
801
|
+
set(version) {
|
|
802
|
+
this.cachedVersion = version;
|
|
803
|
+
this.lastCheckTime = Date.now();
|
|
804
|
+
}
|
|
805
|
+
/**
|
|
806
|
+
* Clear cache
|
|
807
|
+
*/
|
|
808
|
+
clear() {
|
|
809
|
+
this.lastCheckTime = 0;
|
|
810
|
+
this.cachedVersion = null;
|
|
811
|
+
}
|
|
812
|
+
/**
|
|
813
|
+
* Get time since last check
|
|
814
|
+
*/
|
|
815
|
+
getTimeSinceLastCheck() {
|
|
816
|
+
if (this.lastCheckTime === 0) {
|
|
817
|
+
return 0;
|
|
818
|
+
}
|
|
819
|
+
return Date.now() - this.lastCheckTime;
|
|
820
|
+
}
|
|
821
|
+
/** Last check timestamp */
|
|
822
|
+
get lastCheck() {
|
|
823
|
+
return this.lastCheckTime;
|
|
824
|
+
}
|
|
825
|
+
/** Cached version string */
|
|
826
|
+
get version() {
|
|
827
|
+
return this.cachedVersion;
|
|
828
|
+
}
|
|
829
|
+
};
|
|
830
|
+
|
|
831
|
+
// src/utils/version/compare.ts
|
|
832
|
+
init_esm_shims();
|
|
833
|
+
function compareVersions(v1, v2) {
|
|
834
|
+
const parts1 = v1.split(".").map(Number);
|
|
835
|
+
const parts2 = v2.split(".").map(Number);
|
|
836
|
+
for (let i = 0; i < Math.max(parts1.length, parts2.length); i++) {
|
|
837
|
+
const part1 = parts1[i] || 0;
|
|
838
|
+
const part2 = parts2[i] || 0;
|
|
839
|
+
if (part1 > part2) return 1;
|
|
840
|
+
if (part1 < part2) return -1;
|
|
841
|
+
}
|
|
842
|
+
return 0;
|
|
843
|
+
}
|
|
844
|
+
function describeVersionComparison(currentVersion, latestVersion) {
|
|
845
|
+
const comparison = compareVersions(currentVersion, latestVersion);
|
|
846
|
+
if (comparison > 0) {
|
|
847
|
+
return "current version is newer than latest";
|
|
848
|
+
}
|
|
849
|
+
if (comparison < 0) {
|
|
850
|
+
return "latest version is newer";
|
|
851
|
+
}
|
|
852
|
+
return "current version is equal to latest";
|
|
853
|
+
}
|
|
854
|
+
|
|
855
|
+
// src/utils/version/checker.ts
|
|
856
|
+
var VersionChecker = class {
|
|
857
|
+
constructor(provider, currentVersion, cache) {
|
|
858
|
+
this.provider = provider;
|
|
859
|
+
this.currentVersion = currentVersion;
|
|
860
|
+
this.cache = cache || new VersionCache();
|
|
861
|
+
}
|
|
862
|
+
cache;
|
|
863
|
+
/**
|
|
864
|
+
* Check for update (cached or fresh)
|
|
865
|
+
*/
|
|
866
|
+
async checkForUpdate() {
|
|
867
|
+
if (!this.cache.shouldCheck()) {
|
|
868
|
+
const cached = this.cache.get();
|
|
869
|
+
if (cached) {
|
|
870
|
+
return {
|
|
871
|
+
hasUpdate: compareVersions(cached, this.currentVersion) > 0,
|
|
872
|
+
currentVersion: this.currentVersion,
|
|
873
|
+
latestVersion: cached
|
|
874
|
+
};
|
|
875
|
+
}
|
|
876
|
+
}
|
|
877
|
+
const latestVersion = await this.provider.getLatestVersion();
|
|
878
|
+
if (!latestVersion) {
|
|
879
|
+
return {
|
|
880
|
+
hasUpdate: false,
|
|
881
|
+
currentVersion: this.currentVersion,
|
|
882
|
+
latestVersion: null
|
|
883
|
+
};
|
|
884
|
+
}
|
|
885
|
+
this.cache.set(latestVersion);
|
|
886
|
+
return {
|
|
887
|
+
hasUpdate: compareVersions(latestVersion, this.currentVersion) > 0,
|
|
888
|
+
currentVersion: this.currentVersion,
|
|
889
|
+
latestVersion
|
|
890
|
+
};
|
|
891
|
+
}
|
|
892
|
+
/**
|
|
893
|
+
* Check in background (for async execution)
|
|
894
|
+
*/
|
|
895
|
+
async checkInBackground(notifier) {
|
|
896
|
+
try {
|
|
897
|
+
const result = await this.checkForUpdate();
|
|
898
|
+
if (result.hasUpdate && notifier && result.latestVersion) {
|
|
899
|
+
notifier.notify(result.currentVersion, result.latestVersion);
|
|
900
|
+
}
|
|
901
|
+
} catch (error) {
|
|
902
|
+
}
|
|
903
|
+
}
|
|
904
|
+
/**
|
|
905
|
+
* Clear cached data
|
|
906
|
+
*/
|
|
907
|
+
clearCache() {
|
|
908
|
+
this.cache.clear();
|
|
909
|
+
}
|
|
910
|
+
/**
|
|
911
|
+
* Get current cache info
|
|
912
|
+
*/
|
|
913
|
+
getCacheInfo() {
|
|
914
|
+
return {
|
|
915
|
+
lastCheckTime: this.cache.lastCheck,
|
|
916
|
+
cachedVersion: this.cache.version
|
|
917
|
+
};
|
|
918
|
+
}
|
|
919
|
+
};
|
|
920
|
+
|
|
921
|
+
// src/utils/version/provider.ts
|
|
922
|
+
init_esm_shims();
|
|
923
|
+
var NpmVersionProvider = class {
|
|
924
|
+
constructor(packageName, registryUrl) {
|
|
925
|
+
this.packageName = packageName;
|
|
926
|
+
this.registryUrl = registryUrl;
|
|
927
|
+
this.timeout = 5e3;
|
|
928
|
+
}
|
|
929
|
+
timeout;
|
|
930
|
+
/**
|
|
931
|
+
* Get latest version from npm
|
|
932
|
+
*/
|
|
933
|
+
async getLatestVersion() {
|
|
934
|
+
try {
|
|
935
|
+
const controller = new AbortController();
|
|
936
|
+
const timeoutId = setTimeout(() => controller.abort(), this.timeout);
|
|
937
|
+
const response = await fetch(`${this.registryUrl}/${this.packageName}`, {
|
|
938
|
+
signal: controller.signal
|
|
939
|
+
});
|
|
940
|
+
clearTimeout(timeoutId);
|
|
941
|
+
if (!response.ok) {
|
|
942
|
+
return null;
|
|
943
|
+
}
|
|
944
|
+
const data = await response.json();
|
|
945
|
+
return data["dist-tags"]?.latest || null;
|
|
946
|
+
} catch (error) {
|
|
947
|
+
return null;
|
|
948
|
+
}
|
|
949
|
+
}
|
|
950
|
+
};
|
|
951
|
+
|
|
952
|
+
// src/utils/version/persistent-cache.ts
|
|
953
|
+
init_esm_shims();
|
|
954
|
+
import { readFileSync, writeFileSync, mkdirSync } from "fs";
|
|
955
|
+
import { dirname } from "path";
|
|
956
|
+
var PersistentVersionCache = class extends VersionCache {
|
|
957
|
+
cacheFilePath;
|
|
958
|
+
constructor(cacheFilePath, checkInterval) {
|
|
959
|
+
super(checkInterval);
|
|
960
|
+
this.cacheFilePath = cacheFilePath;
|
|
961
|
+
this.loadFromFile();
|
|
962
|
+
}
|
|
963
|
+
loadFromFile() {
|
|
964
|
+
try {
|
|
965
|
+
const content = readFileSync(this.cacheFilePath, "utf-8");
|
|
966
|
+
const data = JSON.parse(content);
|
|
967
|
+
if (typeof data.lastCheckTime === "number" && typeof data.version === "string") {
|
|
968
|
+
this.lastCheckTime = data.lastCheckTime;
|
|
969
|
+
this.cachedVersion = data.version;
|
|
970
|
+
}
|
|
971
|
+
} catch {
|
|
972
|
+
}
|
|
973
|
+
}
|
|
974
|
+
saveToFile() {
|
|
975
|
+
try {
|
|
976
|
+
mkdirSync(dirname(this.cacheFilePath), { recursive: true });
|
|
977
|
+
const data = {
|
|
978
|
+
lastCheckTime: this.lastCheckTime,
|
|
979
|
+
version: this.cachedVersion ?? ""
|
|
980
|
+
};
|
|
981
|
+
writeFileSync(this.cacheFilePath, JSON.stringify(data), "utf-8");
|
|
982
|
+
} catch {
|
|
983
|
+
}
|
|
984
|
+
}
|
|
985
|
+
set(version) {
|
|
986
|
+
super.set(version);
|
|
987
|
+
this.saveToFile();
|
|
988
|
+
}
|
|
989
|
+
clear() {
|
|
990
|
+
super.clear();
|
|
991
|
+
this.saveToFile();
|
|
992
|
+
}
|
|
993
|
+
};
|
|
994
|
+
|
|
995
|
+
// src/utils/version/index.ts
|
|
996
|
+
import { homedir } from "os";
|
|
997
|
+
import { join } from "path";
|
|
998
|
+
|
|
999
|
+
// src/utils/version/notifier.ts
|
|
1000
|
+
init_esm_shims();
|
|
1001
|
+
import chalk2 from "chalk";
|
|
1002
|
+
var ConsoleNotifier = class {
|
|
1003
|
+
notify(currentVersion, latestVersion) {
|
|
1004
|
+
const message = `New version available: ${currentVersion} \u2192 ${latestVersion}, run 'wukong-cli update' to update.`;
|
|
1005
|
+
console.log(chalk2.yellow(message));
|
|
1006
|
+
}
|
|
1007
|
+
};
|
|
1008
|
+
|
|
1009
|
+
// src/utils/version/index.ts
|
|
989
1010
|
var versionCheckerInstance = null;
|
|
990
|
-
function getVersionChecker() {
|
|
1011
|
+
function getVersionChecker(currentVersion) {
|
|
991
1012
|
if (versionCheckerInstance) {
|
|
992
1013
|
return versionCheckerInstance;
|
|
993
1014
|
}
|
|
994
|
-
const
|
|
995
|
-
const
|
|
996
|
-
const packageJson = nodeRequire("../../package.json");
|
|
997
|
-
const { NpmVersionProvider: NpmVersionProvider2 } = (init_provider(), __toCommonJS(provider_exports));
|
|
998
|
-
const { VersionChecker: Checker } = (init_checker(), __toCommonJS(checker_exports));
|
|
999
|
-
const provider = new NpmVersionProvider2(
|
|
1015
|
+
const cacheFilePath = join(homedir(), ".wukong-cli", "version-cache.json");
|
|
1016
|
+
const provider = new NpmVersionProvider(
|
|
1000
1017
|
"@zrhsh/wukong-cli",
|
|
1001
1018
|
"https://registry.npmjs.org"
|
|
1002
1019
|
);
|
|
1003
|
-
const instance = new
|
|
1020
|
+
const instance = new VersionChecker(
|
|
1004
1021
|
provider,
|
|
1005
|
-
|
|
1022
|
+
currentVersion,
|
|
1023
|
+
new PersistentVersionCache(cacheFilePath)
|
|
1006
1024
|
);
|
|
1007
1025
|
versionCheckerInstance = instance;
|
|
1008
1026
|
return instance;
|
|
@@ -1011,12 +1029,12 @@ function getVersionChecker() {
|
|
|
1011
1029
|
// src/commands/auth.ts
|
|
1012
1030
|
init_esm_shims();
|
|
1013
1031
|
import { Command } from "commander";
|
|
1014
|
-
import
|
|
1032
|
+
import chalk5 from "chalk";
|
|
1015
1033
|
import ora3 from "ora";
|
|
1016
1034
|
|
|
1017
1035
|
// src/utils/environment.ts
|
|
1018
1036
|
init_esm_shims();
|
|
1019
|
-
import
|
|
1037
|
+
import chalk3 from "chalk";
|
|
1020
1038
|
function formatEnvironmentDisplay(env, displayName) {
|
|
1021
1039
|
if (env === "prod") {
|
|
1022
1040
|
return "";
|
|
@@ -1026,7 +1044,7 @@ function formatEnvironmentDisplay(env, displayName) {
|
|
|
1026
1044
|
function printEnvironmentInfo(env, displayName) {
|
|
1027
1045
|
const display = formatEnvironmentDisplay(env, displayName);
|
|
1028
1046
|
if (display) {
|
|
1029
|
-
console.log(
|
|
1047
|
+
console.log(chalk3.dim(`Environment: ${chalk3.cyan(display)}`));
|
|
1030
1048
|
}
|
|
1031
1049
|
}
|
|
1032
1050
|
|
|
@@ -1364,7 +1382,7 @@ init_esm_shims();
|
|
|
1364
1382
|
|
|
1365
1383
|
// src/core/http/api-error-handler.ts
|
|
1366
1384
|
init_esm_shims();
|
|
1367
|
-
import
|
|
1385
|
+
import chalk4 from "chalk";
|
|
1368
1386
|
var ApiError = class extends Error {
|
|
1369
1387
|
constructor(code, message, retryable = false) {
|
|
1370
1388
|
super(message);
|
|
@@ -1394,14 +1412,14 @@ var ApiErrorHandler = class {
|
|
|
1394
1412
|
this.register(9909, (response) => {
|
|
1395
1413
|
throw new ApiError(
|
|
1396
1414
|
response.code,
|
|
1397
|
-
response.msg || response.errorMsg || response.message || "
|
|
1415
|
+
response.msg || response.errorMsg || response.message || "Access denied",
|
|
1398
1416
|
false
|
|
1399
1417
|
);
|
|
1400
1418
|
});
|
|
1401
1419
|
this.register(9914, (response) => {
|
|
1402
1420
|
throw new ApiError(
|
|
1403
1421
|
response.code,
|
|
1404
|
-
response.msg || response.errorMsg || response.message || "
|
|
1422
|
+
response.msg || response.errorMsg || response.message || "Session expired, please login again",
|
|
1405
1423
|
false
|
|
1406
1424
|
);
|
|
1407
1425
|
});
|
|
@@ -1458,12 +1476,12 @@ var ApiErrorHandler = class {
|
|
|
1458
1476
|
async tryRecover(error, recoverFunction) {
|
|
1459
1477
|
if (error instanceof ApiError && error.retryable) {
|
|
1460
1478
|
console.log("");
|
|
1461
|
-
console.log(
|
|
1479
|
+
console.log(chalk4.yellow("\u26A0 Token expired, attempting refresh..."));
|
|
1462
1480
|
try {
|
|
1463
1481
|
return await recoverFunction();
|
|
1464
1482
|
} catch (refreshError) {
|
|
1465
1483
|
console.log("");
|
|
1466
|
-
console.log(
|
|
1484
|
+
console.log(chalk4.yellow("\u26A0 Auto-refresh failed:"), chalk4.dim(refreshError.message));
|
|
1467
1485
|
throw new ApiError(
|
|
1468
1486
|
error.code,
|
|
1469
1487
|
`${error.message} (Auto-refresh failed)`
|
|
@@ -1900,63 +1918,63 @@ authCommands.command("login").description("Login using Device Authorization Flow
|
|
|
1900
1918
|
const config = getOceanetConfig();
|
|
1901
1919
|
const envConfig = allEnvs[env];
|
|
1902
1920
|
console.log("");
|
|
1903
|
-
console.log(
|
|
1921
|
+
console.log(chalk5.bgBlue.white.bold(" Wukong CLI Login "));
|
|
1904
1922
|
console.log("");
|
|
1905
1923
|
printEnvironmentInfo(env, envConfig.displayName);
|
|
1906
1924
|
console.log("");
|
|
1907
1925
|
const adapter = createCliDeviceFlowAdapter();
|
|
1908
1926
|
const { verificationUri, deviceCode, expiresIn, interval } = await adapter.getDeviceCode();
|
|
1909
1927
|
console.log("");
|
|
1910
|
-
console.log(
|
|
1911
|
-
console.log(
|
|
1912
|
-
console.log(
|
|
1928
|
+
console.log(chalk5.bold("=".repeat(50)));
|
|
1929
|
+
console.log(chalk5.bold(" Please complete authorization"));
|
|
1930
|
+
console.log(chalk5.bold("=".repeat(50)));
|
|
1913
1931
|
console.log("");
|
|
1914
|
-
console.log(
|
|
1932
|
+
console.log(chalk5.green(" Authorization URL:"));
|
|
1915
1933
|
console.log("");
|
|
1916
|
-
console.log(
|
|
1934
|
+
console.log(chalk5.cyan(` ${verificationUri}`));
|
|
1917
1935
|
console.log("");
|
|
1918
|
-
console.error(
|
|
1919
|
-
console.error(
|
|
1936
|
+
console.error(chalk5.yellow.bold(">>> Please open this link in your browser <<<"));
|
|
1937
|
+
console.error(chalk5.cyan(verificationUri));
|
|
1920
1938
|
console.error("");
|
|
1921
1939
|
const open = await import("open").catch(() => null);
|
|
1922
1940
|
if (open) {
|
|
1923
1941
|
try {
|
|
1924
1942
|
await open.default(verificationUri);
|
|
1925
|
-
console.log(
|
|
1943
|
+
console.log(chalk5.dim(" Browser opened automatically"));
|
|
1926
1944
|
} catch {
|
|
1927
|
-
console.log(
|
|
1945
|
+
console.log(chalk5.dim(" Please copy link to browser"));
|
|
1928
1946
|
}
|
|
1929
1947
|
} else {
|
|
1930
|
-
console.log(
|
|
1948
|
+
console.log(chalk5.dim(" Please copy link to browser"));
|
|
1931
1949
|
}
|
|
1932
1950
|
console.log("");
|
|
1933
|
-
console.log(
|
|
1934
|
-
console.log(
|
|
1935
|
-
console.log(
|
|
1936
|
-
console.log(
|
|
1951
|
+
console.log(chalk5.dim("\u2550".repeat(50)));
|
|
1952
|
+
console.log(chalk5.dim(` Device Code: ${deviceCode}`));
|
|
1953
|
+
console.log(chalk5.dim(` Expires in: ${expiresIn} seconds`));
|
|
1954
|
+
console.log(chalk5.dim("\u2550".repeat(50)));
|
|
1937
1955
|
console.log("");
|
|
1938
1956
|
const tokens = await adapter.pollToken(deviceCode);
|
|
1939
1957
|
await saveToken(tokens.accessToken, tokens.refreshToken);
|
|
1940
1958
|
console.log("");
|
|
1941
|
-
console.log(
|
|
1959
|
+
console.log(chalk5.bgGreen.black.bold(" [OK] Login Successful "));
|
|
1942
1960
|
console.log("");
|
|
1943
|
-
console.log(
|
|
1961
|
+
console.log(chalk5.green("[OK] Tokens saved securely"));
|
|
1944
1962
|
printEnvironmentInfo(env, envConfig.displayName);
|
|
1945
|
-
console.log(
|
|
1963
|
+
console.log(chalk5.dim(`Access Token expires in: ${Math.floor(tokens.expiresIn / 60)} minutes`));
|
|
1946
1964
|
console.log("");
|
|
1947
|
-
console.log(
|
|
1965
|
+
console.log(chalk5.dim("Next:"), chalk5.cyan("wukong-cli auth status"));
|
|
1948
1966
|
console.log("");
|
|
1949
1967
|
} catch (error) {
|
|
1950
1968
|
if (error instanceof ConfigFileError) {
|
|
1951
1969
|
console.log("");
|
|
1952
|
-
console.log(
|
|
1970
|
+
console.log(chalk5.red(`[ERROR] Configuration Error`));
|
|
1953
1971
|
console.log("");
|
|
1954
|
-
console.log(
|
|
1972
|
+
console.log(chalk5.red(error.toUserMessage()));
|
|
1955
1973
|
console.log("");
|
|
1956
1974
|
return;
|
|
1957
1975
|
}
|
|
1958
1976
|
console.log("");
|
|
1959
|
-
console.log(
|
|
1977
|
+
console.log(chalk5.red(`[ERROR] ${error instanceof Error ? error.message : "Unknown error"}`));
|
|
1960
1978
|
console.log("");
|
|
1961
1979
|
}
|
|
1962
1980
|
});
|
|
@@ -1971,11 +1989,11 @@ authCommands.command("logout").description("Logout and clear saved tokens").acti
|
|
|
1971
1989
|
await logout(accessToken);
|
|
1972
1990
|
}
|
|
1973
1991
|
console.log("");
|
|
1974
|
-
console.log(
|
|
1992
|
+
console.log(chalk5.green(`[OK] Logged out from ${env}`), chalk5.dim(`(${envConfig.displayName})`));
|
|
1975
1993
|
console.log("");
|
|
1976
1994
|
} catch {
|
|
1977
1995
|
console.log("");
|
|
1978
|
-
console.log(
|
|
1996
|
+
console.log(chalk5.yellow(`\u25CB Already logged out from ${env}`), chalk5.dim(`(${envConfig.displayName})`));
|
|
1979
1997
|
console.log("");
|
|
1980
1998
|
}
|
|
1981
1999
|
});
|
|
@@ -1988,10 +2006,10 @@ authCommands.command("refresh").description("Manually refresh access token").act
|
|
|
1988
2006
|
const accessToken = await getAccessToken();
|
|
1989
2007
|
if (!accessToken) {
|
|
1990
2008
|
console.log("");
|
|
1991
|
-
console.log(
|
|
2009
|
+
console.log(chalk5.yellow("[ERROR] Not authenticated"));
|
|
1992
2010
|
printEnvironmentInfo(env, envConfig.displayName);
|
|
1993
2011
|
console.log("");
|
|
1994
|
-
console.log(
|
|
2012
|
+
console.log(chalk5.dim(`Run: wukong-cli auth login`));
|
|
1995
2013
|
console.log("");
|
|
1996
2014
|
return;
|
|
1997
2015
|
}
|
|
@@ -2002,7 +2020,7 @@ authCommands.command("refresh").description("Manually refresh access token").act
|
|
|
2002
2020
|
spinner.succeed("Token refreshed successfully!");
|
|
2003
2021
|
console.log("");
|
|
2004
2022
|
printEnvironmentInfo(env, envConfig.displayName);
|
|
2005
|
-
console.log(
|
|
2023
|
+
console.log(chalk5.dim("New tokens saved securely"));
|
|
2006
2024
|
console.log("");
|
|
2007
2025
|
} catch (error) {
|
|
2008
2026
|
spinner.fail("Token refresh failed");
|
|
@@ -2011,18 +2029,18 @@ authCommands.command("refresh").description("Manually refresh access token").act
|
|
|
2011
2029
|
} catch (error) {
|
|
2012
2030
|
if (error instanceof ConfigFileError) {
|
|
2013
2031
|
console.log("");
|
|
2014
|
-
console.log(
|
|
2032
|
+
console.log(chalk5.red(`[ERROR] Configuration Error`));
|
|
2015
2033
|
console.log("");
|
|
2016
|
-
console.log(
|
|
2034
|
+
console.log(chalk5.red(error.toUserMessage()));
|
|
2017
2035
|
console.log("");
|
|
2018
2036
|
return;
|
|
2019
2037
|
}
|
|
2020
2038
|
console.log("");
|
|
2021
|
-
console.log(
|
|
2039
|
+
console.log(chalk5.red(`[ERROR] ${error instanceof Error ? error.message : "Unknown error"}`));
|
|
2022
2040
|
console.log("");
|
|
2023
2041
|
printEnvironmentInfo(env, envConfig.displayName);
|
|
2024
|
-
console.log(
|
|
2025
|
-
console.log(
|
|
2042
|
+
console.log(chalk5.dim(`Your session may have expired. Please run:`));
|
|
2043
|
+
console.log(chalk5.dim(` wukong-cli auth login`));
|
|
2026
2044
|
console.log("");
|
|
2027
2045
|
}
|
|
2028
2046
|
});
|
|
@@ -2036,10 +2054,10 @@ authCommands.command("status").description("Show authentication status").action(
|
|
|
2036
2054
|
const config = getOceanetConfig();
|
|
2037
2055
|
const accessToken = await getAccessToken();
|
|
2038
2056
|
if (!accessToken) {
|
|
2039
|
-
console.log(
|
|
2057
|
+
console.log(chalk5.yellow(`[ERROR] Not authenticated`));
|
|
2040
2058
|
console.log("");
|
|
2041
2059
|
printEnvironmentInfo(env, envConfig.displayName);
|
|
2042
|
-
console.log(
|
|
2060
|
+
console.log(chalk5.dim(`Run: wukong-cli auth login`));
|
|
2043
2061
|
console.log("");
|
|
2044
2062
|
return;
|
|
2045
2063
|
}
|
|
@@ -2047,37 +2065,37 @@ authCommands.command("status").description("Show authentication status").action(
|
|
|
2047
2065
|
const client = getClient();
|
|
2048
2066
|
const userInfoUrl = `${config.AUTH_BASE_URL}/oceanet-auth/web/userInfo`;
|
|
2049
2067
|
const userInfo = await client.get(userInfoUrl);
|
|
2050
|
-
console.log(
|
|
2068
|
+
console.log(chalk5.green("[OK] Authenticated"));
|
|
2051
2069
|
console.log("");
|
|
2052
2070
|
const displayUser = userInfo.firstName ? `${userInfo.firstName} (${userInfo.username})` : userInfo.username || "N/A";
|
|
2053
2071
|
printEnvironmentInfo(env, envConfig.displayName);
|
|
2054
|
-
console.log(
|
|
2055
|
-
console.log(
|
|
2056
|
-
console.log(
|
|
2057
|
-
console.log(
|
|
2072
|
+
console.log(chalk5.dim("User:"), chalk5.cyan(displayUser));
|
|
2073
|
+
console.log(chalk5.dim("Email:"), chalk5.cyan(userInfo.email || "N/A"));
|
|
2074
|
+
console.log(chalk5.dim("OrgCode:"), chalk5.cyan(userInfo.ouCode || "N/A"));
|
|
2075
|
+
console.log(chalk5.dim("OrgName:"), chalk5.cyan(userInfo.ouName || "N/A"));
|
|
2058
2076
|
console.log("");
|
|
2059
2077
|
} catch (error) {
|
|
2060
2078
|
const errorMsg = error instanceof Error ? error.message : String(error);
|
|
2061
|
-
console.log(
|
|
2079
|
+
console.log(chalk5.yellow(`[ERROR] Not authenticated`));
|
|
2062
2080
|
console.log("");
|
|
2063
|
-
console.log(
|
|
2081
|
+
console.log(chalk5.red("Error:"), chalk5.dim(errorMsg));
|
|
2064
2082
|
console.log("");
|
|
2065
2083
|
printEnvironmentInfo(env, envConfig.displayName);
|
|
2066
|
-
console.log(
|
|
2084
|
+
console.log(chalk5.dim(`Run: wukong-cli auth login`));
|
|
2067
2085
|
console.log("");
|
|
2068
2086
|
}
|
|
2069
2087
|
} catch (error) {
|
|
2070
2088
|
if (error instanceof ConfigFileError) {
|
|
2071
|
-
console.log(
|
|
2089
|
+
console.log(chalk5.red(`[ERROR] Configuration Error`));
|
|
2072
2090
|
console.log("");
|
|
2073
|
-
console.log(
|
|
2091
|
+
console.log(chalk5.red(error.toUserMessage()));
|
|
2074
2092
|
console.log("");
|
|
2075
2093
|
return;
|
|
2076
2094
|
}
|
|
2077
|
-
console.log(
|
|
2095
|
+
console.log(chalk5.yellow(`\u2717 Not authenticated`));
|
|
2078
2096
|
console.log("");
|
|
2079
2097
|
printEnvironmentInfo(env, envConfig.displayName);
|
|
2080
|
-
console.log(
|
|
2098
|
+
console.log(chalk5.dim(`Run: wukong-cli auth login`));
|
|
2081
2099
|
console.log("");
|
|
2082
2100
|
}
|
|
2083
2101
|
});
|
|
@@ -2086,7 +2104,7 @@ authCommands.command("status").description("Show authentication status").action(
|
|
|
2086
2104
|
init_esm_shims();
|
|
2087
2105
|
import { Command as Command2 } from "commander";
|
|
2088
2106
|
import ora4 from "ora";
|
|
2089
|
-
import
|
|
2107
|
+
import chalk6 from "chalk";
|
|
2090
2108
|
init_oceanet();
|
|
2091
2109
|
init_config_file_error();
|
|
2092
2110
|
function fixGitBashPath(url) {
|
|
@@ -2135,14 +2153,14 @@ async function executeRequest(method, url, options) {
|
|
|
2135
2153
|
const accessToken = await getAccessToken();
|
|
2136
2154
|
if (!accessToken) {
|
|
2137
2155
|
spinner.fail("Not authenticated");
|
|
2138
|
-
console.error(
|
|
2156
|
+
console.error(chalk6.red("Please run: wukong-cli auth login"));
|
|
2139
2157
|
process.exit(1);
|
|
2140
2158
|
}
|
|
2141
2159
|
const fullUrl = buildUrl2(url, options.baseUrl);
|
|
2142
2160
|
const customHeaders = parseHeaders(options.headers);
|
|
2143
2161
|
const client = getClient();
|
|
2144
2162
|
const requestData = options.data ? JSON.parse(options.data) : void 0;
|
|
2145
|
-
spinner.text = `${method} ${
|
|
2163
|
+
spinner.text = `${method} ${chalk6.cyan(fullUrl)}`;
|
|
2146
2164
|
const startTime = Date.now();
|
|
2147
2165
|
let data;
|
|
2148
2166
|
switch (method.toUpperCase()) {
|
|
@@ -2168,29 +2186,29 @@ async function executeRequest(method, url, options) {
|
|
|
2168
2186
|
const duration = Date.now() - startTime;
|
|
2169
2187
|
spinner.succeed("Response received");
|
|
2170
2188
|
console.log("");
|
|
2171
|
-
console.log(
|
|
2189
|
+
console.log(chalk6.dim("Status:"), "200 OK");
|
|
2172
2190
|
console.log("");
|
|
2173
|
-
console.log(
|
|
2191
|
+
console.log(chalk6.dim("Response:"));
|
|
2174
2192
|
console.log(JSON.stringify(data, null, 2));
|
|
2175
2193
|
} catch (error) {
|
|
2176
2194
|
spinner.fail("Request failed");
|
|
2177
2195
|
if (error instanceof ConfigFileError) {
|
|
2178
2196
|
console.log("");
|
|
2179
|
-
console.log(
|
|
2197
|
+
console.log(chalk6.red(`[ERROR] Configuration Error`));
|
|
2180
2198
|
console.log("");
|
|
2181
|
-
console.log(
|
|
2199
|
+
console.log(chalk6.red(error.toUserMessage()));
|
|
2182
2200
|
console.log("");
|
|
2183
2201
|
process.exit(1);
|
|
2184
2202
|
}
|
|
2185
2203
|
if (error instanceof ApiError) {
|
|
2186
2204
|
console.log("");
|
|
2187
|
-
console.log(
|
|
2188
|
-
console.log(
|
|
2205
|
+
console.log(chalk6.red(`API Error (code: ${error.code})`));
|
|
2206
|
+
console.log(chalk6.red(error.message));
|
|
2189
2207
|
console.log("");
|
|
2190
2208
|
process.exit(1);
|
|
2191
2209
|
}
|
|
2192
2210
|
if (error instanceof Error) {
|
|
2193
|
-
console.error(
|
|
2211
|
+
console.error(chalk6.red(error.message));
|
|
2194
2212
|
}
|
|
2195
2213
|
process.exit(1);
|
|
2196
2214
|
}
|
|
@@ -2216,58 +2234,58 @@ httpCommand.command("delete <url>").description("Send DELETE request").option("-
|
|
|
2216
2234
|
// src/commands/init.ts
|
|
2217
2235
|
init_esm_shims();
|
|
2218
2236
|
import { Command as Command3 } from "commander";
|
|
2219
|
-
import { writeFileSync as
|
|
2220
|
-
import { join as
|
|
2221
|
-
import { homedir as
|
|
2237
|
+
import { writeFileSync as writeFileSync4, existsSync as existsSync3, readFileSync as readFileSync4, mkdirSync as mkdirSync4 } from "fs";
|
|
2238
|
+
import { join as join4, dirname as dirname4 } from "path";
|
|
2239
|
+
import { homedir as homedir4 } from "os";
|
|
2222
2240
|
import { fileURLToPath as fileURLToPath3 } from "url";
|
|
2223
|
-
import
|
|
2224
|
-
var CONFIG_DIR2 =
|
|
2225
|
-
var CONFIG_FILE_PATH2 =
|
|
2241
|
+
import chalk7 from "chalk";
|
|
2242
|
+
var CONFIG_DIR2 = join4(homedir4(), ".wukong-cli");
|
|
2243
|
+
var CONFIG_FILE_PATH2 = join4(CONFIG_DIR2, "wukong-cli.json");
|
|
2226
2244
|
function getProjectRoot2() {
|
|
2227
|
-
let currentDir =
|
|
2228
|
-
while (currentDir !==
|
|
2229
|
-
if (existsSync3(
|
|
2245
|
+
let currentDir = dirname4(fileURLToPath3(import.meta.url));
|
|
2246
|
+
while (currentDir !== dirname4(currentDir)) {
|
|
2247
|
+
if (existsSync3(join4(currentDir, "package.json"))) {
|
|
2230
2248
|
return currentDir;
|
|
2231
2249
|
}
|
|
2232
|
-
currentDir =
|
|
2250
|
+
currentDir = dirname4(currentDir);
|
|
2233
2251
|
}
|
|
2234
2252
|
return process.cwd();
|
|
2235
2253
|
}
|
|
2236
2254
|
function ensureConfigDir2() {
|
|
2237
2255
|
if (!existsSync3(CONFIG_DIR2)) {
|
|
2238
|
-
|
|
2256
|
+
mkdirSync4(CONFIG_DIR2, { recursive: true });
|
|
2239
2257
|
}
|
|
2240
2258
|
}
|
|
2241
2259
|
async function executeInit() {
|
|
2242
|
-
const templatePath =
|
|
2260
|
+
const templatePath = join4(getProjectRoot2(), "wukong-cli.json.template");
|
|
2243
2261
|
if (!existsSync3(templatePath)) {
|
|
2244
|
-
console.error(
|
|
2245
|
-
console.error(
|
|
2262
|
+
console.error(chalk7.red("\u274C Template configuration file not found"));
|
|
2263
|
+
console.error(chalk7.yellow(`Expected location: ${templatePath}`));
|
|
2246
2264
|
process.exit(1);
|
|
2247
2265
|
}
|
|
2248
2266
|
try {
|
|
2249
2267
|
ensureConfigDir2();
|
|
2250
|
-
const templateContent =
|
|
2268
|
+
const templateContent = readFileSync4(templatePath, "utf-8");
|
|
2251
2269
|
const configExists = existsSync3(CONFIG_FILE_PATH2);
|
|
2252
2270
|
if (configExists) {
|
|
2253
|
-
console.log(
|
|
2271
|
+
console.log(chalk7.yellow("\u26A0\uFE0F Existing configuration file will be overwritten"));
|
|
2254
2272
|
}
|
|
2255
|
-
|
|
2256
|
-
console.log(
|
|
2257
|
-
console.log(
|
|
2273
|
+
writeFileSync4(CONFIG_FILE_PATH2, templateContent, "utf-8");
|
|
2274
|
+
console.log(chalk7.green("\u2705 Configuration file created successfully"));
|
|
2275
|
+
console.log(chalk7.gray(`Location: ${CONFIG_FILE_PATH2}`));
|
|
2258
2276
|
if (configExists) {
|
|
2259
|
-
console.log(
|
|
2277
|
+
console.log(chalk7.yellow("Previous configuration has been overwritten"));
|
|
2260
2278
|
}
|
|
2261
2279
|
try {
|
|
2262
2280
|
const config = JSON.parse(templateContent);
|
|
2263
|
-
console.log(
|
|
2264
|
-
console.log(
|
|
2265
|
-
console.log(
|
|
2281
|
+
console.log(chalk7.gray("\nConfiguration preview:"));
|
|
2282
|
+
console.log(chalk7.gray(` Default Environment: ${config.defaultEnv}`));
|
|
2283
|
+
console.log(chalk7.gray(` Configured Environments: ${Object.keys(config.environments).join(", ")}`));
|
|
2266
2284
|
} catch (parseError) {
|
|
2267
2285
|
}
|
|
2268
2286
|
} catch (error) {
|
|
2269
|
-
console.error(
|
|
2270
|
-
console.error(
|
|
2287
|
+
console.error(chalk7.red("\u274C Failed to create configuration file"));
|
|
2288
|
+
console.error(chalk7.yellow(`Error: ${error}`));
|
|
2271
2289
|
process.exit(1);
|
|
2272
2290
|
}
|
|
2273
2291
|
}
|
|
@@ -2369,7 +2387,7 @@ async function runUpdateCommand({
|
|
|
2369
2387
|
}
|
|
2370
2388
|
var updateCommand = new Command4("update").description("Update wukong-cli to the latest npm version").action(async () => {
|
|
2371
2389
|
const exitCode = await runUpdateCommand({
|
|
2372
|
-
currentVersion: "0.4.
|
|
2390
|
+
currentVersion: "0.4.10",
|
|
2373
2391
|
versionProvider: new NpmVersionProvider(
|
|
2374
2392
|
"@zrhsh/wukong-cli",
|
|
2375
2393
|
"https://registry.npmjs.org"
|
|
@@ -2384,7 +2402,7 @@ var updateCommand = new Command4("update").description("Update wukong-cli to the
|
|
|
2384
2402
|
|
|
2385
2403
|
// src/cli.ts
|
|
2386
2404
|
var program = new Command5();
|
|
2387
|
-
program.name("wukong-cli").description("Wukong CLI - TypeScript implementation").version("0.4.
|
|
2405
|
+
program.name("wukong-cli").description("Wukong CLI - TypeScript implementation").version("0.4.10").option("--debug", "Enable debug mode (show HTTP requests)").hook("preAction", (thisCommand) => {
|
|
2388
2406
|
const options = thisCommand.opts();
|
|
2389
2407
|
if (options.debug === true) {
|
|
2390
2408
|
setDebugMode(true, true);
|
|
@@ -2402,8 +2420,9 @@ if (process.argv.length === 2) {
|
|
|
2402
2420
|
program.parse();
|
|
2403
2421
|
setImmediate(() => {
|
|
2404
2422
|
try {
|
|
2405
|
-
const versionChecker = getVersionChecker();
|
|
2406
|
-
|
|
2423
|
+
const versionChecker = getVersionChecker("0.4.10");
|
|
2424
|
+
const notifier = new ConsoleNotifier();
|
|
2425
|
+
versionChecker.checkInBackground(notifier).catch(() => {
|
|
2407
2426
|
});
|
|
2408
2427
|
} catch {
|
|
2409
2428
|
}
|