zen-gitsync 2.7.9 → 2.7.10

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.
@@ -6,10 +6,10 @@
6
6
  <link rel="icon" type="image/svg+xml" href="/favicon.svg" />
7
7
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
8
8
  <title>Zen GitSync</title>
9
- <script type="module" crossorigin src="/assets/index-CFXjsP1g.js"></script>
10
- <link rel="modulepreload" crossorigin href="/assets/vendor-CnppVQxb.js">
11
- <link rel="stylesheet" crossorigin href="/assets/vendor-DQLOxj05.css">
12
- <link rel="stylesheet" crossorigin href="/assets/index-CpTr2__Z.css">
9
+ <script type="module" crossorigin src="/assets/index-CVhwVTl2.js"></script>
10
+ <link rel="modulepreload" crossorigin href="/assets/vendor-BdOLKL5j.js">
11
+ <link rel="stylesheet" crossorigin href="/assets/vendor-BWT9SBHo.css">
12
+ <link rel="stylesheet" crossorigin href="/assets/index-0TRm0C2H.css">
13
13
  </head>
14
14
  <body>
15
15
  <div id="app"></div>
@@ -1920,10 +1920,10 @@ async function startUIServer(noOpen = false, savePort = false) {
1920
1920
  }
1921
1921
  })
1922
1922
 
