ai-yuca 1.0.8 → 1.0.9
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/.cdn.cache.json +2 -2
- package/dist/package.json +1 -1
- package/dist/src/deploy.js +31 -21
- package/dist/src/types/deploy.d.ts +1 -1
- package/package.json +1 -1
- package/src/deploy.ts +37 -26
- package/src/types/deploy.ts +1 -1
- package/src/upload.ts +1 -1
package/.cdn.cache.json
CHANGED
package/dist/package.json
CHANGED
package/dist/src/deploy.js
CHANGED
|
@@ -50,15 +50,32 @@ const uploadWithConfig_1 = require("./uploadWithConfig");
|
|
|
50
50
|
const cache_1 = require("./cache");
|
|
51
51
|
const child_process_1 = require("child_process");
|
|
52
52
|
/**
|
|
53
|
-
*
|
|
53
|
+
* 从GCP存储读取环境配置文件
|
|
54
54
|
*/
|
|
55
|
-
const getConfigFiles = (env, config) => {
|
|
55
|
+
const getConfigFiles = (env, config, keyFile) => {
|
|
56
56
|
return new Promise(async (resolve) => {
|
|
57
57
|
try {
|
|
58
|
-
|
|
58
|
+
// 继承原来的权限文件,创建GCP存储客户端
|
|
59
|
+
const storageClient = keyFile
|
|
60
|
+
? (0, upload_1.createStorageClient)({ keyFilename: keyFile })
|
|
61
|
+
: (0, upload_1.createStorageClient)();
|
|
62
|
+
const bucket = storageClient.bucket(config.aws.Bucket);
|
|
63
|
+
const configPath = `${config.aws.prefix}/static/config/${env}.config.json`;
|
|
64
|
+
const file = bucket.file(configPath);
|
|
65
|
+
// 检查文件是否存在
|
|
66
|
+
const [exists] = await file.exists();
|
|
67
|
+
if (!exists) {
|
|
68
|
+
console.log(`配置文件不存在: ${configPath}`);
|
|
69
|
+
resolve({ data: { projects: [] } });
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
// 直接读取文件内容到内存,不下载到本地
|
|
73
|
+
const [contents] = await file.download();
|
|
74
|
+
const sitemap = JSON.parse(contents.toString());
|
|
59
75
|
resolve({ data: sitemap });
|
|
60
76
|
}
|
|
61
77
|
catch (e) {
|
|
78
|
+
console.log(`读取配置文件失败: ${e instanceof Error ? e.message : String(e)}`);
|
|
62
79
|
resolve({ data: { projects: [] } });
|
|
63
80
|
}
|
|
64
81
|
});
|
|
@@ -176,7 +193,7 @@ async function uploadToGcp(filePath, bucketName, destination, keyFile) {
|
|
|
176
193
|
async function updateEnvironmentConfig(env, projectName, versionInfo, config, keyFile) {
|
|
177
194
|
try {
|
|
178
195
|
// 获取当前环境配置
|
|
179
|
-
const { data: envConfig } = await getConfigFiles(env, config);
|
|
196
|
+
const { data: envConfig } = await getConfigFiles(env, config, keyFile);
|
|
180
197
|
// 查找或创建项目配置
|
|
181
198
|
let projectConfig = envConfig.projects.find((p) => p.name === projectName);
|
|
182
199
|
if (!projectConfig) {
|
|
@@ -198,11 +215,14 @@ async function updateEnvironmentConfig(env, projectName, versionInfo, config, ke
|
|
|
198
215
|
const configPath = `${config.aws.prefix}/static/config/${env}.config.json`;
|
|
199
216
|
const tempFile = path.join(process.cwd(), `temp-${env}-config.json`);
|
|
200
217
|
fs.writeFileSync(tempFile, JSON.stringify(envConfig, null, 2));
|
|
201
|
-
|
|
218
|
+
console.log(configPath, JSON.stringify(envConfig, null, 2));
|
|
219
|
+
const result = await uploadToGcp(tempFile, config.aws.Bucket, configPath, keyFile);
|
|
202
220
|
fs.unlinkSync(tempFile);
|
|
221
|
+
console.log('更新环境配置状态:', JSON.stringify(result), tempFile, config.aws.Bucket, configPath, keyFile);
|
|
203
222
|
return result.success;
|
|
204
223
|
}
|
|
205
|
-
catch (
|
|
224
|
+
catch (e) {
|
|
225
|
+
console.log('更新环境配置失败:', e);
|
|
206
226
|
return false;
|
|
207
227
|
}
|
|
208
228
|
}
|
|
@@ -218,23 +238,11 @@ async function deployFiles(options) {
|
|
|
218
238
|
// 2. 执行upload-config阶段
|
|
219
239
|
console.log('📤 执行upload-config上传配置文件...');
|
|
220
240
|
try {
|
|
221
|
-
|
|
241
|
+
await (0, uploadWithConfig_1.uploadFilesWithConfig)({
|
|
222
242
|
configPath: options.config,
|
|
223
243
|
storageClientOptions: options.keyFile ? { keyFilename: options.keyFile } : {},
|
|
224
244
|
enableCache: true
|
|
225
245
|
});
|
|
226
|
-
if (uploadResult.success.length > 0) {
|
|
227
|
-
console.log(chalk_1.default.green(`✅ upload-config成功: ${uploadResult.success.length}个文件`));
|
|
228
|
-
uploadResult.success.forEach(file => {
|
|
229
|
-
console.log(chalk_1.default.green(` ✅ ${file.file}: ${file.url}`));
|
|
230
|
-
});
|
|
231
|
-
}
|
|
232
|
-
if (uploadResult.failed.length > 0) {
|
|
233
|
-
console.log(chalk_1.default.red(`❌ upload-config失败: ${uploadResult.failed.length}个文件`));
|
|
234
|
-
uploadResult.failed.forEach(file => {
|
|
235
|
-
console.log(chalk_1.default.red(` ❌ ${file.file}: ${file.error}`));
|
|
236
|
-
});
|
|
237
|
-
}
|
|
238
246
|
}
|
|
239
247
|
catch (error) {
|
|
240
248
|
console.warn(`⚠️ upload-config执行失败: ${error instanceof Error ? error.message : String(error)}`);
|
|
@@ -346,7 +354,8 @@ async function deployFiles(options) {
|
|
|
346
354
|
// 7. 环境配置同步阶段
|
|
347
355
|
console.log('🔄 同步环境配置...');
|
|
348
356
|
// 检查项目是否存在
|
|
349
|
-
const { data: envConfig } = await getConfigFiles(options.env, config);
|
|
357
|
+
const { data: envConfig } = await getConfigFiles(options.env, config, options.keyFile);
|
|
358
|
+
console.log('当前环境配置:', JSON.stringify(envConfig));
|
|
350
359
|
const existingProject = envConfig.projects.find((p) => p.name === projectInfo.name);
|
|
351
360
|
if (!existingProject) {
|
|
352
361
|
if (options.force) {
|
|
@@ -375,7 +384,8 @@ async function deployFiles(options) {
|
|
|
375
384
|
timestamp: Date.now(),
|
|
376
385
|
files: obj.links
|
|
377
386
|
};
|
|
378
|
-
await updateEnvironmentConfig(options.env, projectInfo.name, versionInfo, config, options.keyFile);
|
|
387
|
+
const projectConfigUpdate = await updateEnvironmentConfig(options.env, projectInfo.name, versionInfo, config, options.keyFile);
|
|
388
|
+
console.log('配置文件上传结果:', JSON.stringify(projectConfigUpdate));
|
|
379
389
|
// 8. 发布完成阶段
|
|
380
390
|
console.log('💾 记录发布版本...');
|
|
381
391
|
(0, cache_1.writeLastDeployVersion)(cdnKey);
|
|
@@ -61,7 +61,7 @@ export interface DeployResult {
|
|
|
61
61
|
message: string;
|
|
62
62
|
}
|
|
63
63
|
export interface GetConfigFilesFunction {
|
|
64
|
-
(env: string, config: Record<string, any
|
|
64
|
+
(env: string, config: Record<string, any>, keyFile?: string): Promise<{
|
|
65
65
|
data: {
|
|
66
66
|
projects: Array<any>;
|
|
67
67
|
};
|
package/package.json
CHANGED
package/src/deploy.ts
CHANGED
|
@@ -23,16 +23,33 @@ import {
|
|
|
23
23
|
} from './types/deploy';
|
|
24
24
|
|
|
25
25
|
/**
|
|
26
|
-
*
|
|
26
|
+
* 从GCP存储读取环境配置文件
|
|
27
27
|
*/
|
|
28
|
-
const getConfigFiles: GetConfigFilesFunction = (env, config) => {
|
|
28
|
+
const getConfigFiles: GetConfigFilesFunction = (env, config, keyFile) => {
|
|
29
29
|
return new Promise(async resolve => {
|
|
30
30
|
try {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
31
|
+
// 继承原来的权限文件,创建GCP存储客户端
|
|
32
|
+
const storageClient = keyFile
|
|
33
|
+
? createStorageClient({ keyFilename: keyFile })
|
|
34
|
+
: createStorageClient();
|
|
35
|
+
const bucket = storageClient.bucket(config.aws.Bucket);
|
|
36
|
+
const configPath = `${config.aws.prefix}/static/config/${env}.config.json`;
|
|
37
|
+
const file = bucket.file(configPath);
|
|
38
|
+
|
|
39
|
+
// 检查文件是否存在
|
|
40
|
+
const [exists] = await file.exists();
|
|
41
|
+
if (!exists) {
|
|
42
|
+
console.log(`配置文件不存在: ${configPath}`);
|
|
43
|
+
resolve({ data: { projects: [] } });
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// 直接读取文件内容到内存,不下载到本地
|
|
48
|
+
const [contents] = await file.download();
|
|
49
|
+
const sitemap = JSON.parse(contents.toString());
|
|
34
50
|
resolve({ data: sitemap });
|
|
35
51
|
} catch (e) {
|
|
52
|
+
console.log(`读取配置文件失败: ${e instanceof Error ? e.message : String(e)}`);
|
|
36
53
|
resolve({ data: { projects: [] } });
|
|
37
54
|
}
|
|
38
55
|
});
|
|
@@ -156,7 +173,7 @@ async function uploadToGcp(
|
|
|
156
173
|
storageClient: client,
|
|
157
174
|
enableCompression: true
|
|
158
175
|
});
|
|
159
|
-
|
|
176
|
+
|
|
160
177
|
if (result.success) {
|
|
161
178
|
return { success: true, url: result.url };
|
|
162
179
|
} else {
|
|
@@ -183,7 +200,7 @@ async function updateEnvironmentConfig(
|
|
|
183
200
|
): Promise<boolean> {
|
|
184
201
|
try {
|
|
185
202
|
// 获取当前环境配置
|
|
186
|
-
const { data: envConfig } = await getConfigFiles(env, config);
|
|
203
|
+
const { data: envConfig } = await getConfigFiles(env, config, keyFile);
|
|
187
204
|
|
|
188
205
|
// 查找或创建项目配置
|
|
189
206
|
let projectConfig = envConfig.projects.find((p: any) => p.name === projectName);
|
|
@@ -208,13 +225,16 @@ async function updateEnvironmentConfig(
|
|
|
208
225
|
const tempFile = path.join(process.cwd(), `temp-${env}-config.json`);
|
|
209
226
|
|
|
210
227
|
fs.writeFileSync(tempFile, JSON.stringify(envConfig, null, 2));
|
|
228
|
+
|
|
229
|
+
console.log(configPath, JSON.stringify(envConfig, null, 2));
|
|
211
230
|
|
|
212
|
-
const result = await uploadToGcp(tempFile, config.
|
|
231
|
+
const result = await uploadToGcp(tempFile, config.aws.Bucket, configPath, keyFile);
|
|
213
232
|
|
|
214
233
|
fs.unlinkSync(tempFile);
|
|
215
|
-
|
|
234
|
+
console.log('更新环境配置状态:', JSON.stringify(result), tempFile, config.aws.Bucket, configPath, keyFile);
|
|
216
235
|
return result.success;
|
|
217
|
-
} catch {
|
|
236
|
+
} catch(e) {
|
|
237
|
+
console.log('更新环境配置失败:', e);
|
|
218
238
|
return false;
|
|
219
239
|
}
|
|
220
240
|
}
|
|
@@ -235,23 +255,11 @@ export async function deployFiles(options: DeployCommandOptions): Promise<Deploy
|
|
|
235
255
|
// 2. 执行upload-config阶段
|
|
236
256
|
console.log('📤 执行upload-config上传配置文件...');
|
|
237
257
|
try {
|
|
238
|
-
|
|
258
|
+
await uploadFilesWithConfig({
|
|
239
259
|
configPath: options.config,
|
|
240
260
|
storageClientOptions: options.keyFile ? { keyFilename: options.keyFile } : {},
|
|
241
261
|
enableCache: true
|
|
242
262
|
});
|
|
243
|
-
if (uploadResult.success.length > 0) {
|
|
244
|
-
console.log(chalk.green(`✅ upload-config成功: ${uploadResult.success.length}个文件`));
|
|
245
|
-
uploadResult.success.forEach(file => {
|
|
246
|
-
console.log(chalk.green(` ✅ ${file.file}: ${file.url}`));
|
|
247
|
-
});
|
|
248
|
-
}
|
|
249
|
-
if (uploadResult.failed.length > 0) {
|
|
250
|
-
console.log(chalk.red(`❌ upload-config失败: ${uploadResult.failed.length}个文件`));
|
|
251
|
-
uploadResult.failed.forEach(file => {
|
|
252
|
-
console.log(chalk.red(` ❌ ${file.file}: ${file.error}`));
|
|
253
|
-
});
|
|
254
|
-
}
|
|
255
263
|
} catch (error) {
|
|
256
264
|
console.warn(`⚠️ upload-config执行失败: ${error instanceof Error ? error.message : String(error)}`);
|
|
257
265
|
}
|
|
@@ -378,7 +386,10 @@ export async function deployFiles(options: DeployCommandOptions): Promise<Deploy
|
|
|
378
386
|
console.log('🔄 同步环境配置...');
|
|
379
387
|
|
|
380
388
|
// 检查项目是否存在
|
|
381
|
-
const { data: envConfig } = await getConfigFiles(options.env, config);
|
|
389
|
+
const { data: envConfig } = await getConfigFiles(options.env, config, options.keyFile);
|
|
390
|
+
|
|
391
|
+
console.log('当前环境配置:', JSON.stringify(envConfig));
|
|
392
|
+
|
|
382
393
|
const existingProject = envConfig.projects.find((p: any) => p.name === projectInfo.name);
|
|
383
394
|
|
|
384
395
|
if (!existingProject) {
|
|
@@ -410,8 +421,8 @@ export async function deployFiles(options: DeployCommandOptions): Promise<Deploy
|
|
|
410
421
|
files: obj.links
|
|
411
422
|
};
|
|
412
423
|
|
|
413
|
-
await updateEnvironmentConfig(options.env, projectInfo.name, versionInfo, config, options.keyFile);
|
|
414
|
-
|
|
424
|
+
const projectConfigUpdate = await updateEnvironmentConfig(options.env, projectInfo.name, versionInfo, config, options.keyFile);
|
|
425
|
+
console.log('配置文件上传结果:',JSON.stringify(projectConfigUpdate));
|
|
415
426
|
// 8. 发布完成阶段
|
|
416
427
|
console.log('💾 记录发布版本...');
|
|
417
428
|
writeLastDeployVersion(cdnKey);
|
package/src/types/deploy.ts
CHANGED
|
@@ -70,5 +70,5 @@ export interface DeployResult {
|
|
|
70
70
|
}
|
|
71
71
|
|
|
72
72
|
export interface GetConfigFilesFunction {
|
|
73
|
-
(env: string, config: Record<string, any
|
|
73
|
+
(env: string, config: Record<string, any>, keyFile?: string): Promise<{ data: { projects: Array<any> } }>;
|
|
74
74
|
}
|
package/src/upload.ts
CHANGED
|
@@ -52,7 +52,7 @@ function createStorageClient(options: Partial<StorageClientOptions> = {}): Stora
|
|
|
52
52
|
* @param options - 上传选项
|
|
53
53
|
* @returns 上传结果
|
|
54
54
|
*/
|
|
55
|
-
async function
|
|
55
|
+
async function uploadFile(options: UploadFileOptions): Promise<UploadResult> {
|
|
56
56
|
const { bucketName, filePath, destination, storageClient, enableCompression = true } = options;
|
|
57
57
|
|
|
58
58
|
if (!bucketName || !filePath || !storageClient) {
|