@hecom/codearts 0.1.0
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/.env.example +20 -0
- package/README.md +228 -0
- package/bin/codearts +2 -0
- package/dist/bin/cli.d.ts +2 -0
- package/dist/bin/cli.js +137 -0
- package/dist/commands/config.command.d.ts +5 -0
- package/dist/commands/config.command.js +109 -0
- package/dist/commands/daily.command.d.ts +10 -0
- package/dist/commands/daily.command.js +184 -0
- package/dist/commands/index.d.ts +3 -0
- package/dist/commands/index.js +9 -0
- package/dist/commands/work-hour.command.d.ts +5 -0
- package/dist/commands/work-hour.command.js +153 -0
- package/dist/config/holidays.d.ts +60 -0
- package/dist/config/holidays.js +177 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +23 -0
- package/dist/services/api.service.d.ts +98 -0
- package/dist/services/api.service.js +405 -0
- package/dist/services/business.service.d.ts +69 -0
- package/dist/services/business.service.js +330 -0
- package/dist/types/index.d.ts +522 -0
- package/dist/types/index.js +2 -0
- package/dist/utils/config-loader.d.ts +22 -0
- package/dist/utils/config-loader.js +56 -0
- package/dist/utils/global-config.d.ts +24 -0
- package/dist/utils/global-config.js +153 -0
- package/package.json +70 -0
|
@@ -0,0 +1,522 @@
|
|
|
1
|
+
export interface ApiConfig {
|
|
2
|
+
baseURL: string;
|
|
3
|
+
apiKey: string;
|
|
4
|
+
timeout: number;
|
|
5
|
+
}
|
|
6
|
+
export interface HuaweiCloudConfig {
|
|
7
|
+
iamEndpoint: string;
|
|
8
|
+
region: string;
|
|
9
|
+
endpoint: string;
|
|
10
|
+
username: string;
|
|
11
|
+
password: string;
|
|
12
|
+
domainName: string;
|
|
13
|
+
enableLogging?: boolean;
|
|
14
|
+
}
|
|
15
|
+
export interface IamTokenRequest {
|
|
16
|
+
auth: {
|
|
17
|
+
identity: {
|
|
18
|
+
methods: string[];
|
|
19
|
+
password: {
|
|
20
|
+
user: {
|
|
21
|
+
name: string;
|
|
22
|
+
password: string;
|
|
23
|
+
domain: {
|
|
24
|
+
name: string;
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
scope: {
|
|
30
|
+
project?: {
|
|
31
|
+
name?: string;
|
|
32
|
+
id?: string;
|
|
33
|
+
};
|
|
34
|
+
domain?: {
|
|
35
|
+
name?: string;
|
|
36
|
+
id?: string;
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
export interface IamTokenResponse {
|
|
42
|
+
token: {
|
|
43
|
+
expires_at: string;
|
|
44
|
+
issued_at: string;
|
|
45
|
+
methods: string[];
|
|
46
|
+
project?: {
|
|
47
|
+
domain: {
|
|
48
|
+
id: string;
|
|
49
|
+
name: string;
|
|
50
|
+
};
|
|
51
|
+
id: string;
|
|
52
|
+
name: string;
|
|
53
|
+
};
|
|
54
|
+
domain?: {
|
|
55
|
+
id: string;
|
|
56
|
+
name: string;
|
|
57
|
+
};
|
|
58
|
+
roles: Array<{
|
|
59
|
+
id: string;
|
|
60
|
+
name: string;
|
|
61
|
+
}>;
|
|
62
|
+
user: {
|
|
63
|
+
domain: {
|
|
64
|
+
id: string;
|
|
65
|
+
name: string;
|
|
66
|
+
};
|
|
67
|
+
id: string;
|
|
68
|
+
name: string;
|
|
69
|
+
password_expires_at: string;
|
|
70
|
+
};
|
|
71
|
+
catalog?: Array<{
|
|
72
|
+
endpoints: Array<{
|
|
73
|
+
id: string;
|
|
74
|
+
interface: string;
|
|
75
|
+
region: string;
|
|
76
|
+
region_id: string;
|
|
77
|
+
url: string;
|
|
78
|
+
}>;
|
|
79
|
+
id: string;
|
|
80
|
+
name: string;
|
|
81
|
+
type: string;
|
|
82
|
+
}>;
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
export interface CachedToken {
|
|
86
|
+
token: string;
|
|
87
|
+
expiresAt: Date;
|
|
88
|
+
issuedAt: Date;
|
|
89
|
+
projectId?: string;
|
|
90
|
+
projectName?: string;
|
|
91
|
+
}
|
|
92
|
+
export interface ApiResponse<T = unknown> {
|
|
93
|
+
success: boolean;
|
|
94
|
+
data: T | null;
|
|
95
|
+
message?: string;
|
|
96
|
+
error?: string;
|
|
97
|
+
}
|
|
98
|
+
export interface RawData {
|
|
99
|
+
id: string;
|
|
100
|
+
timestamp: string;
|
|
101
|
+
content: unknown;
|
|
102
|
+
metadata?: Record<string, unknown>;
|
|
103
|
+
}
|
|
104
|
+
export interface ProcessedData {
|
|
105
|
+
id: string;
|
|
106
|
+
processedAt: string;
|
|
107
|
+
result: unknown;
|
|
108
|
+
summary?: string;
|
|
109
|
+
}
|
|
110
|
+
export interface RequestOptions {
|
|
111
|
+
method?: 'GET' | 'POST' | 'PUT' | 'DELETE';
|
|
112
|
+
headers?: Record<string, string>;
|
|
113
|
+
params?: Record<string, unknown>;
|
|
114
|
+
data?: unknown;
|
|
115
|
+
}
|
|
116
|
+
export interface ProjectType {
|
|
117
|
+
SCRUM: 'scrum';
|
|
118
|
+
NORMAL: 'normal';
|
|
119
|
+
XBOARD: 'xboard';
|
|
120
|
+
}
|
|
121
|
+
export interface ProjectQueryParams {
|
|
122
|
+
offset?: number;
|
|
123
|
+
limit?: number;
|
|
124
|
+
search?: string;
|
|
125
|
+
project_type?: 'scrum' | 'normal' | 'xboard';
|
|
126
|
+
sort?: string;
|
|
127
|
+
archive?: 'true' | 'false';
|
|
128
|
+
query_type?: 'domain_projects' | 'absent';
|
|
129
|
+
}
|
|
130
|
+
export interface ProjectCreator {
|
|
131
|
+
user_num_id: number;
|
|
132
|
+
user_id: string;
|
|
133
|
+
user_name: string;
|
|
134
|
+
domain_id: string;
|
|
135
|
+
domain_name: string;
|
|
136
|
+
nick_name: string;
|
|
137
|
+
}
|
|
138
|
+
export interface Project {
|
|
139
|
+
project_num_id: number;
|
|
140
|
+
project_id: string;
|
|
141
|
+
project_name: string;
|
|
142
|
+
description: string;
|
|
143
|
+
created_time: number;
|
|
144
|
+
updated_time: number;
|
|
145
|
+
project_type: 'scrum' | 'normal' | 'xboard';
|
|
146
|
+
creator: ProjectCreator;
|
|
147
|
+
}
|
|
148
|
+
export interface ProjectListResponse {
|
|
149
|
+
projects: Project[];
|
|
150
|
+
total: number;
|
|
151
|
+
}
|
|
152
|
+
export interface ProjectMember {
|
|
153
|
+
domain_id: string;
|
|
154
|
+
domain_name: string;
|
|
155
|
+
user_id: string;
|
|
156
|
+
user_name: string;
|
|
157
|
+
user_num_id: number;
|
|
158
|
+
role_id: number;
|
|
159
|
+
nick_name: string;
|
|
160
|
+
role_name: string;
|
|
161
|
+
user_type: 'User' | 'Federation';
|
|
162
|
+
forbidden: 0 | 1;
|
|
163
|
+
}
|
|
164
|
+
export interface ProjectMemberListResponse {
|
|
165
|
+
members: ProjectMember[];
|
|
166
|
+
total: number;
|
|
167
|
+
}
|
|
168
|
+
export interface ProjectMemberQueryParams {
|
|
169
|
+
offset?: number;
|
|
170
|
+
limit?: number;
|
|
171
|
+
}
|
|
172
|
+
export interface ShowProjectWorkHoursRequest {
|
|
173
|
+
begin_time?: string;
|
|
174
|
+
end_time?: string;
|
|
175
|
+
limit?: number;
|
|
176
|
+
offset?: number;
|
|
177
|
+
user_ids?: string[];
|
|
178
|
+
work_hours_dates?: string;
|
|
179
|
+
work_hours_types?: string;
|
|
180
|
+
}
|
|
181
|
+
export interface WorkHour {
|
|
182
|
+
closed_time: string;
|
|
183
|
+
created_time: string;
|
|
184
|
+
issue_id: number;
|
|
185
|
+
issue_type: string;
|
|
186
|
+
nick_name: string;
|
|
187
|
+
project_name: string;
|
|
188
|
+
subject: string;
|
|
189
|
+
summary: string;
|
|
190
|
+
user_id: string;
|
|
191
|
+
user_name: string;
|
|
192
|
+
work_date: string;
|
|
193
|
+
work_hours_created_time: string;
|
|
194
|
+
work_hours_num: string;
|
|
195
|
+
work_hours_type_name: string;
|
|
196
|
+
work_hours_updated_time: string;
|
|
197
|
+
}
|
|
198
|
+
export interface ShowProjectWorkHoursResponse {
|
|
199
|
+
total: number;
|
|
200
|
+
work_hours: WorkHour[];
|
|
201
|
+
}
|
|
202
|
+
export interface CustomField {
|
|
203
|
+
custom_field?: string;
|
|
204
|
+
value?: string;
|
|
205
|
+
}
|
|
206
|
+
export interface ListIssuesV4Request {
|
|
207
|
+
subject?: string;
|
|
208
|
+
issue_ids?: number[];
|
|
209
|
+
assigned_ids?: string[];
|
|
210
|
+
closed_time_interval?: string;
|
|
211
|
+
created_time_interval?: string;
|
|
212
|
+
creator_ids?: string[];
|
|
213
|
+
custom_fields?: CustomField[];
|
|
214
|
+
developer_ids?: string[];
|
|
215
|
+
domain_ids?: number[];
|
|
216
|
+
done_ratios?: number[];
|
|
217
|
+
include_deleted?: boolean;
|
|
218
|
+
iteration_ids?: number[];
|
|
219
|
+
limit?: number;
|
|
220
|
+
module_ids?: number[];
|
|
221
|
+
offset?: number;
|
|
222
|
+
priority_ids?: number[];
|
|
223
|
+
query_type?: 'epic' | 'feature' | 'backlog';
|
|
224
|
+
severity_ids?: number[];
|
|
225
|
+
status_ids?: number[];
|
|
226
|
+
story_point_ids?: number[];
|
|
227
|
+
tracker_ids?: number[];
|
|
228
|
+
updated_time_interval?: string;
|
|
229
|
+
}
|
|
230
|
+
export interface IssueUser {
|
|
231
|
+
id: number;
|
|
232
|
+
name: string;
|
|
233
|
+
nick_name: string;
|
|
234
|
+
user_id: string;
|
|
235
|
+
user_num_id: number;
|
|
236
|
+
first_name: string;
|
|
237
|
+
}
|
|
238
|
+
export interface IssueCustomField {
|
|
239
|
+
name: string;
|
|
240
|
+
new_name: string;
|
|
241
|
+
value: string;
|
|
242
|
+
}
|
|
243
|
+
export interface IssueDomain {
|
|
244
|
+
id: number;
|
|
245
|
+
name: string;
|
|
246
|
+
}
|
|
247
|
+
export interface IssueIteration {
|
|
248
|
+
id: number;
|
|
249
|
+
name: string;
|
|
250
|
+
}
|
|
251
|
+
export interface IssueModule {
|
|
252
|
+
id: number;
|
|
253
|
+
name: string;
|
|
254
|
+
}
|
|
255
|
+
export interface IssueNewCustomField {
|
|
256
|
+
custom_field: string;
|
|
257
|
+
field_name: string;
|
|
258
|
+
value: string;
|
|
259
|
+
}
|
|
260
|
+
export interface IssueParent {
|
|
261
|
+
id: number;
|
|
262
|
+
name: string;
|
|
263
|
+
}
|
|
264
|
+
export interface IssuePriority {
|
|
265
|
+
id: number;
|
|
266
|
+
name: string;
|
|
267
|
+
}
|
|
268
|
+
export interface IssueProjectInfo {
|
|
269
|
+
project_id: string;
|
|
270
|
+
project_name: string;
|
|
271
|
+
project_num_id: number;
|
|
272
|
+
}
|
|
273
|
+
export interface IssueSeverity {
|
|
274
|
+
id: number;
|
|
275
|
+
name: string;
|
|
276
|
+
}
|
|
277
|
+
export interface IssueStatus {
|
|
278
|
+
id: number;
|
|
279
|
+
name: string;
|
|
280
|
+
}
|
|
281
|
+
export interface IssueTracker {
|
|
282
|
+
id: number;
|
|
283
|
+
name: string;
|
|
284
|
+
}
|
|
285
|
+
export interface IssueItem {
|
|
286
|
+
actual_work_hours: number;
|
|
287
|
+
assigned_cc_user: IssueUser[];
|
|
288
|
+
assigned_user: IssueUser;
|
|
289
|
+
begin_time: string;
|
|
290
|
+
closed_time: string;
|
|
291
|
+
created_time: string;
|
|
292
|
+
creator: IssueUser;
|
|
293
|
+
custom_fields: IssueCustomField[];
|
|
294
|
+
developer: IssueUser;
|
|
295
|
+
domain: IssueDomain;
|
|
296
|
+
done_ratio: number;
|
|
297
|
+
end_time: string;
|
|
298
|
+
expected_work_hours: number;
|
|
299
|
+
id: number;
|
|
300
|
+
iteration: IssueIteration;
|
|
301
|
+
module: IssueModule;
|
|
302
|
+
name: string;
|
|
303
|
+
new_custom_fields: IssueNewCustomField[];
|
|
304
|
+
parent_issue: IssueParent;
|
|
305
|
+
priority: IssuePriority;
|
|
306
|
+
project: IssueProjectInfo;
|
|
307
|
+
severity: IssueSeverity;
|
|
308
|
+
status: IssueStatus;
|
|
309
|
+
tracker: IssueTracker;
|
|
310
|
+
updated_time: string;
|
|
311
|
+
deleted: boolean;
|
|
312
|
+
}
|
|
313
|
+
export interface ListIssuesV4Response {
|
|
314
|
+
issues: IssueItem[];
|
|
315
|
+
total: number;
|
|
316
|
+
}
|
|
317
|
+
export interface ListProjectIterationsV4Request {
|
|
318
|
+
updated_time_interval?: string;
|
|
319
|
+
include_deleted?: boolean;
|
|
320
|
+
}
|
|
321
|
+
export interface IterationInfo {
|
|
322
|
+
begin_time: string;
|
|
323
|
+
deleted: boolean;
|
|
324
|
+
description: string;
|
|
325
|
+
end_time: string;
|
|
326
|
+
id: number;
|
|
327
|
+
name: string;
|
|
328
|
+
status: string;
|
|
329
|
+
updated_time: number;
|
|
330
|
+
}
|
|
331
|
+
export interface ListProjectIterationsV4Response {
|
|
332
|
+
iterations: IterationInfo[];
|
|
333
|
+
total: number;
|
|
334
|
+
}
|
|
335
|
+
export interface AddIssueNotesRequest {
|
|
336
|
+
id: string;
|
|
337
|
+
notes: string;
|
|
338
|
+
projectUUId: string;
|
|
339
|
+
type?: string;
|
|
340
|
+
}
|
|
341
|
+
export interface UserVO {
|
|
342
|
+
assigned_nick_name?: string;
|
|
343
|
+
first_name?: string;
|
|
344
|
+
id?: number;
|
|
345
|
+
identifier?: string;
|
|
346
|
+
last_name?: string;
|
|
347
|
+
name?: string;
|
|
348
|
+
}
|
|
349
|
+
export interface CustomFieldV2 {
|
|
350
|
+
name?: string;
|
|
351
|
+
value?: string;
|
|
352
|
+
new_name?: string;
|
|
353
|
+
}
|
|
354
|
+
export interface IssueDetailCustomFieldV2 {
|
|
355
|
+
custom_field?: string;
|
|
356
|
+
field_name?: string;
|
|
357
|
+
value?: string;
|
|
358
|
+
field_type?: string;
|
|
359
|
+
description?: string;
|
|
360
|
+
}
|
|
361
|
+
export interface DomainVO {
|
|
362
|
+
id?: number;
|
|
363
|
+
name?: string;
|
|
364
|
+
}
|
|
365
|
+
export interface ProjectVO {
|
|
366
|
+
identifier?: string;
|
|
367
|
+
name?: string;
|
|
368
|
+
id?: number;
|
|
369
|
+
project_type?: string;
|
|
370
|
+
}
|
|
371
|
+
export interface IterationVO {
|
|
372
|
+
id?: number;
|
|
373
|
+
name?: string;
|
|
374
|
+
}
|
|
375
|
+
export interface StoryPointVO {
|
|
376
|
+
id?: number;
|
|
377
|
+
name?: string;
|
|
378
|
+
}
|
|
379
|
+
export interface ModuleVO {
|
|
380
|
+
id?: number;
|
|
381
|
+
name?: string;
|
|
382
|
+
}
|
|
383
|
+
export interface ParentIssueVO {
|
|
384
|
+
id?: number;
|
|
385
|
+
name?: string;
|
|
386
|
+
}
|
|
387
|
+
export interface PriorityVO {
|
|
388
|
+
id?: number;
|
|
389
|
+
name?: string;
|
|
390
|
+
}
|
|
391
|
+
export interface SeverityVO {
|
|
392
|
+
id?: number;
|
|
393
|
+
name?: string;
|
|
394
|
+
}
|
|
395
|
+
export interface StatusVO {
|
|
396
|
+
id?: number;
|
|
397
|
+
name?: string;
|
|
398
|
+
}
|
|
399
|
+
export interface EnvVO {
|
|
400
|
+
id?: number;
|
|
401
|
+
name?: string;
|
|
402
|
+
}
|
|
403
|
+
export interface TrackerVO {
|
|
404
|
+
id?: number;
|
|
405
|
+
name?: string;
|
|
406
|
+
}
|
|
407
|
+
export interface IssueAccessoryV2 {
|
|
408
|
+
attachment_id?: number;
|
|
409
|
+
issue_id?: number;
|
|
410
|
+
creator_num_id?: number;
|
|
411
|
+
created_date?: string;
|
|
412
|
+
file_name?: string;
|
|
413
|
+
container_type?: string;
|
|
414
|
+
disk_file_name?: string;
|
|
415
|
+
digest?: string;
|
|
416
|
+
disk_directory?: string;
|
|
417
|
+
creator_id?: string;
|
|
418
|
+
}
|
|
419
|
+
export interface IssueDetailResponseV2 {
|
|
420
|
+
actual_work_hours?: number;
|
|
421
|
+
assigned_cc_user?: UserVO[];
|
|
422
|
+
assigned_to?: UserVO;
|
|
423
|
+
start_date?: string;
|
|
424
|
+
created_on?: string;
|
|
425
|
+
author?: UserVO;
|
|
426
|
+
custom_fields?: CustomFieldV2[];
|
|
427
|
+
custom_value_new?: IssueDetailCustomFieldV2;
|
|
428
|
+
developer?: UserVO;
|
|
429
|
+
domain?: DomainVO;
|
|
430
|
+
done_ratio?: number;
|
|
431
|
+
end_time?: string;
|
|
432
|
+
expected_work_hours?: number;
|
|
433
|
+
id?: number;
|
|
434
|
+
project?: ProjectVO;
|
|
435
|
+
iteration?: IterationVO;
|
|
436
|
+
story_point?: StoryPointVO;
|
|
437
|
+
module?: ModuleVO;
|
|
438
|
+
subject?: string;
|
|
439
|
+
parent_issue?: ParentIssueVO;
|
|
440
|
+
priority?: PriorityVO;
|
|
441
|
+
severity?: SeverityVO;
|
|
442
|
+
status?: StatusVO;
|
|
443
|
+
release_dev?: string;
|
|
444
|
+
find_release_dev?: string;
|
|
445
|
+
env?: EnvVO;
|
|
446
|
+
tracker?: TrackerVO;
|
|
447
|
+
updated_on?: string;
|
|
448
|
+
closed_time?: string;
|
|
449
|
+
description?: string;
|
|
450
|
+
accessories_list?: IssueAccessoryV2[];
|
|
451
|
+
inner_text?: string;
|
|
452
|
+
}
|
|
453
|
+
export interface AddIssueNotesResult {
|
|
454
|
+
issue: IssueDetailResponseV2;
|
|
455
|
+
}
|
|
456
|
+
export interface AddIssueNotesResponse {
|
|
457
|
+
result: AddIssueNotesResult;
|
|
458
|
+
status: string;
|
|
459
|
+
}
|
|
460
|
+
/**
|
|
461
|
+
* 用户工作项统计信息
|
|
462
|
+
*/
|
|
463
|
+
export interface UserWorkStats {
|
|
464
|
+
userName: string;
|
|
465
|
+
count: number;
|
|
466
|
+
expectedHours: number;
|
|
467
|
+
actualHours: number;
|
|
468
|
+
completionRate: number;
|
|
469
|
+
} /**
|
|
470
|
+
* 工作项进度统计结果
|
|
471
|
+
*/
|
|
472
|
+
export interface WorkProgressStats {
|
|
473
|
+
totalCount: number;
|
|
474
|
+
totalExpectedHours: number;
|
|
475
|
+
totalActualHours: number;
|
|
476
|
+
overallCompletionRate: number;
|
|
477
|
+
userStats: UserWorkStats[];
|
|
478
|
+
} /**
|
|
479
|
+
* 用户工时统计信息
|
|
480
|
+
*/
|
|
481
|
+
export interface UserWorkHourStats {
|
|
482
|
+
userName: string;
|
|
483
|
+
userId: string;
|
|
484
|
+
totalHours: number;
|
|
485
|
+
workHours: WorkHour[];
|
|
486
|
+
}
|
|
487
|
+
/**
|
|
488
|
+
* 工时统计结果
|
|
489
|
+
*/
|
|
490
|
+
export interface WorkHourStats {
|
|
491
|
+
date: string;
|
|
492
|
+
totalHours: number;
|
|
493
|
+
totalEntries: number;
|
|
494
|
+
userStats: UserWorkHourStats[];
|
|
495
|
+
}
|
|
496
|
+
/**
|
|
497
|
+
* 领域工时统计信息
|
|
498
|
+
*/
|
|
499
|
+
export interface TypeWorkHourStats {
|
|
500
|
+
type: string;
|
|
501
|
+
totalHours: number;
|
|
502
|
+
workHours: WorkHour[];
|
|
503
|
+
}
|
|
504
|
+
/**
|
|
505
|
+
* 用户全量工时统计信息(按领域分组)
|
|
506
|
+
*/
|
|
507
|
+
export interface UserAllWorkHourStats {
|
|
508
|
+
userName: string;
|
|
509
|
+
userId: string;
|
|
510
|
+
totalHours: number;
|
|
511
|
+
domainStats: TypeWorkHourStats[];
|
|
512
|
+
}
|
|
513
|
+
/**
|
|
514
|
+
* 全量工时统计结果
|
|
515
|
+
*/
|
|
516
|
+
export interface AllWorkHourStats {
|
|
517
|
+
beginDate: string;
|
|
518
|
+
endDate: string;
|
|
519
|
+
totalHours: number;
|
|
520
|
+
totalEntries: number;
|
|
521
|
+
userStats: UserAllWorkHourStats[];
|
|
522
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { HuaweiCloudConfig } from '../types';
|
|
2
|
+
export interface CliOptions {
|
|
3
|
+
projectId?: string;
|
|
4
|
+
roleId?: string;
|
|
5
|
+
username?: string;
|
|
6
|
+
password?: string;
|
|
7
|
+
domain?: string;
|
|
8
|
+
region?: string;
|
|
9
|
+
iamEndpoint?: string;
|
|
10
|
+
codeartsUrl?: string;
|
|
11
|
+
}
|
|
12
|
+
export interface LoadedConfig {
|
|
13
|
+
projectId: string;
|
|
14
|
+
roleIds: number[];
|
|
15
|
+
config: HuaweiCloudConfig;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* 加载配置,优先级:命令行参数 > 当前目录 .env > 全局配置 > 默认值
|
|
19
|
+
* @param cliOptions 命令行选项
|
|
20
|
+
* @returns 加载的配置
|
|
21
|
+
*/
|
|
22
|
+
export declare function loadConfig(cliOptions?: CliOptions): LoadedConfig;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.loadConfig = loadConfig;
|
|
7
|
+
const dotenv_1 = __importDefault(require("dotenv"));
|
|
8
|
+
const global_config_1 = require("./global-config");
|
|
9
|
+
// 加载当前目录的 .env 文件(如果存在)
|
|
10
|
+
dotenv_1.default.config();
|
|
11
|
+
// 加载全局配置
|
|
12
|
+
const globalConfig = (0, global_config_1.globalConfigExists)() ? (0, global_config_1.readGlobalConfig)() : {};
|
|
13
|
+
/**
|
|
14
|
+
* 加载配置,优先级:命令行参数 > 当前目录 .env > 全局配置 > 默认值
|
|
15
|
+
* @param cliOptions 命令行选项
|
|
16
|
+
* @returns 加载的配置
|
|
17
|
+
*/
|
|
18
|
+
function loadConfig(cliOptions = {}) {
|
|
19
|
+
// 命令行参数 > 当前目录 .env > 全局配置
|
|
20
|
+
const projectId = cliOptions.projectId || process.env.PROJECT_ID || globalConfig.PROJECT_ID;
|
|
21
|
+
const roleIdStr = cliOptions.roleId || process.env.ROLE_ID || globalConfig.ROLE_ID;
|
|
22
|
+
if (!projectId) {
|
|
23
|
+
throw new Error('缺少必需参数: --project-id 或环境变量 PROJECT_ID\n提示:运行 codearts config 创建配置');
|
|
24
|
+
}
|
|
25
|
+
if (!roleIdStr) {
|
|
26
|
+
throw new Error('缺少必需参数: --role-id 或环境变量 ROLE_ID\n提示:运行 codearts config 创建配置');
|
|
27
|
+
}
|
|
28
|
+
const roleIds = roleIdStr.split(',').map((id) => parseInt(id.trim()));
|
|
29
|
+
if (roleIds.some((id) => isNaN(id))) {
|
|
30
|
+
throw new Error('ROLE_ID 格式不正确,应为数字或逗号分隔的数字列表');
|
|
31
|
+
}
|
|
32
|
+
const username = cliOptions.username || process.env.HUAWEI_CLOUD_USERNAME || globalConfig.HUAWEI_CLOUD_USERNAME;
|
|
33
|
+
const password = cliOptions.password || process.env.HUAWEI_CLOUD_PASSWORD || globalConfig.HUAWEI_CLOUD_PASSWORD;
|
|
34
|
+
const domain = cliOptions.domain || process.env.HUAWEI_CLOUD_DOMAIN || globalConfig.HUAWEI_CLOUD_DOMAIN;
|
|
35
|
+
if (!username || !password || !domain) {
|
|
36
|
+
throw new Error('缺少华为云认证信息: --username, --password, --domain 或对应的环境变量\n提示:运行 codearts config 创建配置');
|
|
37
|
+
}
|
|
38
|
+
const config = {
|
|
39
|
+
iamEndpoint: cliOptions.iamEndpoint ||
|
|
40
|
+
process.env.HUAWEI_CLOUD_IAM_ENDPOINT ||
|
|
41
|
+
globalConfig.HUAWEI_CLOUD_IAM_ENDPOINT ||
|
|
42
|
+
'https://iam.cn-north-4.myhuaweicloud.com',
|
|
43
|
+
region: cliOptions.region ||
|
|
44
|
+
process.env.HUAWEI_CLOUD_REGION ||
|
|
45
|
+
globalConfig.HUAWEI_CLOUD_REGION ||
|
|
46
|
+
'cn-north-4',
|
|
47
|
+
endpoint: cliOptions.codeartsUrl ||
|
|
48
|
+
process.env.CODEARTS_BASE_URL ||
|
|
49
|
+
globalConfig.CODEARTS_BASE_URL ||
|
|
50
|
+
'https://projectman-ext.cn-north-4.myhuaweicloud.cn',
|
|
51
|
+
username,
|
|
52
|
+
password,
|
|
53
|
+
domainName: domain,
|
|
54
|
+
};
|
|
55
|
+
return { projectId, roleIds, config };
|
|
56
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 获取全局配置文件路径
|
|
3
|
+
*/
|
|
4
|
+
export declare function getGlobalConfigPath(): string;
|
|
5
|
+
/**
|
|
6
|
+
* 检查全局配置文件是否存在
|
|
7
|
+
*/
|
|
8
|
+
export declare function globalConfigExists(): boolean;
|
|
9
|
+
/**
|
|
10
|
+
* 读取全局配置
|
|
11
|
+
*/
|
|
12
|
+
export declare function readGlobalConfig(): Record<string, string>;
|
|
13
|
+
/**
|
|
14
|
+
* 写入全局配置
|
|
15
|
+
*/
|
|
16
|
+
export declare function writeGlobalConfig(config: Record<string, string>): void;
|
|
17
|
+
/**
|
|
18
|
+
* 删除全局配置
|
|
19
|
+
*/
|
|
20
|
+
export declare function deleteGlobalConfig(): void;
|
|
21
|
+
/**
|
|
22
|
+
* 获取配置信息(用于显示)
|
|
23
|
+
*/
|
|
24
|
+
export declare function getConfigInfo(): string;
|