1923
- // 版本号递增
1924
- app.post('/api/version-bump', express.json(), async (req, res) => {
1923
+ // 读取 package.json 文件内容
1924
+ app.post('/api/read-package-json', express.json(), async (req, res) => {
1925
1925
  try {
1926
- const { bumpType, packageJsonPath } = req.body
1926
+ const { packageJsonPath } = req.body
1927
1927
 
1928
1928
  // 确定 package.json 的路径
1929
1929
  let pkgPath
@@ -1935,7 +1935,7 @@ async function startUIServer(noOpen = false, savePort = false) {
1935
1935
  pkgPath = path.join(currentProjectPath, 'package.json')
1936
1936
  }
1937
1937
 
1938
- // 检查文件是否存在(使用 Node.js 原生方法)
1938
+ // 检查文件是否存在
1939
1939
  try {
1940
1940
  await fs.access(pkgPath)
1941
1941
  } catch (err) {
@@ -1949,49 +1949,169 @@ async function startUIServer(noOpen = false, savePort = false) {
1949
1949
  const pkgContent = await fs.readFile(pkgPath, 'utf8')
1950
1950
  const pkg = JSON.parse(pkgContent)
1951
1951
 
1952
- if (!pkg.version) {
1953
- return res.status(400).json({
1954
- success: false,
1955
- error: 'package.json 中未找到 version 字段'
1956
- })
1957
- }
1952
+ res.json({
1953
+ success: true,
1954
+ dependencies: pkg.dependencies || {},
1955
+ devDependencies: pkg.devDependencies || {},
1956
+ version: pkg.version
1957
+ })
1958
+ } catch (error) {
1959
+ res.status(500).json({ success: false, error: error.message })
1960
+ }
1961
+ })
1962
+
1963
+ // 版本号递增或依赖版本修改
1964
+ app.post('/api/version-bump', express.json(), async (req, res) => {
1965
+ try {
1966
+ const { bumpType, packageJsonPath, versionTarget, dependencyName, dependencyVersion, dependencyVersionBump, dependencyType } = req.body
1958
1967
 
1959
- const oldVersion = pkg.version
1968
+ // 确定 package.json 的路径
1969
+ let pkgPath
1970
+ if (packageJsonPath && packageJsonPath.trim()) {
1971
+ pkgPath = path.isAbsolute(packageJsonPath)
1972
+ ? packageJsonPath
1973
+ : path.join(currentProjectPath, packageJsonPath)
1974
+ } else {
1975
+ pkgPath = path.join(currentProjectPath, 'package.json')
1976
+ }
1960
1977
 
1961
- // 解析版本号
1962
- const versionParts = oldVersion.split('.').map(Number)
1963
- if (versionParts.length !== 3 || versionParts.some(isNaN)) {
1964
- return res.status(400).json({
1978
+ // 检查文件是否存在(使用 Node.js 原生方法)
1979
+ try {
1980
+ await fs.access(pkgPath)
1981
+ } catch (err) {
1982
+ return res.status(404).json({
1965
1983
  success: false,
1966
- error: `无效的版本号格式: ${oldVersion},应为 x.y.z 格式`
1984
+ error: `未找到 package.json 文件: ${pkgPath}`
1967
1985
  })
1968
1986
  }
1969
1987
 
1970
- // 根据类型递增版本号
1971
- let [major, minor, patch] = versionParts
1972
- if (bumpType === 'major') {
1973
- major += 1
1974
- minor = 0
1975
- patch = 0
1976
- } else if (bumpType === 'minor') {
1977
- minor += 1
1978
- patch = 0
1979
- } else { // patch
1980
- patch += 1
1981
- }
1982
-
1983
- const newVersion = `${major}.${minor}.${patch}`
1984
- pkg.version = newVersion
1985
-
1986
- // 写回 package.json(保持格式化)
1987
- await fs.writeFile(pkgPath, JSON.stringify(pkg, null, 2) + '\n', 'utf8')
1988
+ // 读取 package.json
1989
+ const pkgContent = await fs.readFile(pkgPath, 'utf8')
1990
+ const pkg = JSON.parse(pkgContent)
1988
1991
 
1989
- res.json({
1990
- success: true,
1991
- oldVersion,
1992
- newVersion,
1993
- filePath: pkgPath
1994
- })
1992
+ // 判断是修改 version 还是 dependency
1993
+ if (versionTarget === 'dependency') {
1994
+ // 修改依赖版本
1995
+ const depType = dependencyType || 'dependencies'
1996
+
1997
+ if (!pkg[depType]) {
1998
+ return res.status(400).json({
1999
+ success: false,
2000
+ error: `package.json 中未找到 ${depType} 字段`
2001
+ })
2002
+ }
2003
+
2004
+ if (!pkg[depType][dependencyName]) {
2005
+ return res.status(400).json({
2006
+ success: false,
2007
+ error: `在 ${depType} 中未找到依赖包: ${dependencyName}`
2008
+ })
2009
+ }
2010
+
2011
+ const oldVersion = pkg[depType][dependencyName]
2012
+ let newVersion
2013
+
2014
+ // 判断是自动递增还是手动输入
2015
+ if (dependencyVersionBump) {
2016
+ // 自动递增模式:解析当前版本号并递增
2017
+ // 提取版本号中的数字部分(去除 ^, ~, >=, 等前缀)
2018
+ const versionMatch = oldVersion.match(/(\^|~|>=|>|<=|<)?(\d+\.\d+\.\d+)/)
2019
+ if (!versionMatch) {
2020
+ return res.status(400).json({
2021
+ success: false,
2022
+ error: `无法解析版本号: ${oldVersion},应为 x.y.z 格式(可带 ^, ~ 等前缀)`
2023
+ })
2024
+ }
2025
+
2026
+ const prefix = versionMatch[1] || ''
2027
+ const versionNumber = versionMatch[2]
2028
+ const versionParts = versionNumber.split('.').map(Number)
2029
+
2030
+ if (versionParts.length !== 3 || versionParts.some(isNaN)) {
2031
+ return res.status(400).json({
2032
+ success: false,
2033
+ error: `无效的版本号格式: ${versionNumber}`
2034
+ })
2035
+ }
2036
+
2037
+ // 根据类型递增版本号
2038
+ let [major, minor, patch] = versionParts
2039
+ if (dependencyVersionBump === 'major') {
2040
+ major += 1
2041
+ minor = 0
2042
+ patch = 0
2043
+ } else if (dependencyVersionBump === 'minor') {
2044
+ minor += 1
2045
+ patch = 0
2046
+ } else { // patch
2047
+ patch += 1
2048
+ }
2049
+
2050
+ newVersion = `${prefix}${major}.${minor}.${patch}`
2051
+ } else {
2052
+ // 手动输入模式
2053
+ newVersion = dependencyVersion
2054
+ }
2055
+
2056
+ pkg[depType][dependencyName] = newVersion
2057
+
2058
+ // 写回 package.json(保持格式化)
2059
+ await fs.writeFile(pkgPath, JSON.stringify(pkg, null, 2) + '\n', 'utf8')
2060
+
2061
+ res.json({
2062
+ success: true,
2063
+ oldVersion,
2064
+ newVersion,
2065
+ filePath: pkgPath,
2066
+ dependencyName,
2067
+ dependencyType: depType
2068
+ })
2069
+ } else {
2070
+ // 修改 version 字段(原有逻辑)
2071
+ if (!pkg.version) {
2072
+ return res.status(400).json({
2073
+ success: false,
2074
+ error: 'package.json 中未找到 version 字段'
2075
+ })
2076
+ }
2077
+
2078
+ const oldVersion = pkg.version
2079
+
2080
+ // 解析版本号
2081
+ const versionParts = oldVersion.split('.').map(Number)
2082
+ if (versionParts.length !== 3 || versionParts.some(isNaN)) {
2083
+ return res.status(400).json({
2084
+ success: false,
2085
+ error: `无效的版本号格式: ${oldVersion},应为 x.y.z 格式`
2086
+ })
2087
+ }
2088
+
2089
+ // 根据类型递增版本号
2090
+ let [major, minor, patch] = versionParts
2091
+ if (bumpType === 'major') {
2092
+ major += 1
2093
+ minor = 0
2094
+ patch = 0
2095
+ } else if (bumpType === 'minor') {
2096
+ minor += 1
2097
+ patch = 0
2098
+ } else { // patch
2099
+ patch += 1
2100
+ }
2101
+
2102
+ const newVersion = `${major}.${minor}.${patch}`
2103
+ pkg.version = newVersion
2104
+
2105
+ // 写回 package.json(保持格式化)
2106
+ await fs.writeFile(pkgPath, JSON.stringify(pkg, null, 2) + '\n', 'utf8')
2107
+
2108
+ res.json({
2109
+ success: true,
2110
+ oldVersion,
2111
+ newVersion,
2112
+ filePath: pkgPath
2113
+ })
2114
+ }
1995
2115
  } catch (error) {
1996
2116
  res.status(500).json({ success: false, error: error.message })
1997
2117
  }