vcs-patch-deploy 1.2.0 → 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.
- package/CHANGELOG.md +48 -0
- package/README.md +181 -8
- package/assets/php/apply-update.php +727 -32
- package/bin/patch-build.js +63 -14
- package/bin/patch-extract.js +24 -8
- package/env.example +26 -0
- package/lib/backends/php.js +5 -0
- package/lib/build-patch.js +350 -49
- package/lib/config.js +83 -13
- package/lib/extract-patch.js +100 -17
- package/lib/file-filter.js +20 -0
- package/lib/git.js +161 -22
- package/lib/index.js +23 -4
- package/lib/manifest.js +65 -2
- package/lib/marker.js +79 -14
- package/lib/modes.js +72 -0
- package/lib/out-prune.js +121 -0
- package/lib/protect.js +124 -0
- package/lib/svn.js +409 -12
- package/lib/version-archive.js +106 -10
- package/lib/version-registry.js +87 -8
- package/lib/zip.js +126 -8
- package/package.json +5 -2
package/bin/patch-build.js
CHANGED
|
@@ -36,8 +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=<文件> 受保护文件列表(每行一个相对路径)
|
|
39
45
|
--no-archive 跳过本地版本归档(deploy/archive/)
|
|
40
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 优先硬链接(同一磁盘可节省约一半空间)
|
|
41
50
|
-h, --help 显示帮助
|
|
42
51
|
|
|
43
52
|
${chalk.yellow('环境变量:')}
|
|
@@ -48,8 +57,17 @@ ${chalk.yellow('环境变量:')}
|
|
|
48
57
|
PATCH_ZIP_PREFIX zip 前缀
|
|
49
58
|
PATCH_VERSION 安装版本号
|
|
50
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 受保护文件列表路径
|
|
51
66
|
PATCH_NO_ARCHIVE true 时跳过本地 archive
|
|
52
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 优先硬链接
|
|
53
71
|
|
|
54
72
|
${chalk.yellow('版本号 + 单独文件部署:')}
|
|
55
73
|
patch-build --vcs=svn --version=1.2.3
|
|
@@ -74,7 +92,7 @@ ${chalk.yellow('服务器应用:')}
|
|
|
74
92
|
|
|
75
93
|
function parseArgs () {
|
|
76
94
|
const args = process.argv.slice(2)
|
|
77
|
-
const opts = { showHelp: false, onlyFiles: [] }
|
|
95
|
+
const opts = { showHelp: false, onlyFiles: [], protectFiles: [] }
|
|
78
96
|
|
|
79
97
|
for (const arg of args) {
|
|
80
98
|
if (arg === '--help' || arg === '-h') opts.showHelp = true
|
|
@@ -82,19 +100,32 @@ function parseArgs () {
|
|
|
82
100
|
else if (arg === '--mark-deployed') opts.markDeployed = true
|
|
83
101
|
else if (arg === '--init') opts.init = true
|
|
84
102
|
else if (arg === '--skip-validation') opts.skipValidation = true
|
|
85
|
-
else if (arg.startsWith('--backend=')) opts.backend = arg.
|
|
86
|
-
else if (arg.startsWith('--vcs=')) opts.vcs = arg.
|
|
87
|
-
else if (arg.startsWith('--source=')) opts.sourceDir = arg.
|
|
88
|
-
else if (arg.startsWith('--deploy=')) opts.deployDir = arg.
|
|
89
|
-
else if (arg.startsWith('--from=')) opts.fromRef = arg.
|
|
90
|
-
else if (arg.startsWith('--to=')) opts.toRef = arg.
|
|
91
|
-
else if (arg.startsWith('--zip-prefix=')) opts.zipPrefix = arg.
|
|
92
|
-
else if (arg.startsWith('--version=')) opts.version = arg.
|
|
93
|
-
else if (arg.startsWith('--only=')) opts.onlyFiles.push(...arg.
|
|
94
|
-
else if (arg.startsWith('--file-list=')) opts.fileList = 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)
|
|
95
119
|
else if (arg === '--no-archive') opts.noArchive = true
|
|
96
|
-
else if (arg.startsWith('--keep-versions=')) opts.keepVersions = arg.
|
|
97
|
-
else
|
|
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
|
+
}
|
|
98
129
|
}
|
|
99
130
|
|
|
100
131
|
return opts
|
|
@@ -106,7 +137,6 @@ async function main () {
|
|
|
106
137
|
showHelp()
|
|
107
138
|
process.exit(0)
|
|
108
139
|
}
|
|
109
|
-
|
|
110
140
|
const config = resolveConfig({
|
|
111
141
|
backend: opts.backend,
|
|
112
142
|
vcs: opts.vcs,
|
|
@@ -121,8 +151,17 @@ async function main () {
|
|
|
121
151
|
version: opts.version,
|
|
122
152
|
onlyFiles: opts.onlyFiles,
|
|
123
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,
|
|
124
160
|
noArchive: opts.noArchive,
|
|
125
161
|
keepVersions: opts.keepVersions,
|
|
162
|
+
pruneOut: opts.pruneOut,
|
|
163
|
+
keepOut: opts.keepOut,
|
|
164
|
+
archiveLink: opts.archiveLink,
|
|
126
165
|
pkgRoot: path.join(__dirname, '..')
|
|
127
166
|
})
|
|
128
167
|
|
|
@@ -135,7 +174,11 @@ async function main () {
|
|
|
135
174
|
}
|
|
136
175
|
|
|
137
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
|
+
}
|
|
138
180
|
console.log(chalk.gray(`源码: ${config.sourceDir}`))
|
|
181
|
+
console.log(chalk.gray(`apply 模板: ${config.applyScriptPath}`))
|
|
139
182
|
console.log(chalk.gray(`deploy: ${config.deployDir}`))
|
|
140
183
|
|
|
141
184
|
const result = await buildPatch(config)
|
|
@@ -148,6 +191,12 @@ async function main () {
|
|
|
148
191
|
if (result.patchDir) console.log(chalk.green(` patch 目录: ${result.patchDir}`))
|
|
149
192
|
if (result.zipPath) console.log(chalk.green(` zip: ${result.zipPath} (${result.zipSize} bytes)`))
|
|
150
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
|
+
}
|
|
151
200
|
if (result.deployVersionLabel) {
|
|
152
201
|
console.log(chalk.gray(` 部署版本标识: ${result.deployVersionLabel}`))
|
|
153
202
|
}
|
package/bin/patch-extract.js
CHANGED
|
@@ -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.
|
|
62
|
-
else if (arg.startsWith('--from-patch=')) opts.fromPatch = arg.
|
|
63
|
-
else if (arg.startsWith('--only=')) opts.onlyFiles.push(...arg.
|
|
64
|
-
else if (arg.startsWith('--file-list=')) opts.fileList = arg.
|
|
65
|
-
else if (arg.startsWith('--deploy=')) opts.deployDir = arg.
|
|
66
|
-
else
|
|
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
|
-
|
|
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,6 +30,22 @@ 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
|
|
|
@@ -36,6 +55,13 @@ PATCH_BACKEND=php
|
|
|
36
55
|
# 本地版本归档(deploy/archive/,默认保留 10 个版本)
|
|
37
56
|
# PATCH_NO_ARCHIVE=false
|
|
38
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
|
|
39
65
|
|
|
40
66
|
# ---------- 工具路径(可选)----------
|
|
41
67
|
# SVN_EXE=C:/Program Files/TortoiseSVN/bin/svn.exe
|
package/lib/backends/php.js
CHANGED
|
@@ -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\//,
|