vcs-patch-deploy 1.1.1 → 1.3.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.
@@ -36,6 +36,17 @@ ${chalk.yellow('选项:')}
36
36
  --version=<版本号> 安装版本号(如 1.2.3,写入 VERSION.txt 与 versions.json)
37
37
  --only=<文件> 仅打包指定文件(逗号分隔,可重复;支持 @files.txt)
38
38
  --file-list=<文件> 文件列表(每行一个相对路径)
39
+ --from-worktree 允许用工作区内容打包(跳过与目标版本的一致性检查)
40
+ --worktree-diff SVN:直接打包工作副本改动(对比基准 revision,含未提交文件)
41
+ --apply-script=<文件> 使用自定义 apply-update.php 模板
42
+ --profile=<名称> 多环境基准(deploy/.last-deploy-marker.<名称>)
43
+ --protect=<路径> 受保护文件(逗号分隔,可重复;线上已存在则跳过覆盖)
44
+ --protect-file=<文件> 受保护文件列表(每行一个相对路径)
45
+ --no-archive 跳过本地版本归档(deploy/archive/)
46
+ --keep-versions=<N> 本地 archive 保留版本数(默认 10)
47
+ --prune-out 构建后清理 deploy/out 旧产物(patch-* / zip)
48
+ --keep-out=<N> deploy/out 保留数量(默认同 --keep-versions)
49
+ --link-archive archive 优先硬链接(同一磁盘可节省约一半空间)
39
50
  -h, --help 显示帮助
40
51
 
41
52
  ${chalk.yellow('环境变量:')}
@@ -46,6 +57,17 @@ ${chalk.yellow('环境变量:')}
46
57
  PATCH_ZIP_PREFIX zip 前缀
47
58
  PATCH_VERSION 安装版本号
48
59
  PATCH_FILE_LIST 仅打包的文件列表路径
60
+ PATCH_FROM_WORKTREE true 时允许用工作区内容打包
61
+ PATCH_DIFF_WORKTREE true 时打包 SVN 工作副本改动
62
+ PATCH_APPLY_SCRIPT 自定义 apply-update.php 路径
63
+ PATCH_PROFILE 多环境基准名称
64
+ PATCH_PROTECT 受保护文件(逗号分隔)
65
+ PATCH_PROTECT_FILE 受保护文件列表路径
66
+ PATCH_NO_ARCHIVE true 时跳过本地 archive
67
+ PATCH_KEEP_VERSIONS 本地 archive 保留版本数(默认 10)
68
+ PATCH_PRUNE_OUT true 时构建后清理 deploy/out 旧产物
69
+ PATCH_KEEP_OUT deploy/out 保留数量(默认同 PATCH_KEEP_VERSIONS)
70
+ PATCH_ARCHIVE_LINK true 时 archive 优先硬链接
49
71
 
50
72
  ${chalk.yellow('版本号 + 单独文件部署:')}
51
73
  patch-build --vcs=svn --version=1.2.3
@@ -70,7 +92,7 @@ ${chalk.yellow('服务器应用:')}
70
92
 
