@zrhsh/wukong-cli 0.4.19 → 0.4.20

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zrhsh/wukong-cli",
3
- "version": "0.4.19",
3
+ "version": "0.4.20",
4
4
  "description": "Wukong CLI - TypeScript with auto token refresh",
5
5
  "private": false,
6
6
  "type": "module",
@@ -1,83 +1,83 @@
1
- /**
2
- * 安装脚本 - 配置文件迁移和创建
3
- * 在 npm install/update 时自动执行
4
- */
5
-
6
- import { writeFileSync, existsSync, mkdirSync, readFileSync, unlinkSync } from 'fs';
7
- import { join, dirname } from 'path';
8
- import { fileURLToPath } from 'url';
9
- import { homedir } from 'os';
10
-
11
- const __filename = fileURLToPath(import.meta.url);
12
- const __dirname = dirname(__filename);
13
-
14
- const TEMPLATE_FILE = join(__dirname, '../wukong-cli.json.template');
15
- const LEGACY_CONFIG_PATH = join(homedir(), 'wukong-cli.json');
16
- const CONFIG_DIR = join(homedir(), '.wukong-cli');
17
- const CONFIG_FILE_PATH = join(CONFIG_DIR, 'wukong-cli.json');
18
-
19
- /**
20
- * 确保配置目录存在
21
- */
22
- function ensureConfigDir() {
23
- if (!existsSync(CONFIG_DIR)) {
24
- mkdirSync(CONFIG_DIR, { recursive: true });
25
- }
26
- }
27
-
28
- /**
29
- * 迁移旧配置(针对老用户)
30
- */
31
- function migrateLegacyConfig() {
32
- // 旧配置存在 + 新配置不存在 → 迁移
33
- if (existsSync(LEGACY_CONFIG_PATH) && !existsSync(CONFIG_FILE_PATH)) {
34
- try {
35
- ensureConfigDir();
36
- const oldConfig = readFileSync(LEGACY_CONFIG_PATH, 'utf-8');
37
- writeFileSync(CONFIG_FILE_PATH, oldConfig, 'utf-8');
38
- unlinkSync(LEGACY_CONFIG_PATH);
39
-
40
- console.log('✓ Migrated configuration to new location');
41
- console.log('✓ Old config removed:', LEGACY_CONFIG_PATH);
42
- console.log('✓ New location:', CONFIG_FILE_PATH);
43
- return true;
44
- } catch (error) {
45
- console.warn('⚠ Migration failed:', error.message);
46
- return false;
47
- }
48
- }
49
- return false;
50
- }
51
-
52
- /**
53
- * 创建默认配置(针对新用户)
54
- */
55
- function createDefaultConfig() {
56
- // 新配置已存在 → 不覆盖
57
- if (existsSync(CONFIG_FILE_PATH)) {
58
- return;
59
- }
60
-
61
- // 新配置不存在 → 在新位置创建
62
- try {
63
- if (!existsSync(TEMPLATE_FILE)) {
64
- console.warn('⚠ Template not found:', TEMPLATE_FILE);
65
- console.warn('⚠ Create config manually at:', CONFIG_FILE_PATH);
66
- return;
67
- }
68
-
69
- ensureConfigDir();
70
- const templateContent = readFileSync(TEMPLATE_FILE, 'utf-8');
71
- writeFileSync(CONFIG_FILE_PATH, templateContent, 'utf-8');
72
-
73
- console.log('✓ Created default config:', CONFIG_FILE_PATH);
74
- } catch (error) {
75
- console.warn('⚠ Failed to create config:', error.message);
76
- }
77
- }
78
-
79
- // 主逻辑:先尝试迁移,无需迁移时创建默认配置
80
- const migrated = migrateLegacyConfig();
81
- if (!migrated) {
82
- createDefaultConfig();
83
- }
1
+ /**
2
+ * 安装脚本 - 配置文件迁移和创建
3
+ * 在 npm install/update 时自动执行
4
+ */
5
+
6
+ import { writeFileSync, existsSync, mkdirSync, readFileSync, unlinkSync } from 'fs';
7
+ import { join, dirname } from 'path';
8
+ import { fileURLToPath } from 'url';
9
+ import { homedir } from 'os';
10
+
11
+ const __filename = fileURLToPath(import.meta.url);
12
+ const __dirname = dirname(__filename);
13
+
14
+ const TEMPLATE_FILE = join(__dirname, '../wukong-cli.json.template');
15
+ const LEGACY_CONFIG_PATH = join(homedir(), 'wukong-cli.json');
16
+ const CONFIG_DIR = join(homedir(), '.wukong-cli');
17
+ const CONFIG_FILE_PATH = join(CONFIG_DIR, 'wukong-cli.json');
18
+
19
+ /**
20
+ * 确保配置目录存在
21
+ */
22
+ function ensureConfigDir() {
23
+ if (!existsSync(CONFIG_DIR)) {
24
+ mkdirSync(CONFIG_DIR, { recursive: true });
25
+ }
26
+ }
27
+
28
+ /**
29
+ * 迁移旧配置(针对老用户)
30
+ */
31
+ function migrateLegacyConfig() {
32
+ // 旧配置存在 + 新配置不存在 → 迁移
33
+ if (existsSync(LEGACY_CONFIG_PATH) && !existsSync(CONFIG_FILE_PATH)) {
34
+ try {
35
+ ensureConfigDir();
36
+ const oldConfig = readFileSync(LEGACY_CONFIG_PATH, 'utf-8');
37
+ writeFileSync(CONFIG_FILE_PATH, oldConfig, 'utf-8');
38
+ unlinkSync(LEGACY_CONFIG_PATH);
39
+
40
+ console.log('✓ Migrated configuration to new location');
41
+ console.log('✓ Old config removed:', LEGACY_CONFIG_PATH);
42
+ console.log('✓ New location:', CONFIG_FILE_PATH);
43
+ return true;
44
+ } catch (error) {
45
+ console.warn('⚠ Migration failed:', error.message);
46
+ return false;
47
+ }
48
+ }
49
+ return false;
50
+ }
51
+
52
+ /**
53
+ * 创建默认配置(针对新用户)
54
+ */
55
+ function createDefaultConfig() {
56
+ // 新配置已存在 → 不覆盖
57
+ if (existsSync(CONFIG_FILE_PATH)) {
58
+ return;
59
+ }
60
+
61
+ // 新配置不存在 → 在新位置创建
62
+ try {
63
+ if (!existsSync(TEMPLATE_FILE)) {
64
+ console.warn('⚠ Template not found:', TEMPLATE_FILE);
65
+ console.warn('⚠ Create config manually at:', CONFIG_FILE_PATH);
66
+ return;
67
+ }
68
+
69
+ ensureConfigDir();
70
+ const templateContent = readFileSync(TEMPLATE_FILE, 'utf-8');
71
+ writeFileSync(CONFIG_FILE_PATH, templateContent, 'utf-8');
72
+
73
+ console.log('✓ Created default config:', CONFIG_FILE_PATH);
74
+ } catch (error) {
75
+ console.warn('⚠ Failed to create config:', error.message);
76
+ }
77
+ }
78
+
79
+ // 主逻辑:先尝试迁移,无需迁移时创建默认配置
80
+ const migrated = migrateLegacyConfig();
81
+ if (!migrated) {
82
+ createDefaultConfig();
83
+ }
@@ -1,25 +1,25 @@
1
- {
2
- "defaultEnv": "prod",
3
- "environments": {
4
- "dev": {
5
- "authBaseUrl": "https://portal-dev.zrhsh.com",
6
- "apiBaseUrl": "https://nrp-dev.zrhsh.com",
7
- "clientId": "wukong-cli-dev"
8
- },
9
- "beta": {
10
- "authBaseUrl": "https://portal-beta.zrhsh.com",
11
- "apiBaseUrl": "https://nrp-recode.zrhsh.com",
12
- "clientId": "wukong-cli-beta"
13
- },
14
- "uat": {
15
- "authBaseUrl": "https://portal-uat.zrhsh.com",
16
- "apiBaseUrl": "https://nrp-pd.zrhsh.com",
17
- "clientId": "wukong-cli-uat"
18
- },
19
- "prod": {
20
- "authBaseUrl": "https://portal.zrhsh.com",
21
- "apiBaseUrl": "https://nrp.zrhsh.com",
22
- "clientId": "wukong-cli-prod"
23
- }
24
- }
25
- }
1
+ {
2
+ "defaultEnv": "prod",
3
+ "environments": {
4
+ "dev": {
5
+ "authBaseUrl": "https://portal-dev.zrhsh.com",
6
+ "apiBaseUrl": "https://nrp-dev.zrhsh.com",
7
+ "clientId": "wukong-cli-dev"
8
+ },
9
+ "beta": {
10
+ "authBaseUrl": "https://portal-beta.zrhsh.com",
11
+ "apiBaseUrl": "https://nrp-recode.zrhsh.com",
12
+ "clientId": "wukong-cli-beta"
13
+ },
14
+ "uat": {
15
+ "authBaseUrl": "https://portal-uat.zrhsh.com",
16
+ "apiBaseUrl": "https://nrp-pd.zrhsh.com",
17
+ "clientId": "wukong-cli-uat"
18
+ },
19
+ "prod": {
20
+ "authBaseUrl": "https://portal.zrhsh.com",
21
+ "apiBaseUrl": "https://nrp.zrhsh.com",
22
+ "clientId": "wukong-cli-prod"
23
+ }
24
+ }
25
+ }