jacky-proxy 1.0.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.
@@ -0,0 +1,26 @@
1
+ /**
2
+ * config generate 命令实现
3
+ */
4
+
5
+ const path = require('path');
6
+ const { generateConfig } = require('../../scripts/generate-config');
7
+
8
+ async function configGenerateCommand(options) {
9
+ const opts = {
10
+ rootDir: options.root || process.cwd(),
11
+ outputPath: path.join(process.cwd(), options.output || 'proxy.config.json'),
12
+ libraryId: parseInt(options.libraryId || '2773'),
13
+ startId: parseInt(options.startId || '1')
14
+ };
15
+
16
+ try {
17
+ generateConfig(opts);
18
+ console.log('\n✨ 配置生成完成!');
19
+ } catch (error) {
20
+ console.error('\n❌ 配置生成失败:', error.message);
21
+ process.exit(1);
22
+ }
23
+ }
24
+
25
+ module.exports = configGenerateCommand;
26
+
@@ -0,0 +1,29 @@
1
+ /**
2
+ * config merge 命令实现
3
+ */
4
+
5
+ const fs = require('fs');
6
+ const path = require('path');
7
+ const { generateConfig, mergeConfig } = require('../../scripts/generate-config');
8
+
9
+ async function configMergeCommand(options) {
10
+ const configPath = path.join(process.cwd(), options.config || 'proxy.config.json');
11
+
12
+ if (!fs.existsSync(configPath)) {
13
+ console.error('❌ 现有配置文件不存在');
14
+ process.exit(1);
15
+ }
16
+
17
+ const existingConfig = JSON.parse(fs.readFileSync(configPath, 'utf-8'));
18
+ const newConfig = generateConfig({
19
+ rootDir: options.root || process.cwd(),
20
+ outputPath: null // 不保存,只返回配置对象
21
+ });
22
+ const mergedConfig = mergeConfig(existingConfig, newConfig);
23
+
24
+ fs.writeFileSync(configPath, JSON.stringify(mergedConfig, null, 2), 'utf-8');
25
+ console.log('\n✅ 配置合并完成');
26
+ }
27
+
28
+ module.exports = configMergeCommand;
29
+
@@ -0,0 +1,30 @@
1
+ /**
2
+ * config validate 命令实现
3
+ */
4
+
5
+ const path = require('path');
6
+ const { validateConfig } = require('../../scripts/generate-config');
7
+
8
+ async function configValidateCommand(options) {
9
+ const configPath = path.join(process.cwd(), options.config || 'proxy.config.json');
10
+ const result = validateConfig(configPath);
11
+
12
+ if (result.valid) {
13
+ console.log('\n✅ 配置文件验证通过');
14
+ if (result.warnings.length > 0) {
15
+ console.log('\n⚠️ 警告:');
16
+ result.warnings.forEach(w => console.log(` - ${w}`));
17
+ }
18
+ } else {
19
+ console.error('\n❌ 配置文件验证失败:');
20
+ result.errors.forEach(e => console.error(` - ${e}`));
21
+ if (result.warnings.length > 0) {
22
+ console.log('\n⚠️ 警告:');
23
+ result.warnings.forEach(w => console.log(` - ${w}`));
24
+ }
25
+ process.exit(1);
26
+ }
27
+ }
28
+
29
+ module.exports = configValidateCommand;
30
+