ai-yuca 1.0.7 → 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 CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "lastUploadVersion": "mfhlsh6u",
3
- "lastDeployTime": "2025-09-13T02:39:31.383Z",
4
- "lastDeployVersion": "mfhnr62y"
3
+ "lastDeployTime": "2025-09-15T06:15:45.798Z",
4
+ "lastDeployVersion": "mfkqd0es"
5
5
  }
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ai-yuca",
3
- "version": "1.0.7",
3
+ "version": "1.0.9",
4
4
  "description": "一个实用的AI辅助工具",
5
5
  "main": "dist/src/index.js",
6
6
  "types": "dist/src/index.d.ts",
@@ -32,6 +32,7 @@
32
32
  "dependencies": {
33
33
  "@google-cloud/storage": "^7.17.1",
34
34
  "axios": "^1.12.1",
35
+ "chalk": "^4.1.2",
35
36
  "commander": "^10.0.0",
36
37
  "inquirer": "^12.9.4",
37
38
  "md5-file": "^5.0.0"
@@ -44,20 +44,38 @@ const fs = __importStar(require("fs"));
44
44
  const path = __importStar(require("path"));
45
45
  const axios_1 = __importDefault(require("axios"));
46
46
  const inquirer_1 = __importDefault(require("inquirer"));
47
+ const chalk_1 = __importDefault(require("chalk"));
47
48
  const upload_1 = require("./upload");
48
49
  const uploadWithConfig_1 = require("./uploadWithConfig");
49
50
  const cache_1 = require("./cache");
50
51
  const child_process_1 = require("child_process");
51
52
  /**
52
- * 获取环境配置文件
53
+ * 从GCP存储读取环境配置文件
53
54
  */
54
- const getConfigFiles = (env, config) => {
55
+ const getConfigFiles = (env, config, keyFile) => {
55
56
  return new Promise(async (resolve) => {
56
57
  try {
57
- const { data: sitemap = { projects: [] } } = await axios_1.default.get(`${config.aws.HostName}/${config.aws.prefix}/static/config/${env}.config.json`);
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());
58
75
  resolve({ data: sitemap });
59
76
  }
60
77
  catch (e) {
78
+ console.log(`读取配置文件失败: ${e instanceof Error ? e.message : String(e)}`);
61
79
  resolve({ data: { projects: [] } });
62
80
  }
63
81
  });
@@ -175,7 +193,7 @@ async function uploadToGcp(filePath, bucketName, destination, keyFile) {
175
193
  async function updateEnvironmentConfig(env, projectName, versionInfo, config, keyFile) {
176
194
  try {
177
195
  // 获取当前环境配置
178
- const { data: envConfig } = await getConfigFiles(env, config);
196
+ const { data: envConfig } = await getConfigFiles(env, config, keyFile);
179
197
  // 查找或创建项目配置
180
198
  let projectConfig = envConfig.projects.find((p) => p.name === projectName);
181
199
  if (!projectConfig) {
@@ -197,11 +215,14 @@ async function updateEnvironmentConfig(env, projectName, versionInfo, config, ke
197
215
  const configPath = `${config.aws.prefix}/static/config/${env}.config.json`;
198
216
  const tempFile = path.join(process.cwd(), `temp-${env}-config.json`);
199
217
  fs.writeFileSync(tempFile, JSON.stringify(envConfig, null, 2));
200
- const result = await uploadToGcp(tempFile, config.bucketName, configPath, keyFile);
218
+ console.log(configPath, JSON.stringify(envConfig, null, 2));
219
+ const result = await uploadToGcp(tempFile, config.aws.Bucket, configPath, keyFile);
201
220
  fs.unlinkSync(tempFile);
221
+ console.log('更新环境配置状态:', JSON.stringify(result), tempFile, config.aws.Bucket, configPath, keyFile);
202
222
  return result.success;
203
223
  }
204
- catch (_a) {
224
+ catch (e) {
225
+ console.log('更新环境配置失败:', e);
205
226
  return false;
206
227
  }
207
228
  }
@@ -217,12 +238,11 @@ async function deployFiles(options) {
217
238
  // 2. 执行upload-config阶段
218
239
  console.log('📤 执行upload-config上传配置文件...');
219
240
  try {
220
- const uploadResult = await (0, uploadWithConfig_1.uploadFilesWithConfig)({
241
+ await (0, uploadWithConfig_1.uploadFilesWithConfig)({
221
242
  configPath: options.config,
222
243
  storageClientOptions: options.keyFile ? { keyFilename: options.keyFile } : {},
223
244
  enableCache: true
224
245
  });
225
- console.log(`✅ upload-config完成: 成功${uploadResult.success.length}个,失败${uploadResult.failed.length}个`);
226
246
  }
227
247
  catch (error) {
228
248
  console.warn(`⚠️ upload-config执行失败: ${error instanceof Error ? error.message : String(error)}`);
@@ -261,9 +281,10 @@ async function deployFiles(options) {
261
281
  });
262
282
  if (result.success) {
263
283
  uploadedFiles.push(relativePath);
284
+ console.log(chalk_1.default.green(` ✅ ${relativePath}: ${result.url || destination}`));
264
285
  }
265
286
  else {
266
- console.warn(` 警告: ${relativePath} 上传失败: ${result.error}`);
287
+ console.log(chalk_1.default.red(` ${relativePath}: ${result.error || '上传失败'}`));
267
288
  }
268
289
  }
269
290
  // 6. 发布配置文件上传阶段
@@ -333,7 +354,8 @@ async function deployFiles(options) {
333
354
  // 7. 环境配置同步阶段
334
355
  console.log('🔄 同步环境配置...');
335
356
  // 检查项目是否存在
336
- 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));
337
359
  const existingProject = envConfig.projects.find((p) => p.name === projectInfo.name);
338
360
  if (!existingProject) {
339
361
  if (options.force) {
@@ -362,7 +384,8 @@ async function deployFiles(options) {
362
384
  timestamp: Date.now(),
363
385
  files: obj.links
364
386
  };
365
- 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));
366
389
  // 8. 发布完成阶段
367
390
  console.log('💾 记录发布版本...');
368
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>): Promise<{
64
+ (env: string, config: Record<string, any>, keyFile?: string): Promise<{
65
65
  data: {
66
66
  projects: Array<any>;
67
67
  };
@@ -32,6 +32,9 @@ var __importStar = (this && this.__importStar) || (function () {
32
32
  return result;
33
33
  };
34
34
  })();
35
+ var __importDefault = (this && this.__importDefault) || function (mod) {
36
+ return (mod && mod.__esModule) ? mod : { "default": mod };
37
+ };
35
38
  Object.defineProperty(exports, "__esModule", { value: true });
36
39
  exports.uploadFilesWithConfig = uploadFilesWithConfig;
37
40
  exports.getConfigSummary = getConfigSummary;
@@ -40,6 +43,7 @@ exports.getConfigSummary = getConfigSummary;
40
43
  */
41
44
  const storage_1 = require("@google-cloud/storage");
42
45
  const path = __importStar(require("path"));
46
+ const chalk_1 = __importDefault(require("chalk"));
43
47
  const upload_1 = require("./upload");
44
48
  const config_1 = require("./config");
45
49
  const cache_1 = require("./cache");
@@ -171,7 +175,22 @@ async function uploadFilesWithConfig(options = {}) {
171
175
  }
172
176
  console.log(`已更新缓存,新增 ${result.success.length} 个文件记录`);
173
177
  }
174
- console.log(`上传完成! 成功: ${result.success.length}, 失败: ${result.failed.length}, 跳过: ${skippedFiles.length}`);
178
+ // 显示上传结果
179
+ if (result.success.length > 0) {
180
+ console.log(chalk_1.default.green(`✅ 上传成功: ${result.success.length}个文件`));
181
+ result.success.forEach(file => {
182
+ console.log(chalk_1.default.green(` ✅ ${file.file}: ${file.url}`));
183
+ });
184
+ }
185
+ if (result.failed.length > 0) {
186
+ console.log(chalk_1.default.red(`❌ 上传失败: ${result.failed.length}个文件`));
187
+ result.failed.forEach(file => {
188
+ console.log(chalk_1.default.red(` ❌ ${file.file}: ${file.error}`));
189
+ });
190
+ }
191
+ if (skippedFiles.length > 0) {
192
+ console.log(chalk_1.default.yellow(`⏭️ 跳过: ${skippedFiles.length}个文件(已存在于缓存中)`));
193
+ }
175
194
  // 合并跳过的文件到成功结果中
176
195
  if (skippedFiles.length > 0 && cacheManager) {
177
196
  const skippedResults = skippedFiles.map(file => ({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ai-yuca",
3
- "version": "1.0.7",
3
+ "version": "1.0.9",
4
4
  "description": "一个实用的AI辅助工具",
5
5
  "main": "dist/src/index.js",
6
6
  "types": "dist/src/index.d.ts",
@@ -32,6 +32,7 @@
32
32
  "dependencies": {
33
33
  "@google-cloud/storage": "^7.17.1",
34
34
  "axios": "^1.12.1",
35
+ "chalk": "^4.1.2",
35
36
  "commander": "^10.0.0",
36
37
  "inquirer": "^12.9.4",
37
38
  "md5-file": "^5.0.0"
package/src/deploy.ts CHANGED
@@ -6,6 +6,7 @@ import * as fs from 'fs';
6
6
  import * as path from 'path';
7
7
  import axios from 'axios';
8
8
  import inquirer from 'inquirer';
9
+ import chalk from 'chalk';
9
10
  import { createStorageClient, uploadFile } from './upload';
10
11
  import { getConfigSummary, uploadFilesWithConfig } from './uploadWithConfig';
11
12
  import { readLastUploadCacheFile, writeLastDeployVersion } from './cache';
@@ -22,16 +23,33 @@ import {
22
23
  } from './types/deploy';
23
24
 
24
25
  /**
25
- * 获取环境配置文件
26
+ * 从GCP存储读取环境配置文件
26
27
  */
27
- const getConfigFiles: GetConfigFilesFunction = (env, config) => {
28
+ const getConfigFiles: GetConfigFilesFunction = (env, config, keyFile) => {
28
29
  return new Promise(async resolve => {
29
30
  try {
30
- const { data: sitemap = { projects: [] } } = await axios.get(
31
- `${config.aws.HostName}/${config.aws.prefix}/static/config/${env}.config.json`
32
- );
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());
33
50
  resolve({ data: sitemap });
34
51
  } catch (e) {
52
+ console.log(`读取配置文件失败: ${e instanceof Error ? e.message : String(e)}`);
35
53
  resolve({ data: { projects: [] } });
36
54
  }
37
55
  });
@@ -155,7 +173,7 @@ async function uploadToGcp(
155
173
  storageClient: client,
156
174
  enableCompression: true
157
175
  });
158
-
176
+
159
177
  if (result.success) {
160
178
  return { success: true, url: result.url };
161
179
  } else {
@@ -182,7 +200,7 @@ async function updateEnvironmentConfig(
182
200
  ): Promise<boolean> {
183
201
  try {
184
202
  // 获取当前环境配置
185
- const { data: envConfig } = await getConfigFiles(env, config);
203
+ const { data: envConfig } = await getConfigFiles(env, config, keyFile);
186
204
 
187
205
  // 查找或创建项目配置
188
206
  let projectConfig = envConfig.projects.find((p: any) => p.name === projectName);
@@ -207,13 +225,16 @@ async function updateEnvironmentConfig(
207
225
  const tempFile = path.join(process.cwd(), `temp-${env}-config.json`);
208
226
 
209
227
  fs.writeFileSync(tempFile, JSON.stringify(envConfig, null, 2));
228
+
229
+ console.log(configPath, JSON.stringify(envConfig, null, 2));
210
230
 
211
- const result = await uploadToGcp(tempFile, config.bucketName, configPath, keyFile);
231
+ const result = await uploadToGcp(tempFile, config.aws.Bucket, configPath, keyFile);
212
232
 
213
233
  fs.unlinkSync(tempFile);
214
-
234
+ console.log('更新环境配置状态:', JSON.stringify(result), tempFile, config.aws.Bucket, configPath, keyFile);
215
235
  return result.success;
216
- } catch {
236
+ } catch(e) {
237
+ console.log('更新环境配置失败:', e);
217
238
  return false;
218
239
  }
219
240
  }
@@ -234,12 +255,11 @@ export async function deployFiles(options: DeployCommandOptions): Promise<Deploy
234
255
  // 2. 执行upload-config阶段
235
256
  console.log('📤 执行upload-config上传配置文件...');
236
257
  try {
237
- const uploadResult = await uploadFilesWithConfig({
258
+ await uploadFilesWithConfig({
238
259
  configPath: options.config,
239
260
  storageClientOptions: options.keyFile ? { keyFilename: options.keyFile } : {},
240
261
  enableCache: true
241
262
  });
242
- console.log(`✅ upload-config完成: 成功${uploadResult.success.length}个,失败${uploadResult.failed.length}个`);
243
263
  } catch (error) {
244
264
  console.warn(`⚠️ upload-config执行失败: ${error instanceof Error ? error.message : String(error)}`);
245
265
  }
@@ -287,8 +307,9 @@ export async function deployFiles(options: DeployCommandOptions): Promise<Deploy
287
307
 
288
308
  if (result.success) {
289
309
  uploadedFiles.push(relativePath);
310
+ console.log(chalk.green(` ✅ ${relativePath}: ${result.url || destination}`));
290
311
  } else {
291
- console.warn(` 警告: ${relativePath} 上传失败: ${result.error}`);
312
+ console.log(chalk.red(` ${relativePath}: ${result.error || '上传失败'}`));
292
313
  }
293
314
  }
294
315
 
@@ -365,7 +386,10 @@ export async function deployFiles(options: DeployCommandOptions): Promise<Deploy
365
386
  console.log('🔄 同步环境配置...');
366
387
 
367
388
  // 检查项目是否存在
368
- 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
+
369
393
  const existingProject = envConfig.projects.find((p: any) => p.name === projectInfo.name);
370
394
 
371
395
  if (!existingProject) {
@@ -397,8 +421,8 @@ export async function deployFiles(options: DeployCommandOptions): Promise<Deploy
397
421
  files: obj.links
398
422
  };
399
423
 
400
- await updateEnvironmentConfig(options.env, projectInfo.name, versionInfo, config, options.keyFile);
401
-
424
+ const projectConfigUpdate = await updateEnvironmentConfig(options.env, projectInfo.name, versionInfo, config, options.keyFile);
425
+ console.log('配置文件上传结果:',JSON.stringify(projectConfigUpdate));
402
426
  // 8. 发布完成阶段
403
427
  console.log('💾 记录发布版本...');
404
428
  writeLastDeployVersion(cdnKey);
@@ -70,5 +70,5 @@ export interface DeployResult {
70
70
  }
71
71
 
72
72
  export interface GetConfigFilesFunction {
73
- (env: string, config: Record<string, any>): Promise<{ data: { projects: Array<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 uploadFile(options: UploadFileOptions): Promise<UploadResult> {
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) {
@@ -4,6 +4,7 @@
4
4
  import { Storage } from '@google-cloud/storage';
5
5
  import * as path from 'path';
6
6
  import * as fs from 'fs';
7
+ import chalk from 'chalk';
7
8
  import { StorageClientOptions, UploadFilesResult } from './types/upload';
8
9
  import { uploadFiles } from './upload';
9
10
  import { loadConfig, getBucketName, getUploadDestination, getUploadSourcePath, VSConfig } from './config';
@@ -189,7 +190,22 @@ export async function uploadFilesWithConfig(options: UploadWithConfigOptions = {
189
190
  console.log(`已更新缓存,新增 ${result.success.length} 个文件记录`);
190
191
  }
191
192
 
192
- console.log(`上传完成! 成功: ${result.success.length}, 失败: ${result.failed.length}, 跳过: ${skippedFiles.length}`);
193
+ // 显示上传结果
194
+ if (result.success.length > 0) {
195
+ console.log(chalk.green(`✅ 上传成功: ${result.success.length}个文件`));
196
+ result.success.forEach(file => {
197
+ console.log(chalk.green(` ✅ ${file.file}: ${file.url}`));
198
+ });
199
+ }
200
+ if (result.failed.length > 0) {
201
+ console.log(chalk.red(`❌ 上传失败: ${result.failed.length}个文件`));
202
+ result.failed.forEach(file => {
203
+ console.log(chalk.red(` ❌ ${file.file}: ${file.error}`));
204
+ });
205
+ }
206
+ if (skippedFiles.length > 0) {
207
+ console.log(chalk.yellow(`⏭️ 跳过: ${skippedFiles.length}个文件(已存在于缓存中)`));
208
+ }
193
209
 
194
210
  // 合并跳过的文件到成功结果中
195
211
  if (skippedFiles.length > 0 && cacheManager) {