zen-gitsync 2.4.12 → 2.4.14

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.
@@ -1,16 +1,16 @@
1
- <!doctype html>
2
- <html lang="en">
3
- <head>
4
- <meta charset="UTF-8" />
5
- <link rel="icon" type="image/svg+xml" href="/favicon.svg" />
6
- <meta name="viewport" content="width=device-width, initial-scale=1.0" />
7
- <title>Zen-GitSync - Git同步工具</title>
8
- <script type="module" crossorigin src="/assets/index-BFihJBzC.js"></script>
9
- <link rel="modulepreload" crossorigin href="/assets/vendor-DJt7ABTC.js">
10
- <link rel="stylesheet" crossorigin href="/assets/vendor-D9qDBEE1.css">
11
- <link rel="stylesheet" crossorigin href="/assets/index-CK7Vijoe.css">
12
- </head>
13
- <body>
14
- <div id="app"></div>
15
- </body>
16
- </html>
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8" />
5
+ <link rel="icon" type="image/svg+xml" href="/favicon.svg" />
6
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
7
+ <title>Zen-GitSync - Git同步工具</title>
8
+ <script type="module" crossorigin src="/assets/index-CTaH84EG.js"></script>
9
+ <link rel="modulepreload" crossorigin href="/assets/vendor-DMUTcfLR.js">
10
+ <link rel="stylesheet" crossorigin href="/assets/vendor-HJmoQ7iQ.css">
11
+ <link rel="stylesheet" crossorigin href="/assets/index-BWRGBvFK.css">
12
+ </head>
13
+ <body>
14
+ <div id="app"></div>
15
+ </body>
16
+ </html>
@@ -1987,6 +1987,52 @@ async function startUIServer(noOpen = false, savePort = false) {
1987
1987
  }
1988
1988
  });
1989
1989
 
1990
+ // 解决冲突:保存解决后的文件内容
1991
+ app.post('/api/resolve-conflict', async (req, res) => {
1992
+ try {
1993
+ const { filePath, content } = req.body;
1994
+
1995
+ if (!filePath) {
1996
+ return res.status(400).json({
1997
+ success: false,
1998
+ error: '缺少文件路径参数'
1999
+ });
2000
+ }
2001
+
2002
+ if (content === undefined) {
2003
+ return res.status(400).json({
2004
+ success: false,
2005
+ error: '缺少文件内容参数'
2006
+ });
2007
+ }
2008
+
2009
+ try {
2010
+ // 写入解决后的内容到文件
2011
+ await fs.writeFile(filePath, content, 'utf8');
2012
+
2013
+ // 不自动添加到暂存区,让用户手动决定
2014
+ // Git 会自动将冲突已解决的文件标记为"已修改"状态
2015
+ // await execGitCommand(`git add "${filePath}"`);
2016
+
2017
+ res.json({
2018
+ success: true,
2019
+ message: '冲突已解决,文件已更新'
2020
+ });
2021
+ } catch (writeError) {
2022
+ res.status(500).json({
2023
+ success: false,
2024
+ error: `保存文件失败: ${writeError.message}`
2025
+ });
2026
+ }
2027
+ } catch (error) {
2028
+ console.error('解决冲突失败:', error);
2029
+ res.status(500).json({
2030
+ success: false,
2031
+ error: `解决冲突失败: ${error.message}`
2032
+ });
2033
+ }
2034
+ });
2035
+
1990
2036
  // 撤回文件修改
