build-version-tracker 0.0.1
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/README.md +361 -0
- package/dist/index.es +35 -0
- package/dist/index.js +1 -0
- package/dist/utils-BUNhE9qT.js +1 -0
- package/dist/utils-DMG0M2rI.mjs +69 -0
- package/dist/vite-plugin.es +43 -0
- package/dist/vite-plugin.js +1 -0
- package/package.json +49 -0
package/README.md
ADDED
|
@@ -0,0 +1,361 @@
|
|
|
1
|
+
# Build Version Tracker
|
|
2
|
+
|
|
3
|
+
一个通用的构建工具插件,用于版本跟踪和构建自动化(支持 Webpack 和 Vite)。
|
|
4
|
+
|
|
5
|
+
## 功能特性
|
|
6
|
+
|
|
7
|
+
- 📦 自动生成构建版本信息
|
|
8
|
+
- 🔍 记录构建人、分支和时间
|
|
9
|
+
- 📄 生成版本文件 (version.txt)
|
|
10
|
+
- 🗜️ 自动打包构建产物为 ZIP 文件
|
|
11
|
+
- 🌐 支持环境变量配置
|
|
12
|
+
- ⚡ 同时支持 Webpack 和 Vite 构建工具
|
|
13
|
+
- 🔧 支持 ES 模块和 CommonJS 模块
|
|
14
|
+
|
|
15
|
+
## 安装
|
|
16
|
+
|
|
17
|
+
### 基本安装
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npm install build-version-tracker
|
|
21
|
+
# 或
|
|
22
|
+
pnpm add build-version-tracker
|
|
23
|
+
# 或
|
|
24
|
+
yarn add build-version-tracker
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
### 依赖安装
|
|
28
|
+
|
|
29
|
+
插件需要以下依赖才能正常工作,请根据您的使用场景安装:
|
|
30
|
+
|
|
31
|
+
#### 如果使用 Webpack 插件:
|
|
32
|
+
```bash
|
|
33
|
+
npm install adm-zip webpack
|
|
34
|
+
# 或
|
|
35
|
+
pnpm add adm-zip webpack
|
|
36
|
+
# 或
|
|
37
|
+
yarn add adm-zip webpack
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
#### 如果使用 Vite 插件:
|
|
41
|
+
```bash
|
|
42
|
+
npm install adm-zip
|
|
43
|
+
# 或
|
|
44
|
+
pnpm add adm-zip
|
|
45
|
+
# 或
|
|
46
|
+
yarn add adm-zip
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
#### 一次性安装所有依赖:
|
|
50
|
+
```bash
|
|
51
|
+
npm install build-version-tracker adm-zip webpack
|
|
52
|
+
# 或
|
|
53
|
+
pnpm add build-version-tracker adm-zip webpack
|
|
54
|
+
# 或
|
|
55
|
+
yarn add build-version-tracker adm-zip webpack
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## 本地开发测试
|
|
59
|
+
|
|
60
|
+
### 使用 npm link 进行本地测试
|
|
61
|
+
|
|
62
|
+
如果您想在本地其他项目中测试该插件,可以使用 `npm link` 方法:
|
|
63
|
+
|
|
64
|
+
#### 1. 在插件项目中创建全局链接
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
# 进入插件项目目录
|
|
68
|
+
cd build-version-tracker
|
|
69
|
+
|
|
70
|
+
# 构建插件
|
|
71
|
+
npm run build
|
|
72
|
+
|
|
73
|
+
# 创建全局链接
|
|
74
|
+
npm link
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
#### 2. 在测试项目中链接插件
|
|
78
|
+
|
|
79
|
+
```bash
|
|
80
|
+
# 进入测试项目目录
|
|
81
|
+
cd /path/to/your/test-project
|
|
82
|
+
|
|
83
|
+
# 链接插件
|
|
84
|
+
npm link build-version-tracker
|
|
85
|
+
|
|
86
|
+
# 安装插件的 peerDependencies
|
|
87
|
+
npm install adm-zip webpack
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
#### 3. 在测试项目中使用插件
|
|
91
|
+
|
|
92
|
+
```javascript
|
|
93
|
+
// Webpack 配置示例
|
|
94
|
+
const BuildVersionTracker = require('build-version-tracker');
|
|
95
|
+
|
|
96
|
+
module.exports = {
|
|
97
|
+
// ... 其他配置
|
|
98
|
+
plugins: [
|
|
99
|
+
new BuildVersionTracker({
|
|
100
|
+
distPath: 'dist',
|
|
101
|
+
isBuild: true
|
|
102
|
+
})
|
|
103
|
+
]
|
|
104
|
+
};
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
#### 4. 取消链接(测试完成后)
|
|
108
|
+
|
|
109
|
+
```bash
|
|
110
|
+
# 在测试项目中取消链接
|
|
111
|
+
npm unlink build-version-tracker
|
|
112
|
+
|
|
113
|
+
# 重新安装正式版本(如果需要)
|
|
114
|
+
npm install build-version-tracker
|
|
115
|
+
|
|
116
|
+
# 在插件项目中取消全局链接
|
|
117
|
+
cd build-version-tracker
|
|
118
|
+
npm unlink
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
### 使用 pnpm link(如果使用 pnpm)
|
|
122
|
+
|
|
123
|
+
```bash
|
|
124
|
+
# 在插件项目中
|
|
125
|
+
pnpm link --global
|
|
126
|
+
|
|
127
|
+
# 在测试项目中
|
|
128
|
+
pnpm link --global build-version-tracker
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
### 使用 yarn link(如果使用 yarn)
|
|
132
|
+
|
|
133
|
+
```bash
|
|
134
|
+
# 在插件项目中
|
|
135
|
+
yarn link
|
|
136
|
+
|
|
137
|
+
# 在测试项目中
|
|
138
|
+
yarn link build-version-tracker
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
## 使用方法
|
|
142
|
+
|
|
143
|
+
### Webpack 插件使用
|
|
144
|
+
|
|
145
|
+
#### CommonJS 语法
|
|
146
|
+
```javascript
|
|
147
|
+
const BuildVersionTracker = require('build-version-tracker');
|
|
148
|
+
|
|
149
|
+
module.exports = {
|
|
150
|
+
// ... 其他配置
|
|
151
|
+
plugins: [
|
|
152
|
+
new BuildVersionTracker({
|
|
153
|
+
distPath: 'dist', // 构建输出目录,默认 'dist'
|
|
154
|
+
isBuild: false, // 是否启用构建,默认 false
|
|
155
|
+
htmlName: 'index.html' // HTML 文件名,默认 'index.html'
|
|
156
|
+
})
|
|
157
|
+
]
|
|
158
|
+
};
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
#### ES 模块语法
|
|
162
|
+
```javascript
|
|
163
|
+
import BuildVersionTracker from 'build-version-tracker';
|
|
164
|
+
|
|
165
|
+
export default {
|
|
166
|
+
// ... 其他配置
|
|
167
|
+
plugins: [
|
|
168
|
+
new BuildVersionTracker({
|
|
169
|
+
distPath: 'dist',
|
|
170
|
+
isBuild: false,
|
|
171
|
+
htmlName: 'index.html'
|
|
172
|
+
})
|
|
173
|
+
]
|
|
174
|
+
};
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
### Vite 插件使用
|
|
178
|
+
|
|
179
|
+
#### CommonJS 语法
|
|
180
|
+
```javascript
|
|
181
|
+
const viteVersionPlugin = require('build-version-tracker/vite');
|
|
182
|
+
|
|
183
|
+
export default {
|
|
184
|
+
plugins: [
|
|
185
|
+
viteVersionPlugin({
|
|
186
|
+
distPath: 'dist', // 构建输出目录,默认 'dist'
|
|
187
|
+
isBuild: false, // 是否启用构建,默认 false
|
|
188
|
+
htmlName: 'index.html' // HTML 文件名,默认 'index.html'
|
|
189
|
+
})
|
|
190
|
+
]
|
|
191
|
+
};
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
#### ES 模块语法
|
|
195
|
+
```javascript
|
|
196
|
+
import viteVersionPlugin from 'build-version-tracker/vite';
|
|
197
|
+
|
|
198
|
+
export default {
|
|
199
|
+
plugins: [
|
|
200
|
+
viteVersionPlugin({
|
|
201
|
+
distPath: 'dist',
|
|
202
|
+
isBuild: false,
|
|
203
|
+
htmlName: 'index.html'
|
|
204
|
+
})
|
|
205
|
+
]
|
|
206
|
+
};
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
### 配置说明
|
|
210
|
+
|
|
211
|
+
插件完全通过配置参数控制行为,不依赖环境变量。
|
|
212
|
+
|
|
213
|
+
## 示例
|
|
214
|
+
|
|
215
|
+
### Webpack 基础使用
|
|
216
|
+
|
|
217
|
+
```javascript
|
|
218
|
+
// webpack.config.js
|
|
219
|
+
const BuildVersionTracker = require('build-version-tracker');
|
|
220
|
+
|
|
221
|
+
module.exports = {
|
|
222
|
+
mode: 'production',
|
|
223
|
+
entry: './src/index.js',
|
|
224
|
+
output: {
|
|
225
|
+
path: path.resolve(__dirname, 'dist'),
|
|
226
|
+
filename: 'bundle.js'
|
|
227
|
+
},
|
|
228
|
+
plugins: [
|
|
229
|
+
new BuildVersionTracker()
|
|
230
|
+
]
|
|
231
|
+
};
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
### Vite 基础使用
|
|
235
|
+
|
|
236
|
+
```javascript
|
|
237
|
+
// vite.config.js
|
|
238
|
+
import viteVersionPlugin from 'build-version-tracker/vite';
|
|
239
|
+
|
|
240
|
+
export default {
|
|
241
|
+
plugins: [
|
|
242
|
+
viteVersionPlugin()
|
|
243
|
+
],
|
|
244
|
+
build: {
|
|
245
|
+
outDir: 'dist'
|
|
246
|
+
}
|
|
247
|
+
};
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
### 自定义配置
|
|
251
|
+
|
|
252
|
+
```javascript
|
|
253
|
+
// Webpack 自定义配置
|
|
254
|
+
new BuildVersionTracker({
|
|
255
|
+
distPath: 'build', // 自定义输出目录
|
|
256
|
+
isBuild: true, // 启用构建功能
|
|
257
|
+
htmlName: 'app.html' // 自定义 HTML 文件名
|
|
258
|
+
})
|
|
259
|
+
|
|
260
|
+
// Vite 自定义配置
|
|
261
|
+
viteVersionPlugin({
|
|
262
|
+
distPath: 'build',
|
|
263
|
+
isBuild: true, // 启用构建功能
|
|
264
|
+
htmlName: 'app.html'
|
|
265
|
+
})
|
|
266
|
+
|
|
267
|
+
// 明确配置构建参数(推荐方式)
|
|
268
|
+
new BuildVersionTracker({
|
|
269
|
+
distPath: 'dist', // 明确指定输出目录
|
|
270
|
+
isBuild: true, // 明确控制构建行为
|
|
271
|
+
htmlName: 'index.html'
|
|
272
|
+
})
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
## 输出文件
|
|
276
|
+
|
|
277
|
+
插件会在构建完成后生成以下文件:
|
|
278
|
+
|
|
279
|
+
1. **version.txt**: 包含构建信息的文本文件
|
|
280
|
+
2. **dist.zip**: 构建产物的压缩包
|
|
281
|
+
3. **HTML 文件更新**: 在 body 标签后插入版本信息脚本
|
|
282
|
+
|
|
283
|
+
### version.txt 内容示例
|
|
284
|
+
|
|
285
|
+
```
|
|
286
|
+
构建人: username, 构建分支:main, 构建时间:2024-01-01 12:00:00,构建后文件位于:dist
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
### HTML 文件更新示例
|
|
290
|
+
|
|
291
|
+
构建后,HTML 文件会在 `</body>` 标签前插入版本信息脚本:
|
|
292
|
+
|
|
293
|
+
```html
|
|
294
|
+
<script>console.log("%c构建人: username, 构建分支:main, 构建时间:2024-01-01 12:00:00", 'color:blue')</script>
|
|
295
|
+
</body>
|
|
296
|
+
```
|
|
297
|
+
|
|
298
|
+
## API
|
|
299
|
+
|
|
300
|
+
### Webpack 插件选项
|
|
301
|
+
|
|
302
|
+
| 参数 | 类型 | 默认值 | 描述 |
|
|
303
|
+
|------|------|--------|------|
|
|
304
|
+
| distPath | string | 'dist' | 构建输出目录 |
|
|
305
|
+
| isBuild | boolean | false | 是否启用构建功能 |
|
|
306
|
+
| htmlName | string | 'index.html' | HTML 文件名 |
|
|
307
|
+
|
|
308
|
+
### Vite 插件选项
|
|
309
|
+
|
|
310
|
+
| 参数 | 类型 | 默认值 | 描述 |
|
|
311
|
+
|------|------|--------|------|
|
|
312
|
+
| distPath | string | 'dist' | 构建输出目录 |
|
|
313
|
+
| isBuild | boolean | false | 是否启用构建功能 |
|
|
314
|
+
| htmlName | string | 'index.html' | HTML 文件名 |
|
|
315
|
+
|
|
316
|
+
## 开发
|
|
317
|
+
|
|
318
|
+
### 项目结构
|
|
319
|
+
|
|
320
|
+
```
|
|
321
|
+
src/
|
|
322
|
+
├── index.js # Webpack 插件实现
|
|
323
|
+
├── vite-plugin.js # Vite 插件实现
|
|
324
|
+
└── utils.js # 公共工具函数
|
|
325
|
+
```
|
|
326
|
+
|
|
327
|
+
### 构建项目
|
|
328
|
+
|
|
329
|
+
```bash
|
|
330
|
+
pnpm run build
|
|
331
|
+
# 或
|
|
332
|
+
npm run build
|
|
333
|
+
```
|
|
334
|
+
|
|
335
|
+
### 运行测试
|
|
336
|
+
|
|
337
|
+
```bash
|
|
338
|
+
pnpm test
|
|
339
|
+
# 或
|
|
340
|
+
npm test
|
|
341
|
+
```
|
|
342
|
+
|
|
343
|
+
## 许可证
|
|
344
|
+
|
|
345
|
+
MIT
|
|
346
|
+
|
|
347
|
+
## 贡献
|
|
348
|
+
|
|
349
|
+
欢迎提交 Issue 和 Pull Request!
|
|
350
|
+
|
|
351
|
+
- **提交 Issue**: [GitHub Issues](https://github.com/mingyangya/build-version-tracker/issues)
|
|
352
|
+
- **提交 Pull Request**: [GitHub Pull Requests](https://github.com/mingyangya/build-version-tracker/pulls)
|
|
353
|
+
- **项目仓库**: [GitHub Repository](https://github.com/mingyangya/build-version-tracker)
|
|
354
|
+
|
|
355
|
+
## 更新日志
|
|
356
|
+
|
|
357
|
+
### v0.0.1
|
|
358
|
+
- 初始版本发布
|
|
359
|
+
- 支持 Webpack 和 Vite 构建工具
|
|
360
|
+
- 支持 ES 模块和 CommonJS 模块
|
|
361
|
+
- 自动生成版本信息和打包构建产物
|
package/dist/index.es
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { g as m, k as h, w as d, u, p as g } from "./utils-DMG0M2rI.mjs";
|
|
2
|
+
import i from "path";
|
|
3
|
+
const { packageName: n } = m(), P = h(n, "Plugin"), s = n, f = class {
|
|
4
|
+
constructor(a) {
|
|
5
|
+
this.options = a || {};
|
|
6
|
+
}
|
|
7
|
+
apply(a) {
|
|
8
|
+
const t = this.options.distPath || "dist", c = this.options.isBuild || !1, r = this.options.htmlName || "index.html";
|
|
9
|
+
a.hooks.afterEmit.tapAsync(s, async (w, e) => {
|
|
10
|
+
if (!c) {
|
|
11
|
+
console.log(`⏭️ ${s} 构建已禁用,跳过版本信息生成`), e();
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
try {
|
|
15
|
+
console.log(`📝 ${s} 开始生成版本信息...`);
|
|
16
|
+
const o = await d(t);
|
|
17
|
+
u(o, t, r);
|
|
18
|
+
const l = i.resolve(process.cwd(), t), p = i.resolve(process.cwd(), `${t}.zip`);
|
|
19
|
+
await g({
|
|
20
|
+
distDirPath: l,
|
|
21
|
+
outputZipPath: p
|
|
22
|
+
}), console.log(`✅ ${s} 版本信息生成完成`), e();
|
|
23
|
+
} catch (o) {
|
|
24
|
+
console.error(`❌ ${s} 版本信息生成失败:`, o), e(o);
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
Object.defineProperty(f, "name", {
|
|
30
|
+
value: P,
|
|
31
|
+
writable: !1
|
|
32
|
+
});
|
|
33
|
+
export {
|
|
34
|
+
f as default
|
|
35
|
+
};
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const s=require("./utils-BUNhE9qT.js"),n=require("path"),{packageName:c}=s.getPackageInfo(),m=s.kebabToPascalCase(c,"Plugin"),t=c,r=class{constructor(i){this.options=i||{}}apply(i){const o=this.options.distPath||"dist",l=this.options.isBuild||!1,p=this.options.htmlName||"index.html";i.hooks.afterEmit.tapAsync(t,async(d,a)=>{if(!l){console.log(`⏭️ ${t} 构建已禁用,跳过版本信息生成`),a();return}try{console.log(`📝 ${t} 开始生成版本信息...`);const e=await s.writeVersion(o);s.updateMainHtml(e,o,p);const u=n.resolve(process.cwd(),o),h=n.resolve(process.cwd(),`${o}.zip`);await s.packAndRenameDist({distDirPath:u,outputZipPath:h}),console.log(`✅ ${t} 版本信息生成完成`),a()}catch(e){console.error(`❌ ${t} 版本信息生成失败:`,e),a(e)}})}};Object.defineProperty(r,"name",{value:m,writable:!1});module.exports=r;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const u=require("child_process"),m=require("adm-zip"),c=require("fs"),i=require("path");async function g({distDirPath:e,outputZipPath:t,distName:n="dist"}){try{if(!c.existsSync(e)||!c.statSync(e).isDirectory())throw new Error(`dist 文件夹不存在或不是目录:${e}`);const r=new m;r.addLocalFolder(e,n),r.writeZip(t),console.log(`✅ 操作完成!最终压缩包已保存至:${i.resolve(t)}`)}catch(r){throw console.error("❌ 打包/重命名失败:",r),r}}const p=()=>new Promise(e=>{u.exec("git config user.name",(t,n)=>{if(t){e("unknown");return}e(n.trim())})}),f=()=>new Promise(e=>{u.exec("git rev-parse --abbrev-ref HEAD",(t,n)=>{if(t){e("unknown");return}e(n.trim())})});function S(e){const t=e.getFullYear().toString().slice(0,4),n=(e.getMonth()+1).toString().padStart(2,"0"),r=e.getDate().toString().padStart(2,"0"),o=e.getHours().toString().padStart(2,"0"),s=e.getMinutes().toString().padStart(2,"0"),a=e.getSeconds().toString().padStart(2,"0");return`${t}-${n}-${r} ${o}:${s}:${a}`}const w=async e=>{const t=await p(),n=await f(),r=S(new Date),o=`构建人: ${t}, 构建分支:${n}, 构建时间:${r}`,s=`${o},构建后文件位于:${e}`,a=i.resolve(process.cwd(),`${e}/version.txt`);console.log("-------------fileDistName------------",a);try{c.writeFileSync(a,s)}catch(l){throw console.error("❌ 写入版本信息失败:",l),l}return console.log(`%c======${s}======`,"color:blue"),o};function y(e,t,n="index.html"){const r=i.resolve(process.cwd(),`${t}/${n}`);if(c.existsSync(r)){let o=c.readFileSync(r,"utf-8");o=o.replace("</body>",`<script>console.log("%c${e}", 'color:blue')<\/script></body>`),c.writeFileSync(r,o,"utf-8")}}function $(){const e=i.resolve(__dirname,"../package.json"),t=JSON.parse(c.readFileSync(e,"utf-8")),n=t.name;return{packageJson:t,packageName:n}}function d(e,t=""){return e.split("-").map(n=>n.charAt(0).toUpperCase()+n.slice(1)).join("")+t}exports.getPackageInfo=$;exports.kebabToPascalCase=d;exports.packAndRenameDist=g;exports.updateMainHtml=y;exports.writeVersion=w;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { exec as m } from "child_process";
|
|
2
|
+
import p from "adm-zip";
|
|
3
|
+
import c from "fs";
|
|
4
|
+
import i from "path";
|
|
5
|
+
async function d({ distDirPath: t, outputZipPath: e, distName: r = "dist" }) {
|
|
6
|
+
try {
|
|
7
|
+
if (!c.existsSync(t) || !c.statSync(t).isDirectory())
|
|
8
|
+
throw new Error(`dist 文件夹不存在或不是目录:${t}`);
|
|
9
|
+
const n = new p();
|
|
10
|
+
n.addLocalFolder(t, r), n.writeZip(e), console.log(`✅ 操作完成!最终压缩包已保存至:${i.resolve(e)}`);
|
|
11
|
+
} catch (n) {
|
|
12
|
+
throw console.error("❌ 打包/重命名失败:", n), n;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
const g = () => new Promise((t) => {
|
|
16
|
+
m("git config user.name", (e, r) => {
|
|
17
|
+
if (e) {
|
|
18
|
+
t("unknown");
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
t(r.trim());
|
|
22
|
+
});
|
|
23
|
+
}), u = () => new Promise((t) => {
|
|
24
|
+
m("git rev-parse --abbrev-ref HEAD", (e, r) => {
|
|
25
|
+
if (e) {
|
|
26
|
+
t("unknown");
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
t(r.trim());
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
function f(t) {
|
|
33
|
+
const e = t.getFullYear().toString().slice(0, 4), r = (t.getMonth() + 1).toString().padStart(2, "0"), n = t.getDate().toString().padStart(2, "0"), o = t.getHours().toString().padStart(2, "0"), s = t.getMinutes().toString().padStart(2, "0"), a = t.getSeconds().toString().padStart(2, "0");
|
|
34
|
+
return `${e}-${r}-${n} ${o}:${s}:${a}`;
|
|
35
|
+
}
|
|
36
|
+
const h = async (t) => {
|
|
37
|
+
const e = await g(), r = await u(), n = f(/* @__PURE__ */ new Date()), o = `构建人: ${e}, 构建分支:${r}, 构建时间:${n}`, s = `${o},构建后文件位于:${t}`, a = i.resolve(process.cwd(), `${t}/version.txt`);
|
|
38
|
+
console.log("-------------fileDistName------------", a);
|
|
39
|
+
try {
|
|
40
|
+
c.writeFileSync(a, s);
|
|
41
|
+
} catch (l) {
|
|
42
|
+
throw console.error("❌ 写入版本信息失败:", l), l;
|
|
43
|
+
}
|
|
44
|
+
return console.log(`%c======${s}======`, "color:blue"), o;
|
|
45
|
+
};
|
|
46
|
+
function k(t, e, r = "index.html") {
|
|
47
|
+
const n = i.resolve(process.cwd(), `${e}/${r}`);
|
|
48
|
+
if (c.existsSync(n)) {
|
|
49
|
+
let o = c.readFileSync(n, "utf-8");
|
|
50
|
+
o = o.replace("</body>", `<script>console.log("%c${t}", 'color:blue')<\/script></body>`), c.writeFileSync(n, o, "utf-8");
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
function b() {
|
|
54
|
+
const t = i.resolve(__dirname, "../package.json"), e = JSON.parse(c.readFileSync(t, "utf-8")), r = e.name;
|
|
55
|
+
return {
|
|
56
|
+
packageJson: e,
|
|
57
|
+
packageName: r
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
function N(t, e = "") {
|
|
61
|
+
return t.split("-").map((r) => r.charAt(0).toUpperCase() + r.slice(1)).join("") + e;
|
|
62
|
+
}
|
|
63
|
+
export {
|
|
64
|
+
b as g,
|
|
65
|
+
N as k,
|
|
66
|
+
d as p,
|
|
67
|
+
k as u,
|
|
68
|
+
h as w
|
|
69
|
+
};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { g as d, k as u, w as m, u as p, p as g } from "./utils-DMG0M2rI.mjs";
|
|
2
|
+
import l from "path";
|
|
3
|
+
const { packageName: n } = d(), f = u(n, "VitePlugin"), e = n;
|
|
4
|
+
function h(s = {}) {
|
|
5
|
+
const t = s.distPath || "dist", o = s.isBuild || !1, i = s.htmlName || "index.html";
|
|
6
|
+
return {
|
|
7
|
+
name: e,
|
|
8
|
+
// 构建开始前的钩子
|
|
9
|
+
buildStart() {
|
|
10
|
+
console.log(`🚀 ${e} 开始构建...`);
|
|
11
|
+
},
|
|
12
|
+
// 构建结束后的钩子
|
|
13
|
+
buildEnd() {
|
|
14
|
+
o && console.log(`📝 ${e} 准备生成版本信息...`);
|
|
15
|
+
},
|
|
16
|
+
// 关闭钩子(构建完全结束后)
|
|
17
|
+
async closeBundle() {
|
|
18
|
+
if (!o) {
|
|
19
|
+
console.log(`⏭️ ${e} 构建已禁用,跳过版本信息生成`);
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
try {
|
|
23
|
+
console.log(`📝 ${e} 开始生成版本信息...`);
|
|
24
|
+
const a = await m(t);
|
|
25
|
+
p(a, t, i);
|
|
26
|
+
const c = l.resolve(process.cwd(), t), r = l.resolve(process.cwd(), `${t}.zip`);
|
|
27
|
+
await g({
|
|
28
|
+
distDirPath: c,
|
|
29
|
+
outputZipPath: r
|
|
30
|
+
}), console.log(`✅ ${e} 版本信息生成完成`);
|
|
31
|
+
} catch (a) {
|
|
32
|
+
throw console.error(`❌ ${e} 版本信息生成失败:`, a), a;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
Object.defineProperty(h, "name", {
|
|
38
|
+
value: f,
|
|
39
|
+
writable: !1
|
|
40
|
+
});
|
|
41
|
+
export {
|
|
42
|
+
h as default
|
|
43
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const t=require("./utils-BUNhE9qT.js"),c=require("path"),{packageName:i}=t.getPackageInfo(),m=t.kebabToPascalCase(i,"VitePlugin"),e=i;function l(a={}){const s=a.distPath||"dist",n=a.isBuild||!1,r=a.htmlName||"index.html";return{name:e,buildStart(){console.log(`🚀 ${e} 开始构建...`)},buildEnd(){n&&console.log(`📝 ${e} 准备生成版本信息...`)},async closeBundle(){if(!n){console.log(`⏭️ ${e} 构建已禁用,跳过版本信息生成`);return}try{console.log(`📝 ${e} 开始生成版本信息...`);const o=await t.writeVersion(s);t.updateMainHtml(o,s,r);const u=c.resolve(process.cwd(),s),d=c.resolve(process.cwd(),`${s}.zip`);await t.packAndRenameDist({distDirPath:u,outputZipPath:d}),console.log(`✅ ${e} 版本信息生成完成`)}catch(o){throw console.error(`❌ ${e} 版本信息生成失败:`,o),o}}}}Object.defineProperty(l,"name",{value:m,writable:!1});module.exports=l;
|
package/package.json
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "build-version-tracker",
|
|
3
|
+
"description": "A universal build tool plugin for version tracking and build automation (supports Webpack and Vite)",
|
|
4
|
+
"keywords": ["build", "version", "tracker", "automation", "webpack", "vite", "plugin"],
|
|
5
|
+
"private": false,
|
|
6
|
+
"version": "0.0.1",
|
|
7
|
+
"type": "commonjs",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": "./dist/index.js",
|
|
11
|
+
"require": "./dist/index.js"
|
|
12
|
+
},
|
|
13
|
+
"./vite": {
|
|
14
|
+
"import": "./dist/vite-plugin.js",
|
|
15
|
+
"require": "./dist/vite-plugin.js"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"main": "./dist/index.js",
|
|
19
|
+
"files": [
|
|
20
|
+
"dist",
|
|
21
|
+
"README.md"
|
|
22
|
+
],
|
|
23
|
+
"scripts": {
|
|
24
|
+
"build": "vite build",
|
|
25
|
+
"test": "node ./test-simple.js"
|
|
26
|
+
},
|
|
27
|
+
"peerDependencies": {
|
|
28
|
+
"adm-zip": "^0.5.16",
|
|
29
|
+
"webpack": "^5.88.0"
|
|
30
|
+
},
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"vite": "^5.0.0"
|
|
33
|
+
},
|
|
34
|
+
"publishConfig": {
|
|
35
|
+
"access": "public",
|
|
36
|
+
"registry": "https://registry.npmjs.org/"
|
|
37
|
+
},
|
|
38
|
+
"repository": {
|
|
39
|
+
"type": "git",
|
|
40
|
+
"url": "git+https://github.com/mingyangya/build-version-tracker.git"
|
|
41
|
+
},
|
|
42
|
+
"bugs": {
|
|
43
|
+
"url": "https://github.com/mingyangya/build-version-tracker/issues"
|
|
44
|
+
},
|
|
45
|
+
"homepage": "https://github.com/mingyangya/build-version-tracker#readme",
|
|
46
|
+
"engines": {
|
|
47
|
+
"node": ">=14.0.0"
|
|
48
|
+
}
|
|
49
|
+
}
|