71
93
  function parseArgs () {
72
94
  const args = process.argv.slice(2)
73
- const opts = { showHelp: false, onlyFiles: [] }
95
+ const opts = { showHelp: false, onlyFiles: [], protectFiles: [] }
74
96
 
75
97
  for (const arg of args) {
76
98
  if (arg === '--help' || arg === '-h') opts.showHelp = true
@@ -78,17 +100,32 @@ function parseArgs () {
78
100
  else if (arg === '--mark-deployed') opts.markDeployed = true
79
101
  else if (arg === '--init') opts.init = true
80
102
  else if (arg === '--skip-validation') opts.skipValidation = true
81
- else if (arg.startsWith('--backend=')) opts.backend = arg.split('=')[1]
82
- else if (arg.startsWith('--vcs=')) opts.vcs = arg.split('=')[1]
83
- else if (arg.startsWith('--source=')) opts.sourceDir = arg.split('=')[1]
84
- else if (arg.startsWith('--deploy=')) opts.deployDir = arg.split('=')[1]
85
- else if (arg.startsWith('--from=')) opts.fromRef = arg.split('=')[1]
86
- else if (arg.startsWith('--to=')) opts.toRef = arg.split('=')[1]
87
- else if (arg.startsWith('--zip-prefix=')) opts.zipPrefix = arg.split('=')[1]
88
- else if (arg.startsWith('--version=')) opts.version = arg.split('=')[1]
89
- else if (arg.startsWith('--only=')) opts.onlyFiles.push(...arg.split('=')[1].split(','))
90
- else if (arg.startsWith('--file-list=')) opts.fileList = arg.split('=')[1]
91
- else console.warn(chalk.yellow(`未知参数: ${arg}`))
103
+ else if (arg.startsWith('--backend=')) opts.backend = arg.slice(arg.indexOf('=') + 1)
104
+ else if (arg.startsWith('--vcs=')) opts.vcs = arg.slice(arg.indexOf('=') + 1)
105
+ else if (arg.startsWith('--source=')) opts.sourceDir = arg.slice(arg.indexOf('=') + 1)
106
+ else if (arg.startsWith('--deploy=')) opts.deployDir = arg.slice(arg.indexOf('=') + 1)
107
+ else if (arg.startsWith('--from=')) opts.fromRef = arg.slice(arg.indexOf('=') + 1)
108
+ else if (arg.startsWith('--to=')) opts.toRef = arg.slice(arg.indexOf('=') + 1)
109
+ else if (arg.startsWith('--zip-prefix=')) opts.zipPrefix = arg.slice(arg.indexOf('=') + 1)
110
+ else if (arg.startsWith('--version=')) opts.version = arg.slice(arg.indexOf('=') + 1)
111
+ else if (arg.startsWith('--only=')) opts.onlyFiles.push(...arg.slice(arg.indexOf('=') + 1).split(','))
112
+ else if (arg.startsWith('--file-list=')) opts.fileList = arg.slice(arg.indexOf('=') + 1)
113
+ else if (arg === '--from-worktree') opts.fromWorktree = true
114
+ else if (arg === '--worktree-diff') opts.diffWorktree = true
115
+ else if (arg.startsWith('--apply-script=')) opts.applyScriptPath = arg.slice(arg.indexOf('=') + 1)
116
+ else if (arg.startsWith('--profile=')) opts.profile = arg.slice(arg.indexOf('=') + 1)
117
+ else if (arg.startsWith('--protect=')) opts.protectFiles.push(...arg.slice(arg.indexOf('=') + 1).split(','))
118
+ else if (arg.startsWith('--protect-file=')) opts.protectFile = arg.slice(arg.indexOf('=') + 1)
119
+ else if (arg === '--no-archive') opts.noArchive = true
120
+ else if (arg.startsWith('--keep-versions=')) opts.keepVersions = arg.slice(arg.indexOf('=') + 1)
121
+ else if (arg === '--prune-out') opts.pruneOut = true
122
+ else if (arg.startsWith('--keep-out=')) opts.keepOut = arg.slice(arg.indexOf('=') + 1)
123
+ else if (arg === '--link-archive') opts.archiveLink = true
124
+ else {
125
+ throw new Error(
126
+ `未知参数: ${arg}\n参数需使用 --name=value 形式(如 --source=./trunk);可用 --help 查看全部参数`
127
+ )
128
+ }
92
129
  }
93
130
 
94
131
  return opts
@@ -100,7 +137,6 @@ async function main () {
100
137
  showHelp()
101
138
  process.exit(0)
102
139
  }
103
-
104
140
  const config = resolveConfig({
105
141
  backend: opts.backend,
106
142
  vcs: opts.vcs,
@@ -115,6 +151,17 @@ async function main () {
115
151
  version: opts.version,
116
152
  onlyFiles: opts.onlyFiles,
117
153
  fileList: opts.fileList,
154
+ fromWorktree: opts.fromWorktree,
155
+ diffWorktree: opts.diffWorktree,
156
+ applyScriptPath: opts.applyScriptPath || undefined,
157
+ profile: opts.profile,
158
+ protectFiles: opts.protectFiles,
159
+ protectFile: opts.protectFile,
160
+ noArchive: opts.noArchive,
161
+ keepVersions: opts.keepVersions,
162
+ pruneOut: opts.pruneOut,
163
+ keepOut: opts.keepOut,
164
+ archiveLink: opts.archiveLink,
118
165
  pkgRoot: path.join(__dirname, '..')
119
166
  })
120
167
 
@@ -127,7 +174,11 @@ async function main () {
127
174
  }
128
175
 
129
176
  console.log(chalk.cyan(`后端: ${config.backend} VCS: ${config.vcs}`))
177
+ if (config.profile) {
178
+ console.log(chalk.cyan(`环境 profile: ${config.profile}(基准 deploy/.last-deploy-marker.${config.profile})`))
179
+ }
130
180
  console.log(chalk.gray(`源码: ${config.sourceDir}`))
181
+ console.log(chalk.gray(`apply 模板: ${config.applyScriptPath}`))
131
182
  console.log(chalk.gray(`deploy: ${config.deployDir}`))
132
183
 
133
184
  const result = await buildPatch(config)
@@ -139,6 +190,16 @@ async function main () {
139
190
  console.log(chalk.green(` 变更文件: ${result.fileCount} 删除: ${result.deletedCount}`))
140
191
  if (result.patchDir) console.log(chalk.green(` patch 目录: ${result.patchDir}`))
141
192
  if (result.zipPath) console.log(chalk.green(` zip: ${result.zipPath} (${result.zipSize} bytes)`))
193
+ if (result.archiveDir) console.log(chalk.green(` 归档: ${result.archiveDir}`))
194
+ if (result.prunedOut?.length) {
195
+ console.log(chalk.gray(` 已清理 out: ${result.prunedOut.length} 个旧产物`))
196
+ }
197
+ if (result.protectCount) {
198
+ console.log(chalk.gray(` 受保护文件: ${result.protectCount} 个(线上已存在则跳过覆盖)`))
199
+ }
200
+ if (result.deployVersionLabel) {
201
+ console.log(chalk.gray(` 部署版本标识: ${result.deployVersionLabel}`))
202
+ }
142
203
  }
143
204
 
144
205
  if (result.warnings?.length) {
@@ -32,6 +32,9 @@ ${chalk.yellow('选项:')}
32
32
  --only=<路径> 要提取的文件(逗号分隔,可重复;支持 @files.txt)
33
33
  --file-list=<文件> 每行一个相对路径的列表文件
34
34
  --deploy=<目录> deploy 目录
35
+ --apply-script=<文件> 使用自定义 apply-update.php 模板
36
+ --protect=<路径> 追加受保护文件(逗号分隔,可重复)
37
+ --protect-file=<文件> 追加受保护文件列表
35
38
  --no-zip 仅生成 patch 目录
36
39
  --register 将子集包写入 versions.json
37
40
  --list-versions 列出已注册版本
@@ -51,19 +54,26 @@ ${chalk.yellow('示例:')}
51
54
 
52
55
  function parseArgs () {
53
56
  const args = process.argv.slice(2)
54
- const opts = { showHelp: false, onlyFiles: [] }
57
+ const opts = { showHelp: false, onlyFiles: [], protectFiles: [] }
55
58
 
56
59
  for (const arg of args) {
57
60
  if (arg === '--help' || arg === '-h') opts.showHelp = true
58
61
  else if (arg === '--no-zip') opts.noZip = true
59
62
  else if (arg === '--register') opts.register = true
60
63
  else if (arg === '--list-versions') opts.listVersions = true
61
- else if (arg.startsWith('--version=')) opts.version = arg.split('=')[1]
62
- else if (arg.startsWith('--from-patch=')) opts.fromPatch = arg.split('=')[1]
63
- else if (arg.startsWith('--only=')) opts.onlyFiles.push(...arg.split('=')[1].split(','))
64
- else if (arg.startsWith('--file-list=')) opts.fileList = arg.split('=')[1]
65
- else if (arg.startsWith('--deploy=')) opts.deployDir = arg.split('=')[1]
66
- else console.warn(chalk.yellow(`未知参数: ${arg}`))
64
+ else if (arg.startsWith('--version=')) opts.version = arg.slice(arg.indexOf('=') + 1)
65
+ else if (arg.startsWith('--from-patch=')) opts.fromPatch = arg.slice(arg.indexOf('=') + 1)
66
+ else if (arg.startsWith('--only=')) opts.onlyFiles.push(...arg.slice(arg.indexOf('=') + 1).split(','))
67
+ else if (arg.startsWith('--file-list=')) opts.fileList = arg.slice(arg.indexOf('=') + 1)
68
+ else if (arg.startsWith('--deploy=')) opts.deployDir = arg.slice(arg.indexOf('=') + 1)
69
+ else if (arg.startsWith('--apply-script=')) opts.applyScriptPath = arg.slice(arg.indexOf('=') + 1)
70
+ else if (arg.startsWith('--protect=')) opts.protectFiles.push(...arg.slice(arg.indexOf('=') + 1).split(','))
71
+ else if (arg.startsWith('--protect-file=')) opts.protectFile = arg.slice(arg.indexOf('=') + 1)
72
+ else {
73
+ throw new Error(
74
+ `未知参数: ${arg}\n参数需使用 --name=value 形式;可用 --help 查看全部参数`
75
+ )
76
+ }
67
77
  }
68
78
 
69
79
  return opts
@@ -76,9 +86,14 @@ async function main () {
76
86
  process.exit(0)
77
87
  }
78
88
 
89
+ // 仅读取 deploy 元数据,不依赖当前目录的 VCS 类型
79
90
  const config = resolveConfig({
80
91
  deployDir: opts.deployDir,
81
- pkgRoot: path.join(__dirname, '..')
92
+ applyScriptPath: opts.applyScriptPath || undefined,
93
+ protectFiles: opts.protectFiles,
94
+ protectFile: opts.protectFile,
95
+ pkgRoot: path.join(__dirname, '..'),
96
+ needsVcs: false
82
97
  })
83
98
 
84
99
  if (opts.listVersions) {
@@ -106,6 +121,7 @@ async function main () {
106
121
  fileList: opts.fileList || null,
107
122
  noZip: opts.noZip,
108
123
  zipPrefix: config.zipPrefix,
124
+ protectFiles: config.protectFiles,
109
125
  registerSubset: Boolean(opts.register)
110
126
  })
111
127
 
package/env.example CHANGED
@@ -15,6 +15,9 @@ PATCH_BACKEND=php
15
15
  # 服务器 apply-update.php:备份根目录(默认 <Backend>/.deploy-backups/)
16
16
  # PATCH_BACKUP_DIR=/data/backups/my-api
17
17
 
18
+ # 服务器 apply-update.php:备份会话保留数量(默认 10,部署成功后自动清理)
19
+ # PATCH_KEEP_BACKUPS=10
20
+
18
21
  # zip 文件名前缀
19
22
  # PATCH_ZIP_PREFIX=backend-update
20
23
 
@@ -27,12 +30,39 @@ PATCH_BACKEND=php
27
30
  # 仅打包/部署的文件列表(每行一个相对路径)
28
31
  # PATCH_FILE_LIST=hotfix-files.txt
29
32
 
33
+ # 允许用工作区内容打包(跳过与目标版本的一致性校验,默认 false)
34
+ # PATCH_FROM_WORKTREE=false
35
+
36
+ # SVN:直接打包工作副本改动(对比基准 revision,含未提交文件,默认 false)
37
+ # PATCH_DIFF_WORKTREE=false
38
+
39
+ # 自定义 apply-update.php 模板(默认使用插件内置模板)
40
+ # PATCH_APPLY_SCRIPT=deploy/apply-update.php
41
+
42
+ # 多环境基准名称(使用 deploy/.last-deploy-marker.<profile>)
43
+ # PATCH_PROFILE=php85
44
+
45
+ # 受保护文件(线上已存在则跳过覆盖,逗号分隔;也可用 deploy/protect.txt)
46
+ # PATCH_PROTECT=config/date_config.json
47
+ # PATCH_PROTECT_FILE=protect-files.txt
48
+
30
49
  # 服务器 apply-update.php:仅部署指定文件(逗号分隔)
31
50
  # PATCH_DEPLOY_FILES=app/service/Foo.php,app/controller/Bar.php
32
51
 
33
52
  # 跳过 PHP 项目结构校验(非标准目录时使用)
34
53
  # PATCH_SKIP_VALIDATION=false
35
54
 
55
+ # 本地版本归档(deploy/archive/,默认保留 10 个版本)
56
+ # PATCH_NO_ARCHIVE=false
57
+ # PATCH_KEEP_VERSIONS=10
58
+ # 归档时优先硬链接(同一磁盘可节省约一半空间)
59
+ # PATCH_ARCHIVE_LINK=false
60
+
61
+ # 构建后清理 deploy/out 旧产物(patch-* 目录 / zip,默认 false)
62
+ # PATCH_PRUNE_OUT=false
63
+ # deploy/out 保留数量(默认同 PATCH_KEEP_VERSIONS)
64
+ # PATCH_KEEP_OUT=10
65
+
36
66
  # ---------- 工具路径(可选)----------
37
67
  # SVN_EXE=C:/Program Files/TortoiseSVN/bin/svn.exe
38
68
  # GIT_EXE=C:/Program Files/Git/bin/git.exe
@@ -15,6 +15,11 @@ const PHP_EXCLUDE_PATTERNS = [
15
15
  /(^|\/)public\/runtime\//,
16
16
  /(^|\/)public\/cache\//,
17
17
  /(^|\/)deploy\/out\//,
18
+ /(^|\/)deploy\/\.last-deploy-(?:marker|rev)/,
19
+ /(^|\/)deploy\/versions\.json$/,
20
+ /(^|\/)deploy\/protect\.txt$/,
21
+ /(^|\/)deploy\/archive\//,
22
+ /(^|\/)\.deploy-backups\//,
18
23
  /(^|\/)tests\/coverage\//,
19
24
  /(^|\/)build\//,
20
25
  /(^|\/)dist\//,