vite-plugin-multiversion 1.0.1 → 1.0.2
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 +2 -1
- package/dist/index.js +3 -5
- package/dist/index.mjs +3 -5
- package/package.json +1 -1
- package/src/cleanOldVersions.ts +3 -8
package/README.md
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
通过打包进行多版本控制的 Vite 插件
|
|
4
4
|
|
|
5
|
+
|
|
5
6
|
## 安装
|
|
6
7
|
|
|
7
8
|
```bash
|
|
@@ -77,7 +78,7 @@ VITE_APP_ENV=prod
|
|
|
77
78
|
|
|
78
79
|
### cleanOldVersions
|
|
79
80
|
|
|
80
|
-
|
|
81
|
+
删除超过指定天数的旧版本目录。超过指定天数的删除版本中,会保留至少一个版本,防止出现指定删除x天,x+1天再打包把前面的版本全删掉了(保证打包完除了当前版本,至少还有最后的一个线上版本(超过x天))
|
|
81
82
|
|
|
82
83
|
| 参数 | 类型 | 默认值 | 说明 |
|
|
83
84
|
|------|------|--------|------|
|
package/dist/index.js
CHANGED
|
@@ -100,13 +100,11 @@ function cleanOldVersions(options) {
|
|
|
100
100
|
});
|
|
101
101
|
}
|
|
102
102
|
}
|
|
103
|
+
const maxOldTimestamp = Math.max(...oldVersions.map((i) => i.timestamp));
|
|
104
|
+
console.log(`[clean-old-versions] \u8D85\u8FC7${days}\u5929\u6700\u5927\u4FDD\u7559\u5386\u53F2\u4E3A:${maxOldTimestamp}`);
|
|
103
105
|
let deletedCount = 0;
|
|
104
|
-
oldVersions.forEach((item) => {
|
|
106
|
+
oldVersions.filter((i) => i.timestamp !== maxOldTimestamp).forEach((item) => {
|
|
105
107
|
const { dirPath, entryName } = item;
|
|
106
|
-
if (oldVersions.length - deletedCount <= 1) {
|
|
107
|
-
console.log(`[clean-old-versions] \u89E6\u53D1\u6700\u5C11\u4FDD\u7559\u8D85\u8FC71\u5929\u7684\u4E00\u4E2A\u65E7\u5386\u53F2: ${entryName}`);
|
|
108
|
-
return;
|
|
109
|
-
}
|
|
110
108
|
import_node_fs2.default.rmSync(dirPath, { recursive: true, force: true });
|
|
111
109
|
console.log(`[clean-old-versions] \u5DF2\u5220\u9664: ${entryName}`);
|
|
112
110
|
deletedCount++;
|
package/dist/index.mjs
CHANGED
|
@@ -63,13 +63,11 @@ function cleanOldVersions(options) {
|
|
|
63
63
|
});
|
|
64
64
|
}
|
|
65
65
|
}
|
|
66
|
+
const maxOldTimestamp = Math.max(...oldVersions.map((i) => i.timestamp));
|
|
67
|
+
console.log(`[clean-old-versions] \u8D85\u8FC7${days}\u5929\u6700\u5927\u4FDD\u7559\u5386\u53F2\u4E3A:${maxOldTimestamp}`);
|
|
66
68
|
let deletedCount = 0;
|
|
67
|
-
oldVersions.forEach((item) => {
|
|
69
|
+
oldVersions.filter((i) => i.timestamp !== maxOldTimestamp).forEach((item) => {
|
|
68
70
|
const { dirPath, entryName } = item;
|
|
69
|
-
if (oldVersions.length - deletedCount <= 1) {
|
|
70
|
-
console.log(`[clean-old-versions] \u89E6\u53D1\u6700\u5C11\u4FDD\u7559\u8D85\u8FC71\u5929\u7684\u4E00\u4E2A\u65E7\u5386\u53F2: ${entryName}`);
|
|
71
|
-
return;
|
|
72
|
-
}
|
|
73
71
|
fs2.rmSync(dirPath, { recursive: true, force: true });
|
|
74
72
|
console.log(`[clean-old-versions] \u5DF2\u5220\u9664: ${entryName}`);
|
|
75
73
|
deletedCount++;
|
package/package.json
CHANGED
package/src/cleanOldVersions.ts
CHANGED
|
@@ -50,17 +50,12 @@ export function cleanOldVersions(options: CleanOldVersionsOptions): Plugin {
|
|
|
50
50
|
})
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
|
-
|
|
53
|
+
const maxOldTimestamp = Math.max(...oldVersions.map(i => i.timestamp))
|
|
54
|
+
console.log(`[clean-old-versions] 超过${days}天最大保留历史为:${maxOldTimestamp}`)
|
|
54
55
|
let deletedCount = 0
|
|
55
56
|
|
|
56
|
-
oldVersions.forEach(item => {
|
|
57
|
+
oldVersions.filter(i => i.timestamp !== maxOldTimestamp).forEach(item => {
|
|
57
58
|
const { dirPath, entryName } = item
|
|
58
|
-
|
|
59
|
-
if (oldVersions.length - deletedCount <= 1) {
|
|
60
|
-
console.log(`[clean-old-versions] 触发最少保留超过1天的一个旧历史: ${entryName}`)
|
|
61
|
-
return
|
|
62
|
-
}
|
|
63
|
-
|
|
64
59
|
fs.rmSync(dirPath, { recursive: true, force: true })
|
|
65
60
|
console.log(`[clean-old-versions] 已删除: ${entryName}`)
|
|
66
61
|
deletedCount++
|