vite-plugin-zip-file 2.0.0 → 2.1.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 CHANGED
@@ -17,15 +17,17 @@ or
17
17
  npm install vite-plugin-zip-file --save-dev
18
18
  ```
19
19
 
20
- # Optons
20
+ # Options
21
21
 
22
22
 
23
23
  | Param | Types | Rquired | Default | Desc |
24
24
  | :--------- | ------------ | ------- | ------- | ------------------------------------------------------------ |
25
- | folderPath | String\|Path | true | - | Path to the compressed folder |
26
- | outPath | String\|Path | true | - | Compressed package output path |
25
+ | folderPath | String\|Path | true | /dist | Path to the compressed folder |
26
+ | outPath | String\|Path | true | / | Compressed package output path |
27
27
  | zipName | String | false | dist | Package name |
28
- | enabled | Boolean | false | true | This parameter is used to control whether the plugin is enabled. It is usually used to determine whether to compress files according to the environment |
28
+ | enabled | Boolean | false | true | This parameter is used to control whether the plugin is enabled. It is usually used to determine whether to compress files according to the environment |
29
+
30
+
29
31
 
30
32
 
31
33
 
package/lib/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const j=require("path"),q=require("fs"),w=require("node:module"),y=e=>e&&typeof e=="object"&&"default"in e?e:{default:e},r=y(j),i=y(q),P=w.createRequire(typeof document>"u"?new(require("url")).URL("file:"+__filename).href:document.currentScript&&document.currentScript.src||new URL("index.cjs",document.baseURI).href),l=r.default.sep,Z={enabled:!0,folderPath:"",outPath:"",zipName:""},z=e=>{let S={...Z,...e},{enabled:s,folderPath:u,outPath:c,zipName:t}=S;if(s=Boolean(s),!u||!c)throw new Error("config.folderPath and config.outPath is required.");u=r.default.resolve(u),c=r.default.resolve(c),t=t||u.split(l).pop()+".zip";const _=()=>{const g=P("jszip"),d=new g,p=function(n,o,a=""){const b=i.default.readdirSync(o);a+=o.split(l).pop()+l,b.forEach(m=>{const f=r.default.join(o,l,m);i.default.statSync(f).isDirectory()?p(n,f,a):n.file(a+m,i.default.readFileSync(f))})},h=(n=t)=>{const o=r.default.join(c,l+n);i.default.existsSync(o)&&i.default.unlinkSync(o)},v=function(){p(d,u),d.generateAsync({type:"nodebuffer",compression:"DEFLATE",compressionOptions:{level:9}}).then(n=>{h(t),i.default.writeFileSync(r.default.join(c,l,t),n)})};h(t),v()};return{name:"vite-plugin-zip-file",apply:"build",closeBundle(){!s||_()}}};exports.viteZip=z;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("path"),i=require("fs"),q=require("node:module"),w=q.createRequire(typeof document>"u"?new(require("url")).URL("file:"+__filename).href:document.currentScript&&document.currentScript.src||new URL("index.cjs",document.baseURI).href),r=e.sep,{cwd:y}=process,P={enabled:!0,folderPath:e.join(y(),"/dist"),outPath:e.resolve(y()),zipName:""},Z=h=>{let S={...P,...h},{enabled:l,folderPath:c,outPath:s,zipName:n}=S;if(l=Boolean(l),!c||!s)throw new Error("config.folderPath and config.outPath is required.");c=e.resolve(c),s=e.resolve(s),n=n||c.split(r).pop()+".zip";const v=()=>{const g=w("jszip"),d=new g,f=function(t,o,p=""){const j=i.readdirSync(o);p+=o.split(r).pop()+r,j.forEach(m=>{const u=e.join(o,r,m);i.statSync(u).isDirectory()?f(t,u,p):t.file(p+m,i.readFileSync(u))})},a=(t=n)=>{const o=e.join(s,r+t);i.existsSync(o)&&i.unlinkSync(o)},b=function(){f(d,c),d.generateAsync({type:"nodebuffer",compression:"DEFLATE",compressionOptions:{level:9}}).then(t=>{a(n),i.writeFileSync(e.join(s,r,n),t)})};a(n),b()};return{name:"vite-plugin-zip-file",apply:"build",closeBundle(){l&&v()}}};exports.viteZip=Z;
package/lib/index.mjs CHANGED
@@ -1,50 +1,53 @@
1
- import r from "path";
2
- import n from "fs";
3
- import { createRequire as P } from "node:module";
4
- const Z = P(import.meta.url), i = r.sep, b = {
1
+ import e from "path";
2
+ import i from "fs";
3
+ import { createRequire as z } from "node:module";
4
+ const P = z(import.meta.url), s = e.sep, { cwd: h } = process, Z = {
5
5
  enabled: !0,
6
- folderPath: "",
7
- outPath: "",
6
+ folderPath: e.join(h(), "/dist"),
7
+ outPath: e.resolve(h()),
8
8
  zipName: ""
9
- }, F = (h) => {
10
- let y = {
11
- ...b,
12
- ...h
13
- }, { enabled: p, folderPath: s, outPath: c, zipName: e } = y;
14
- if (p = Boolean(p), !s || !c)
9
+ }, k = (y) => {
10
+ let S = {
11
+ ...Z,
12
+ ...y
13
+ }, { enabled: p, folderPath: r, outPath: c, zipName: o } = S;
14
+ if (p = Boolean(p), !r || !c)
15
15
  throw new Error("config.folderPath and config.outPath is required.");
16
- s = r.resolve(s), c = r.resolve(c), e = e || s.split(i).pop() + ".zip";
17
- const S = () => {
18
- const g = Z("jszip"), f = new g(), u = function(o, t, l = "") {
19
- const z = n.readdirSync(t);
20
- l += t.split(i).pop() + i, z.forEach((m) => {
21
- const a = r.join(t, i, m);
22
- n.statSync(a).isDirectory() ? u(o, a, l) : o.file(l + m, n.readFileSync(a));
16
+ r = e.resolve(r), c = e.resolve(c), o = o || r.split(s).pop() + ".zip";
17
+ const v = () => {
18
+ const g = P("jszip"), f = new g(), d = function(t, n, l = "") {
19
+ const w = i.readdirSync(n);
20
+ l += n.split(s).pop() + s, w.forEach((m) => {
21
+ const a = e.join(n, s, m);
22
+ i.statSync(a).isDirectory() ? d(t, a, l) : t.file(l + m, i.readFileSync(a));
23
23
  });
24
- }, d = (o = e) => {
25
- const t = r.join(c, i + o);
26
- n.existsSync(t) && n.unlinkSync(t);
27
- }, v = function() {
28
- u(f, s), f.generateAsync({
24
+ }, u = (t = o) => {
25
+ const n = e.join(c, s + t);
26
+ i.existsSync(n) && i.unlinkSync(n);
27
+ }, j = function() {
28
+ d(f, r), f.generateAsync({
29
29
  type: "nodebuffer",
30
+ // 压缩类型
30
31
  compression: "DEFLATE",
32
+ // 压缩算法
31
33
  compressionOptions: {
34
+ // 压缩级别
32
35
  level: 9
33
36
  }
34
- }).then((o) => {
35
- d(e), n.writeFileSync(r.join(c, i, e), o);
37
+ }).then((t) => {
38
+ u(o), i.writeFileSync(e.join(c, s, o), t);
36
39
  });
37
40
  };
38
- d(e), v();
41
+ u(o), j();
39
42
  };
40
43
  return {
41
44
  name: "vite-plugin-zip-file",
42
45
  apply: "build",
43
46
  closeBundle() {
44
- !p || S();
47
+ p && v();
45
48
  }
46
49
  };
47
50
  };
48
51
  export {
49
- F as viteZip
52
+ k as viteZip
50
53
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-plugin-zip-file",
3
- "version": "2.0.0",
3
+ "version": "2.1.1",
4
4
  "description": "zip files at build time.",
5
5
  "type": "module",
6
6
  "main": "lib/index.cjs",