1991
2037
  app.post('/api/revert_file', async (req, res) => {
1992
2038
  try {
@@ -2843,6 +2889,136 @@ async function startUIServer(noOpen = false, savePort = false) {
2843
2889
  }
2844
2890
  });
2845
2891
 
2892
+ // ========== NPM 脚本管理相关 API ==========
2893
+
2894
+ // 扫描项目目录及子目录下的所有package.json,并提取scripts
2895
+ app.get('/api/scan-npm-scripts', async (req, res) => {
2896
+ try {
2897
+ const projectRoot = process.cwd();
2898
+ const packageJsons = [];
2899
+
2900
+ // 递归扫描目录查找package.json
2901
+ async function scanDirectory(dir, depth = 0) {
2902
+ // 限制扫描深度,避免扫描过深
2903
+ if (depth > 5) return;
2904
+
2905
+ try {
2906
+ const items = await fs.readdir(dir, { withFileTypes: true });
2907
+
2908
+ for (const item of items) {
2909
+ const fullPath = path.join(dir, item.name);
2910
+
2911
+ // 跳过常见的不需要扫描的目录
2912
+ if (item.isDirectory()) {
2913
+ const dirName = item.name;
2914
+ if (dirName === 'node_modules' ||
2915
+ dirName === '.git' ||
2916
+ dirName === 'dist' ||
2917
+ dirName === 'build' ||
2918
+ dirName.startsWith('.')) {
2919
+ continue;
2920
+ }
2921
+
2922
+ // 递归扫描子目录
2923
+ await scanDirectory(fullPath, depth + 1);
2924
+ } else if (item.name === 'package.json') {
2925
+ // 读取package.json文件
2926
+ try {
2927
+ const content = await fs.readFile(fullPath, 'utf8');
2928
+ const packageData = JSON.parse(content);
2929
+
2930
+ // 只有当scripts存在且至少有一个脚本时才添加
2931
+ if (packageData.scripts && Object.keys(packageData.scripts).length > 0) {
2932
+ const relativePath = path.relative(projectRoot, dir);
2933
+ packageJsons.push({
2934
+ path: dir,
2935
+ relativePath: relativePath || '.',
2936
+ name: packageData.name || path.basename(dir),
2937
+ scripts: packageData.scripts
2938
+ });
2939
+ }
2940
+ } catch (error) {
2941
+ console.error(`读取package.json失败: ${fullPath}`, error);
2942
+ }
2943
+ }
2944
+ }
2945
+ } catch (error) {
2946
+ console.error(`扫描目录失败: ${dir}`, error);
2947
+ }
2948
+ }
2949
+
2950
+ // 从项目根目录开始扫描
2951
+ await scanDirectory(projectRoot);
2952
+
2953
+ res.json({
2954
+ success: true,
2955
+ packages: packageJsons,
2956
+ totalScripts: packageJsons.reduce((sum, pkg) => sum + Object.keys(pkg.scripts).length, 0)
2957
+ });
2958
+ } catch (error) {
2959
+ console.error('扫描npm脚本失败:', error);
2960
+ res.status(500).json({
2961
+ success: false,
2962
+ error: `扫描npm脚本失败: ${error.message}`
2963
+ });
2964
+ }
2965
+ });
2966
+
2967
+ // 在新终端中执行npm脚本
2968
+ app.post('/api/run-npm-script', async (req, res) => {
2969
+ try {
2970
+ const { packagePath, scriptName } = req.body;
2971
+
2972
+ if (!packagePath || !scriptName) {
2973
+ return res.status(400).json({
2974
+ success: false,
2975
+ error: '缺少必要参数:packagePath 和 scriptName'
2976
+ });
2977
+ }
2978
+
2979
+ console.log(`执行npm脚本: ${scriptName} in ${packagePath}`);
2980
+
2981
+ // 根据操作系统选择合适的终端命令
2982
+ let terminalCommand;
2983
+ const npmCommand = `npm run ${scriptName}`;
2984
+
2985
+ if (process.platform === 'win32') {
2986
+ // Windows: 使用 start 命令打开新的 cmd 窗口
2987
+ // /K 参数表示执行命令后保持窗口打开
2988
+ terminalCommand = `start cmd /K "cd /d ${packagePath} && ${npmCommand}"`;
2989
+ } else if (process.platform === 'darwin') {
2990
+ // macOS: 使用 osascript 打开 Terminal.app
2991
+ const script = `tell application "Terminal" to do script "cd ${packagePath} && ${npmCommand}"`;
2992
+ terminalCommand = `osascript -e '${script}'`;
2993
+ } else {
2994
+ // Linux: 尝试常见的终端模拟器
2995
+ // 优先使用 gnome-terminal, 然后是 xterm
2996
+ terminalCommand = `gnome-terminal -- bash -c "cd ${packagePath} && ${npmCommand}; exec bash" || xterm -e "cd ${packagePath} && ${npmCommand}; bash"`;
2997
+ }
2998
+
2999
+ // 执行命令打开新终端
3000
+ const { exec } = await import('child_process');
3001
+ exec(terminalCommand, (error, stdout, stderr) => {
3002
+ if (error) {
3003
+ console.error('打开终端失败:', error);
3004
+ }
3005
+ });
3006
+
3007
+ res.json({
3008
+ success: true,
3009
+ message: `已在新终端中执行: ${scriptName}`,
3010
+ command: npmCommand,
3011
+ path: packagePath
3012
+ });
3013
+ } catch (error) {
3014
+ console.error('执行npm脚本失败:', error);
3015
+ res.status(500).json({
3016
+ success: false,
3017
+ error: `执行npm脚本失败: ${error.message}`
3018
+ });
3019
+ }
3020
+ });
3021
+
2846
3022
  // Socket.io 实时更新
2847
3023
  io.on('connection', (socket) => {
2848
3024
  console.log('客户端已连接:', socket.id);