vite-plugin-multiversion 1.0.0 → 1.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 +3 -2
- package/dist/index.d.mts +0 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.js +4 -5
- package/dist/index.mjs +4 -5
- package/package.json +1 -1
- package/src/cleanOldVersions.ts +4 -6
package/README.md
CHANGED
|
@@ -83,8 +83,9 @@ VITE_APP_ENV=prod
|
|
|
83
83
|
|------|------|--------|------|
|
|
84
84
|
| outDir | string | 'dist-prod' | 输出目录 |
|
|
85
85
|
| days | number | 2 | 保留天数 |
|
|
86
|
-
| now | number | Date.now() |
|
|
87
|
-
|
|
86
|
+
| now | number | Date.now() | 版本目录名(如时间戳) |
|
|
87
|
+
|
|
88
|
+
> 删除超过指定天数的旧版本,最少保留1个旧版本
|
|
88
89
|
|
|
89
90
|
## 目录结构
|
|
90
91
|
|
package/dist/index.d.mts
CHANGED
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -68,7 +68,7 @@ function versionLink(options) {
|
|
|
68
68
|
var import_node_fs2 = __toESM(require("fs"));
|
|
69
69
|
var import_node_path2 = __toESM(require("path"));
|
|
70
70
|
function cleanOldVersions(options) {
|
|
71
|
-
const { outDir = "dist-prod", days = 2, now
|
|
71
|
+
const { outDir = "dist-prod", days = 2, now } = options;
|
|
72
72
|
return {
|
|
73
73
|
name: "clean-old-versions",
|
|
74
74
|
apply: "build",
|
|
@@ -101,11 +101,10 @@ function cleanOldVersions(options) {
|
|
|
101
101
|
}
|
|
102
102
|
}
|
|
103
103
|
let deletedCount = 0;
|
|
104
|
-
const maxDeletable = oldVersions.length - minVersions;
|
|
105
104
|
oldVersions.forEach((item) => {
|
|
106
|
-
const { dirPath,
|
|
107
|
-
if (deletedCount
|
|
108
|
-
console.log(`[clean-old-versions] \u89E6\u53D1\u6700\u5C11\u4FDD\u7559
|
|
105
|
+
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}`);
|
|
109
108
|
return;
|
|
110
109
|
}
|
|
111
110
|
import_node_fs2.default.rmSync(dirPath, { recursive: true, force: true });
|
package/dist/index.mjs
CHANGED
|
@@ -31,7 +31,7 @@ function versionLink(options) {
|
|
|
31
31
|
import fs2 from "fs";
|
|
32
32
|
import path2 from "path";
|
|
33
33
|
function cleanOldVersions(options) {
|
|
34
|
-
const { outDir = "dist-prod", days = 2, now
|
|
34
|
+
const { outDir = "dist-prod", days = 2, now } = options;
|
|
35
35
|
return {
|
|
36
36
|
name: "clean-old-versions",
|
|
37
37
|
apply: "build",
|
|
@@ -64,11 +64,10 @@ function cleanOldVersions(options) {
|
|
|
64
64
|
}
|
|
65
65
|
}
|
|
66
66
|
let deletedCount = 0;
|
|
67
|
-
const maxDeletable = oldVersions.length - minVersions;
|
|
68
67
|
oldVersions.forEach((item) => {
|
|
69
|
-
const { dirPath,
|
|
70
|
-
if (deletedCount
|
|
71
|
-
console.log(`[clean-old-versions] \u89E6\u53D1\u6700\u5C11\u4FDD\u7559
|
|
68
|
+
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}`);
|
|
72
71
|
return;
|
|
73
72
|
}
|
|
74
73
|
fs2.rmSync(dirPath, { recursive: true, force: true });
|
package/package.json
CHANGED
package/src/cleanOldVersions.ts
CHANGED
|
@@ -6,11 +6,10 @@ export interface CleanOldVersionsOptions {
|
|
|
6
6
|
outDir?: string
|
|
7
7
|
days?: number
|
|
8
8
|
now?: number
|
|
9
|
-
minVersions?: number
|
|
10
9
|
}
|
|
11
10
|
|
|
12
11
|
export function cleanOldVersions(options: CleanOldVersionsOptions): Plugin {
|
|
13
|
-
const { outDir = 'dist-prod', days = 2, now
|
|
12
|
+
const { outDir = 'dist-prod', days = 2, now } = options
|
|
14
13
|
|
|
15
14
|
return {
|
|
16
15
|
name: 'clean-old-versions',
|
|
@@ -53,13 +52,12 @@ export function cleanOldVersions(options: CleanOldVersionsOptions): Plugin {
|
|
|
53
52
|
}
|
|
54
53
|
|
|
55
54
|
let deletedCount = 0
|
|
56
|
-
const maxDeletable = oldVersions.length - minVersions
|
|
57
55
|
|
|
58
56
|
oldVersions.forEach(item => {
|
|
59
|
-
const { dirPath,
|
|
57
|
+
const { dirPath, entryName } = item
|
|
60
58
|
|
|
61
|
-
if (deletedCount
|
|
62
|
-
console.log(`[clean-old-versions]
|
|
59
|
+
if (oldVersions.length - deletedCount <= 1) {
|
|
60
|
+
console.log(`[clean-old-versions] 触发最少保留超过1天的一个旧历史: ${entryName}`)
|
|
63
61
|
return
|
|
64
62
|
}
|
|
65
63
|
|