vite-plugin-zip-file 3.1.2 → 4.1.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/README.md +1 -1
- package/lib/index.cjs +5 -1
- package/lib/index.d.ts +11 -0
- package/lib/index.mjs +54 -35
- package/package.json +17 -6
package/README.md
CHANGED
package/lib/index.cjs
CHANGED
|
@@ -1 +1,5 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("path"),n=require("fs"),Z=require("node:module");var y=typeof document<"u"?document.currentScript:null;const E=Z.createRequire(typeof document>"u"?require("url").pathToFileURL(__filename).href:y&&y.tagName.toUpperCase()==="SCRIPT"&&y.src||new URL("index.cjs",document.baseURI).href),r=c.sep,{cwd:w}=process,C={enabled:!0,folderPath:c.join(w(),"/dist"),outPath:c.resolve(w()),zipName:"",deleteFolder:!1,withoutMainFolder:!1};let a={};const N=z=>{let F={...C,...z},{enabled:d,folderPath:l,outPath:p,zipName:s,deleteFolder:P,withoutMainFolder:b}=F;if(d=!!d,!l||!p)throw new Error("config.folderPath and config.outPath is required.");l=c.resolve(l),p=c.resolve(p),s=s||l.split(r).pop()+".zip";const j=()=>{const i=E("jszip"),m=new i,g=function(e,o,t="",f=0){const R=n.readdirSync(o);b?f!==0&&(t+=o.split(r).pop()+r):t+=o.split(r).pop()+r,R.forEach(v=>{const u=c.join(o,r,v);n.statSync(u).isDirectory()?g(e,u,t,f+1):e.file(t+v,n.readFileSync(u))})},S=(e=s)=>{const o=c.join(p,r+e);n.existsSync(o)&&n.unlinkSync(o)},h=e=>{n.readdirSync(e).forEach(t=>{const f=e+r+t;n.statSync(f).isDirectory()?h(f):n.unlinkSync(f)}),n.rmdirSync(e)},q=async()=>new Promise((e,o)=>{g(m,l,"",0),m.generateAsync({type:"nodebuffer",compression:"DEFLATE",compressionOptions:{level:9}}).then(t=>{S(s),n.writeFileSync(c.join(p,r,s),t),P&&h(l),e(s)}).catch(t=>{o(t)})});return S(s),q()};return{name:"vite-plugin-zip-file",apply:"build",enforce:"post",configResolved(i){a=i.logger},async closeBundle(){try{if(!d)return;const i=await j();a.info(`
|
|
2
|
+
✨ [vite-plugin-zip-file] - zip floder successfully: ${i}
|
|
3
|
+
`)}catch(i){a.error(typeof i=="string"?i:JSON.stringify(i)),a.error(`
|
|
4
|
+
❌ [vite-plugin-zip-file] - zip floder failed.
|
|
5
|
+
`)}}}};exports.viteZip=N;
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { PluginOption } from 'vite';
|
|
2
|
+
interface ViteZipConfig {
|
|
3
|
+
enabled?: boolean;
|
|
4
|
+
folderPath: string;
|
|
5
|
+
outPath: string;
|
|
6
|
+
zipName?: string;
|
|
7
|
+
deleteFolder?: boolean;
|
|
8
|
+
withoutMainFolder?: boolean;
|
|
9
|
+
}
|
|
10
|
+
export declare const viteZip: (customConfig: ViteZipConfig) => PluginOption;
|
|
11
|
+
export {};
|
package/lib/index.mjs
CHANGED
|
@@ -1,38 +1,40 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import { createRequire as
|
|
4
|
-
const
|
|
1
|
+
import l from "path";
|
|
2
|
+
import t from "fs";
|
|
3
|
+
import { createRequire as b } from "node:module";
|
|
4
|
+
const k = b(import.meta.url), r = l.sep, { cwd: v } = process, q = {
|
|
5
5
|
enabled: !0,
|
|
6
|
-
folderPath:
|
|
7
|
-
outPath:
|
|
6
|
+
folderPath: l.join(v(), "/dist"),
|
|
7
|
+
outPath: l.resolve(v()),
|
|
8
8
|
zipName: "",
|
|
9
9
|
deleteFolder: !1,
|
|
10
10
|
withoutMainFolder: !1
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
11
|
+
};
|
|
12
|
+
let a = {};
|
|
13
|
+
const J = (z) => {
|
|
14
|
+
let w = {
|
|
15
|
+
...q,
|
|
16
|
+
...z
|
|
17
|
+
}, { enabled: d, folderPath: c, outPath: p, zipName: s, deleteFolder: F, withoutMainFolder: P } = w;
|
|
18
|
+
if (d = !!d, !c || !p)
|
|
17
19
|
throw new Error("config.folderPath and config.outPath is required.");
|
|
18
|
-
|
|
20
|
+
c = l.resolve(c), p = l.resolve(p), s = s || c.split(r).pop() + ".zip";
|
|
19
21
|
const j = () => {
|
|
20
|
-
const
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
const
|
|
24
|
-
|
|
22
|
+
const n = k("jszip"), y = new n(), m = function(e, o, i = "", f = 0) {
|
|
23
|
+
const Z = t.readdirSync(o);
|
|
24
|
+
P ? f !== 0 && (i += o.split(r).pop() + r) : i += o.split(r).pop() + r, Z.forEach((h) => {
|
|
25
|
+
const u = l.join(o, r, h);
|
|
26
|
+
t.statSync(u).isDirectory() ? m(e, u, i, f + 1) : e.file(i + h, t.readFileSync(u));
|
|
25
27
|
});
|
|
26
|
-
},
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
},
|
|
30
|
-
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
}),
|
|
34
|
-
}, E =
|
|
35
|
-
|
|
28
|
+
}, g = (e = s) => {
|
|
29
|
+
const o = l.join(p, r + e);
|
|
30
|
+
t.existsSync(o) && t.unlinkSync(o);
|
|
31
|
+
}, S = (e) => {
|
|
32
|
+
t.readdirSync(e).forEach((i) => {
|
|
33
|
+
const f = e + r + i;
|
|
34
|
+
t.statSync(f).isDirectory() ? S(f) : t.unlinkSync(f);
|
|
35
|
+
}), t.rmdirSync(e);
|
|
36
|
+
}, E = async () => new Promise((e, o) => {
|
|
37
|
+
m(y, c, "", 0), y.generateAsync({
|
|
36
38
|
type: "nodebuffer",
|
|
37
39
|
// 压缩类型
|
|
38
40
|
compression: "DEFLATE",
|
|
@@ -41,20 +43,37 @@ const b = Z(import.meta.url), t = i.sep, { cwd: h } = process, k = {
|
|
|
41
43
|
// 压缩级别
|
|
42
44
|
level: 9
|
|
43
45
|
}
|
|
44
|
-
}).then((
|
|
45
|
-
|
|
46
|
+
}).then((i) => {
|
|
47
|
+
g(s), t.writeFileSync(l.join(p, r, s), i), F && S(c), e(s);
|
|
48
|
+
}).catch((i) => {
|
|
49
|
+
o(i);
|
|
46
50
|
});
|
|
47
|
-
};
|
|
48
|
-
|
|
51
|
+
});
|
|
52
|
+
return g(s), E();
|
|
49
53
|
};
|
|
50
54
|
return {
|
|
51
55
|
name: "vite-plugin-zip-file",
|
|
52
56
|
apply: "build",
|
|
53
|
-
|
|
54
|
-
|
|
57
|
+
enforce: "post",
|
|
58
|
+
configResolved(n) {
|
|
59
|
+
a = n.logger;
|
|
60
|
+
},
|
|
61
|
+
async closeBundle() {
|
|
62
|
+
try {
|
|
63
|
+
if (!d)
|
|
64
|
+
return;
|
|
65
|
+
const n = await j();
|
|
66
|
+
a.info(`
|
|
67
|
+
✨ [vite-plugin-zip-file] - zip floder successfully: ${n}
|
|
68
|
+
`);
|
|
69
|
+
} catch (n) {
|
|
70
|
+
a.error(typeof n == "string" ? n : JSON.stringify(n)), a.error(`
|
|
71
|
+
❌ [vite-plugin-zip-file] - zip floder failed.
|
|
72
|
+
`);
|
|
73
|
+
}
|
|
55
74
|
}
|
|
56
75
|
};
|
|
57
76
|
};
|
|
58
77
|
export {
|
|
59
|
-
|
|
78
|
+
J as viteZip
|
|
60
79
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vite-plugin-zip-file",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "4.1.0",
|
|
4
|
+
"description": "Zip files at build time.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.cjs",
|
|
7
7
|
"files": [
|
|
@@ -11,11 +11,20 @@
|
|
|
11
11
|
"README.md"
|
|
12
12
|
],
|
|
13
13
|
"module": "lib/index.mjs",
|
|
14
|
+
"types": "lib/index.d.ts",
|
|
15
|
+
"exports": {
|
|
16
|
+
".": {
|
|
17
|
+
"types": "./lib/index.d.ts",
|
|
18
|
+
"import": "./lib/index.mjs",
|
|
19
|
+
"require": "./lib/index.cjs"
|
|
20
|
+
},
|
|
21
|
+
"./package.json": "./package.json"
|
|
22
|
+
},
|
|
14
23
|
"scripts": {
|
|
15
24
|
"dev": "vite",
|
|
16
25
|
"build": "vite build",
|
|
17
26
|
"build-d": "node --inspect-brk=9229 ./node_modules/vite/dist/node/cli.js build",
|
|
18
|
-
"build-plugin": "vite --config plugin.config.
|
|
27
|
+
"build-plugin": "vite --config plugin.config.ts build && tsc"
|
|
19
28
|
},
|
|
20
29
|
"repository": {
|
|
21
30
|
"type": "git",
|
|
@@ -33,11 +42,13 @@
|
|
|
33
42
|
},
|
|
34
43
|
"homepage": "https://github.com/Ssis53/vite-plugin-zip#readme",
|
|
35
44
|
"dependencies": {
|
|
36
|
-
"jszip": "
|
|
45
|
+
"jszip": "3.10.1"
|
|
37
46
|
},
|
|
38
47
|
"devDependencies": {
|
|
39
|
-
"
|
|
40
|
-
"@
|
|
48
|
+
"@rollup/plugin-node-resolve": "^15.2.0",
|
|
49
|
+
"@types/node": "^22.13.15",
|
|
50
|
+
"typescript": "^5.8.2",
|
|
51
|
+
"vite": "^6.2.0"
|
|
41
52
|
},
|
|
42
53
|
"peerDependencies": {
|
|
43
54
|
"vite": ">=2.0.0"
|