prime-dev-cli 1.0.9 → 1.0.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/bin/cli.mjs CHANGED
@@ -7,6 +7,7 @@ import path from 'node:path';
7
7
  import os from 'node:os';
8
8
  import lodash from 'lodash';
9
9
  import { fileURLToPath } from 'node:url';
10
+ import simpleGit from 'simple-git';
10
11
 
11
12
  const __filename = fileURLToPath(import.meta.url);
12
13
  const __dirname = path.dirname(__filename);
@@ -14,20 +15,24 @@ const pkg = JSON.parse(fs.readFileSync(path.join(__dirname, '..', 'package.json'
14
15
 
15
16
  const command = process.argv[2];
16
17
 
17
- if(command === 'init') {
18
- setProjectsFile()
19
- }else if (command === 'ui') {
20
- setProjectsFile()
21
- startServer()
22
- }
23
- else if (command === 'help') {
24
- helpStdout()
25
- }else if (command === 'version') {
26
- console.log(`prime-cli ${pkg.version}`);
27
- }else {
28
- helpStdout()
18
+ async function main() {
19
+ if(command === 'init') {
20
+ await setProjectsFile()
21
+ }else if (command === 'ui') {
22
+ await setProjectsFile()
23
+ startServer()
24
+ }
25
+ else if (command === 'help') {
26
+ helpStdout()
27
+ }else if (command === 'version') {
28
+ console.log(`prime-cli ${pkg.version}`);
29
+ }else {
30
+ helpStdout()
31
+ }
29
32
  }
30
33
 
34
+ main().catch(console.error);
35
+
31
36
  function helpStdout() {
32
37
  console.log(`Usage: prime <command>
33
38
  prime-cli ${pkg.version}
@@ -64,30 +69,136 @@ function startServer(){
64
69
  }
65
70
 
66
71
  // 设置环境文件
67
- function setProjectsFile(){
72
+ async function setProjectsFile(){
68
73
  const __filename = fileURLToPath(import.meta.url);
69
74
  const __dirname = path.dirname(__filename);
70
- const sourcePath = path.join(__dirname, '..', 'config', 'projects.json');
75
+
76
+ // GitLab 仓库配置
77
+ const GITLAB_REPO = 'https://gitlab.primelifescience.com.cn/prime-direct/fe/dev-config-source.git';
78
+ const CONFIG_SOURCE_PATH = 'prime-dev-cli/config/projects.json';
79
+
80
+ // 本地路径配置
81
+ const tempRepoDir = path.join(os.tmpdir(), 'prime-dev-config-source');
82
+ const localConfigPath = path.join(__dirname, '..', 'config', 'projects.json');
71
83
  const destPath = path.join(os.homedir(), '.prime-projects.json');
84
+ const commitHashFile = path.join(os.homedir(), '.prime-projects-commit');
72
85
 
73
- if (!fs.existsSync(destPath)) {
74
- fs.copyFileSync(sourcePath, destPath);
75
- console.log('默认配置文件已创建在: ' + destPath);
76
- } else {
77
- try {
78
- const sourceData = fs.readFileSync(sourcePath, 'utf8');
79
- const destData = fs.readFileSync(destPath, 'utf8');
86
+ try {
87
+ console.log('正在检查配置更新...');
88
+
89
+ // 初始化 git 客户端
90
+ const git = simpleGit();
91
+
92
+ let needsUpdate = false;
93
+ let latestCommitHash = '';
94
+
95
+ // 检查临时仓库是否存在
96
+ if (fs.existsSync(tempRepoDir)) {
97
+ // 仓库已存在,检查是否有更新
98
+ const repoGit = simpleGit(tempRepoDir);
99
+
100
+ try {
101
+ // 拉取最新更改
102
+ await repoGit.fetch();
103
+
104
+ // 获取远程 master 分支的最新提交哈希
105
+ const remoteLog = await repoGit.log(['origin/master', '-1']);
106
+ latestCommitHash = remoteLog.latest.hash;
107
+
108
+ // 读取本地保存的提交哈希
109
+ let localCommitHash = '';
110
+ if (fs.existsSync(commitHashFile)) {
111
+ localCommitHash = fs.readFileSync(commitHashFile, 'utf8').trim();
112
+ }
113
+
114
+ // 比较提交哈希
115
+ if (localCommitHash !== latestCommitHash) {
116
+ needsUpdate = true;
117
+ console.log('发现配置更新,正在拉取...');
118
+
119
+ // 拉取最新代码
120
+ await repoGit.pull('origin', 'master');
121
+ } else {
122
+ console.log('配置已是最新版本,无需更新');
123
+ }
124
+ } catch (error) {
125
+ console.log('检查更新失败,重新克隆仓库...');
126
+ // 删除损坏的仓库目录
127
+ fs.rmSync(tempRepoDir, { recursive: true, force: true });
128
+ needsUpdate = true;
129
+ }
130
+ } else {
131
+ // 仓库不存在,需要克隆
132
+ needsUpdate = true;
133
+ console.log('首次拉取配置仓库...');
134
+ }
135
+
136
+ // 如果需要更新,克隆或重新克隆仓库
137
+ if (needsUpdate && !fs.existsSync(tempRepoDir)) {
138
+ await git.clone(GITLAB_REPO, tempRepoDir);
139
+
140
+ // 获取最新提交哈希
141
+ const repoGit = simpleGit(tempRepoDir);
142
+ const log = await repoGit.log(['-1']);
143
+ latestCommitHash = log.latest.hash;
144
+ } else if (needsUpdate && fs.existsSync(tempRepoDir)) {
145
+ // 如果仓库存在但需要更新,获取更新后的提交哈希
146
+ const repoGit = simpleGit(tempRepoDir);
147
+ const log = await repoGit.log(['-1']);
148
+ latestCommitHash = log.latest.hash;
149
+ }
150
+
151
+ // 检查源配置文件是否存在
152
+ const sourceConfigPath = path.join(tempRepoDir, CONFIG_SOURCE_PATH);
153
+ if (!fs.existsSync(sourceConfigPath)) {
154
+ throw new Error(`配置文件不存在: ${CONFIG_SOURCE_PATH}`);
155
+ }
156
+
157
+ // 如果需要更新或本地配置不存在,则进行更新
158
+ if (needsUpdate || !fs.existsSync(destPath)) {
159
+ // 确保本地 config 目录存在
160
+ const configDir = path.dirname(localConfigPath);
161
+ if (!fs.existsSync(configDir)) {
162
+ fs.mkdirSync(configDir, { recursive: true });
163
+ }
164
+
165
+ // 复制配置文件到项目目录
166
+ fs.copyFileSync(sourceConfigPath, localConfigPath);
167
+ console.log('已更新项目配置文件: ' + localConfigPath);
168
+
169
+ // 处理用户配置文件
170
+ if (!fs.existsSync(destPath)) {
171
+ // 首次创建用户配置文件
172
+ fs.copyFileSync(sourceConfigPath, destPath);
173
+ console.log('默认配置文件已创建在: ' + destPath);
174
+ } else {
175
+ // 增量更新用户配置文件
176
+ const sourceData = fs.readFileSync(sourceConfigPath, 'utf8');
177
+ const destData = fs.readFileSync(destPath, 'utf8');
80
178
 
81
- const sourceJson = JSON.parse(sourceData);
82
- const destJson = JSON.parse(destData);
179
+ const sourceJson = JSON.parse(sourceData);
180
+ const destJson = JSON.parse(destData);
83
181
 
84
- const mergedJson = lodash.defaultsDeep(destJson, sourceJson);
182
+ const mergedJson = lodash.defaultsDeep(destJson, sourceJson);
85
183
 
86
- fs.writeFileSync(destPath, JSON.stringify(mergedJson, null, 2), 'utf8');
87
- console.log('配置文件已增量更新: ' + destPath);
88
- } catch (error) {
89
- console.error('更新配置文件时出错:', error);
184
+ fs.writeFileSync(destPath, JSON.stringify(mergedJson, null, 2), 'utf8');
185
+ console.log('配置文件已增量更新: ' + destPath);
186
+ }
187
+
188
+ // 保存最新的提交哈希
189
+ if (latestCommitHash) {
190
+ fs.writeFileSync(commitHashFile, latestCommitHash, 'utf8');
191
+ }
192
+ }
193
+
194
+ } catch (error) {
195
+ console.error('更新配置文件时出错:', error.message);
196
+
197
+ // 如果从 GitLab 拉取失败,尝试使用本地备份配置
198
+ const fallbackPath = path.join(__dirname, '..', 'config', 'projects.example.json');
199
+ if (fs.existsSync(fallbackPath) && !fs.existsSync(destPath)) {
200
+ fs.copyFileSync(fallbackPath, destPath);
201
+ console.log('使用本地备份配置文件: ' + destPath);
90
202
  }
91
203
  }
92
-
93
204
  }
@@ -0,0 +1,351 @@
1
+ {
2
+ "esource-fe": {
3
+ "repo": "https://gitlab.primelifescience.com.cn/prime-direct/fe/esource-fe.git",
4
+ "mockingIntercept": false,
5
+ "mockOpen": false,
6
+ "envs": {
7
+ "icrc": {
8
+ "host": "http://localhost:8806",
9
+ "currentProxy": "sit",
10
+ "proxyEnv": {
11
+ "dev": "http://icrc.dev.healthprime.cn",
12
+ "sit": "http://icrc.sit.healthprime.cn",
13
+ "uat": "https://icrc-uat.primelifescience.com.cn",
14
+ "prod": "https://icrc.primelifescience.com.cn",
15
+ "lpyy-uat": "http://icrc.lpyy-uat.healthprime.cn",
16
+ "custom": "http://localhost:8828"
17
+ },
18
+ "envFileName": ".env.dev.c.local",
19
+ "proxyKey": "PROXY_URL",
20
+ "subApps": [
21
+ "ilink-icrc"
22
+ ],
23
+ "startCommand": "npm run serve:c"
24
+ },
25
+ "idea": {
26
+ "host": "http://localhost:8807",
27
+ "currentProxy": "sit",
28
+ "proxyEnv": {
29
+ "dev": "http://idea.dev.healthprime.cn",
30
+ "sit": "http://idea.sit.healthprime.cn",
31
+ "uat": "https://idea-uat.primelifescience.com.cn",
32
+ "prod": "https://idea.primelifescience.com.cn",
33
+ "lpyy-uat": "http://idea.lpyy-uat.healthprime.cn",
34
+ "custom": "http://localhost:8828"
35
+ },
36
+ "envFileName": ".env.dev.h.local",
37
+ "proxyKey": "PROXY_URL",
38
+ "subApps": [
39
+ "ilink-idea"
40
+ ],
41
+ "startCommand": "npm run serve:h"
42
+ }
43
+ }
44
+ },
45
+ "ilink-fe": {
46
+ "mockingIntercept": false,
47
+ "repo": "https://gitlab.primelifescience.com.cn/prime-direct/fe/ilink-fe.git",
48
+ "mockOpen": false,
49
+ "envs": {
50
+ "ilink": {
51
+ "host": "http://localhost:8810",
52
+ "currentProxy": "sit",
53
+ "proxyEnv": {
54
+ "dev": "http://ilink.dev.healthprime.cn",
55
+ "sit": "http://ilink.sit.healthprime.cn",
56
+ "uat": "https://ilink-uat.primelifescience.com.cn",
57
+ "prod": "https://ilink.primelifescience.com.cn",
58
+ "lpyy-uat": "http://ilink.lpyy-uat.healthprime.cn",
59
+ "custom": "http://localhost:8828"
60
+ },
61
+ "envFileName": ".env.local",
62
+ "proxyKey": "PROXY_URL",
63
+ "subApps": [],
64
+ "startCommand": "npm run dev"
65
+ },
66
+ "ilink-icrc": {
67
+ "host": "http://localhost:8811",
68
+ "currentProxy": "sit",
69
+ "proxyEnv": {
70
+ "dev": "http://ilink.dev.healthprime.cn",
71
+ "sit": "http://ilink.sit.healthprime.cn",
72
+ "uat": "https://ilink-uat.primelifescience.com.cn",
73
+ "prod": "https://ilink.primelifescience.com.cn",
74
+ "lpyy-uat": "http://ilink.lpyy-uat.healthprime.cn",
75
+ "custom": "http://localhost:8828"
76
+ },
77
+ "envFileName": ".env.icrc.local",
78
+ "proxyKey": "PROXY_URL",
79
+ "subApps": [],
80
+ "startCommand": "npm run dev:icrc"
81
+ },
82
+ "ilink-idea": {
83
+ "host": "http://localhost:8812",
84
+ "currentProxy": "sit",
85
+ "proxyEnv": {
86
+ "dev": "http://ilink.dev.healthprime.cn",
87
+ "sit": "http://ilink.sit.healthprime.cn",
88
+ "uat": "https://ilink-uat.primelifescience.com.cn",
89
+ "prod": "https://ilink.primelifescience.com.cn",
90
+ "lpyy-uat": "http://ilink.lpyy-uat.healthprime.cn",
91
+ "custom": "http://localhost:8828"
92
+ },
93
+ "envFileName": ".env.idea.local",
94
+ "proxyKey": "PROXY_URL",
95
+ "subApps": [],
96
+ "startCommand": "npm run dev:idea"
97
+ },
98
+ "ilink-isource-site": {
99
+ "host": "http://localhost:8813",
100
+ "currentProxy": "sit",
101
+ "proxyEnv": {
102
+ "dev": "http://ilink.dev.healthprime.cn",
103
+ "sit": "http://ilink.sit.healthprime.cn",
104
+ "uat": "https://ilink-uat.primelifescience.com.cn",
105
+ "prod": "https://ilink.primelifescience.com.cn",
106
+ "lpyy-uat": "http://ilink.lpyy-uat.healthprime.cn",
107
+ "custom": "http://localhost:8828"
108
+ },
109
+ "envFileName": ".env.isource.local",
110
+ "proxyKey": "PROXY_URL",
111
+ "subApps": [],
112
+ "startCommand": "npm run dev:isource"
113
+ },
114
+ "ilink-ijudge": {
115
+ "host": "http://localhost:8814",
116
+ "currentProxy": "sit",
117
+ "proxyEnv": {
118
+ "dev": "http://ilink.dev.healthprime.cn",
119
+ "sit": "http://ilink.sit.healthprime.cn",
120
+ "uat": "https://ilink-uat.primelifescience.com.cn",
121
+ "prod": "https://ilink.primelifescience.com.cn",
122
+ "lpyy-uat": "http://ilink.lpyy-uat.healthprime.cn",
123
+ "custom": "http://localhost:8828"
124
+ },
125
+ "envFileName": ".env.ijudge.local",
126
+ "proxyKey": "PROXY_URL",
127
+ "subApps": [],
128
+ "startCommand": "npm run dev:ijudge"
129
+ },
130
+ "ilink-isource": {
131
+ "host": "http://localhost:8814",
132
+ "currentProxy": "sit",
133
+ "proxyEnv": {
134
+ "dev": "http://ilink.dev.healthprime.cn",
135
+ "sit": "http://ilink.sit.healthprime.cn",
136
+ "uat": "https://ilink-uat.primelifescience.com.cn",
137
+ "prod": "https://ilink.primelifescience.com.cn",
138
+ "lpyy-uat": "http://ilink.lpyy-uat.healthprime.cn",
139
+ "custom": "http://localhost:8828"
140
+ },
141
+ "envFileName": ".env.ijudge.local",
142
+ "proxyKey": "PROXY_URL",
143
+ "subApps": [],
144
+ "startCommand": "npm run dev:ijudge"
145
+ },
146
+ "ilink-iqc": {
147
+ "host": "http://localhost:8816",
148
+ "currentProxy": "sit",
149
+ "proxyEnv": {
150
+ "dev": "http://ilink.dev.healthprime.cn",
151
+ "sit": "http://ilink.sit.healthprime.cn",
152
+ "uat": "https://ilink-uat.primelifescience.com.cn",
153
+ "prod": "https://ilink.primelifescience.com.cn",
154
+ "lpyy-uat": "http://ilink.lpyy-uat.healthprime.cn",
155
+ "custom": "http://localhost:8828"
156
+ },
157
+ "envFileName": ".env.iqc.local",
158
+ "proxyKey": "PROXY_URL",
159
+ "subApps": [],
160
+ "startCommand": "npm run dev:iqc"
161
+ }
162
+ }
163
+ },
164
+ "iqc-fe": {
165
+ "mockingIntercept": false,
166
+ "repo": "https://gitlab.primelifescience.com.cn/prime-direct/fe/iqc-fe.git",
167
+ "mockOpen": true,
168
+ "envs": {
169
+ "iqc": {
170
+ "host": "http://localhost:8828",
171
+ "currentProxy": "sit",
172
+ "proxyEnv": {
173
+ "dev": "http://iqc.dev.healthprime.cn",
174
+ "sit": "http://iqc.sit.healthprime.cn",
175
+ "uat": "https://iqc-uat.primelifescience.com.cn",
176
+ "prod": "https://iqc.primelifescience.com.cn",
177
+ "lpyy-uat": "http://iqc.lpyy-uat.healthprime.cn",
178
+ "custom": ""
179
+ },
180
+ "envFileName": ".env.local",
181
+ "proxyKey": "PROXY_URL",
182
+ "subApps": [
183
+ "ilink-iqc"
184
+ ],
185
+ "startCommand": "npm run dev"
186
+ }
187
+ }
188
+ },
189
+ "auth-common": {
190
+ "repo": "https://gitlab.primelifescience.com.cn/prime-front/auth-common.git",
191
+ "mockingIntercept": false,
192
+ "mockOpen": false,
193
+ "envs": {
194
+ "icrc-auth": {
195
+ "host": "http://localhost:8815",
196
+ "currentProxy": "sit",
197
+ "proxyEnv": {
198
+ "dev": "http://icrc-auth.dev.healthprime.cn",
199
+ "sit": "http://icrc-auth.sit.healthprime.cn",
200
+ "uat": "https://icrc-auth-uat.primelifescience.com.cn",
201
+ "prod": "https://icrc-auth.primelifescience.com.cn",
202
+ "custom": ""
203
+ },
204
+ "envFileName": ".env.local",
205
+ "proxyKey": "PROXY_URL",
206
+ "subApps": [],
207
+ "startCommand": "npm run dev"
208
+ },
209
+ "idea-auth": {
210
+ "host": "http://localhost:8815",
211
+ "currentProxy": "sit",
212
+ "proxyEnv": {
213
+ "dev": "http://idea-auth.dev.healthprime.cn",
214
+ "sit": "http://idea-auth.sit.healthprime.cn",
215
+ "uat": "https://idea-auth-uat.primelifescience.com.cn",
216
+ "prod": "https://idea-auth.primelifescience.com.cn",
217
+ "lpyy-uat": "http://idea-auth.lpyy-uat.healthprime.cn",
218
+ "custom": ""
219
+ },
220
+ "envFileName": ".env.local",
221
+ "proxyKey": "PROXY_URL",
222
+ "subApps": [],
223
+ "startCommand": "npm run dev"
224
+ }
225
+ }
226
+ },
227
+ "igcp-fe": {
228
+ "repo": "https://gitlab.primelifescience.com.cn/prime-direct/fe/igcp-fe.git",
229
+ "mockingIntercept": false,
230
+ "mockOpen": false,
231
+ "envs": {
232
+ "igcp": {
233
+ "host": "http://localhost:8825",
234
+ "currentProxy": "sit",
235
+ "proxyEnv": {
236
+ "dev": "http://igcp.dev.healthprime.cn",
237
+ "sit": "http://igcp.sit.healthprime.cn",
238
+ "uat": "https://igcp-uat.primelifescience.com.cn",
239
+ "prod": "https://igcp.primelifescience.com.cn",
240
+ "custom": ""
241
+ },
242
+ "envFileName": ".env.local",
243
+ "proxyKey": "PROXY_URL",
244
+ "subApps": [],
245
+ "startCommand": "npm run dev"
246
+ }
247
+ }
248
+ },
249
+ "isource-fe": {
250
+ "repo": "https://gitlab.primelifescience.com.cn/prime-direct/fe/isource-fe.git",
251
+ "mockingIntercept": false,
252
+ "mockOpen": false,
253
+ "envs": {
254
+ "ijudge": {
255
+ "host": "http://localhost:8819",
256
+ "currentProxy": "sit",
257
+ "proxyEnv": {
258
+ "dev": "http://ijudge.dev.healthprime.cn",
259
+ "sit": "http://ijudge.sit.healthprime.cn",
260
+ "uat": "https://ijudge-uat.primelifescience.com.cn",
261
+ "prod": "https://ijudge.primelifescience.com.cn",
262
+ "custom": ""
263
+ },
264
+ "envFileName": ".env.center.local",
265
+ "proxyKey": "PROXY_URL",
266
+ "subApps": [
267
+ "ilink-ijudge"
268
+ ],
269
+ "startCommand": "npm run dev:c"
270
+ },
271
+ "isource": {
272
+ "host": "http://localhost:8819",
273
+ "currentProxy": "sit",
274
+ "proxyEnv": {
275
+ "dev": "http://isource.dev.healthprime.cn",
276
+ "sit": "http://isource.sit.healthprime.cn",
277
+ "uat": "https://isource-uat.primelifescience.com.cn",
278
+ "prod": "https://isource.primelifescience.com.cn",
279
+ "custom": ""
280
+ },
281
+ "envFileName": ".env.center.local",
282
+ "proxyKey": "PROXY_URL",
283
+ "subApps": [
284
+ "ilink-isource"
285
+ ],
286
+ "startCommand": "npm run dev:c"
287
+ },
288
+ "isource-site": {
289
+ "host": "http://localhost:8818",
290
+ "currentProxy": "sit",
291
+ "proxyEnv": {
292
+ "dev": "http://isource-site.dev.healthprime.cn",
293
+ "sit": "http://isource-site.sit.healthprime.cn",
294
+ "uat": "https://isource-site-uat.primelifescience.com.cn",
295
+ "prod": "https://isource-site.primelifescience.com.cn",
296
+ "custom": ""
297
+ },
298
+ "envFileName": ".env.hospital.local",
299
+ "proxyKey": "PROXY_URL",
300
+ "subApps": [
301
+ "ilink-isource"
302
+ ],
303
+ "startCommand": "npm run dev:h"
304
+ }
305
+ }
306
+ },
307
+ "iua-fe": {
308
+ "repo": "https://gitlab.primelifescience.com.cn/prime-direct/fe/iua-fe.git",
309
+ "mockingIntercept": false,
310
+ "mockOpen": false,
311
+ "envs": {
312
+ "iua": {
313
+ "host": "http://localhost:8020",
314
+ "currentProxy": "sit",
315
+ "proxyEnv": {
316
+ "dev": "http://iua.dev.healthprime.cn",
317
+ "sit": "http://iua.sit.healthprime.cn",
318
+ "uat": "https://iua-uat.primelifescience.com.cn",
319
+ "prod": "https://iua.primelifescience.com.cn",
320
+ "custom": ""
321
+ },
322
+ "envFileName": ".env.local",
323
+ "proxyKey": "PROXY_URL",
324
+ "subApps": [],
325
+ "startCommand": "npm run dev"
326
+ }
327
+ }
328
+ },
329
+ "ikg-fe": {
330
+ "repo": "https://gitlab.primelifescience.com.cn/prime-one/fe/ikg-fe.git",
331
+ "mockingIntercept": false,
332
+ "mockOpen": false,
333
+ "envs": {
334
+ "iua": {
335
+ "host": "http://localhost:7800",
336
+ "currentProxy": "sit",
337
+ "proxyEnv": {
338
+ "dev": "http://ikg.dev.healthprime.cn",
339
+ "sit": "http://ikg.sit.healthprime.cn",
340
+ "uat": "https://ikg-uat.primelifescience.com.cn",
341
+ "prod": "https://ikg.primelifescience.com.cn",
342
+ "custom": ""
343
+ },
344
+ "envFileName": ".env.local",
345
+ "proxyKey": "PROXY_URL",
346
+ "subApps": [],
347
+ "startCommand": "npm run dev"
348
+ }
349
+ }
350
+ }
351
+ }