vite-plugin-zip-file 2.1.1 → 2.2.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 CHANGED
@@ -20,12 +20,28 @@ npm install vite-plugin-zip-file --save-dev
20
20
  # Options
21
21
 
22
22
 
23
- | Param | Types | Rquired | Default | Desc |
24
- | :--------- | ------------ | ------- | ------- | ------------------------------------------------------------ |
25
- | folderPath | String\|Path | true | /dist | Path to the compressed folder |
26
- | outPath | String\|Path | true | / | Compressed package output path |
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 |
23
+ | Params | Types | Rquired | Default | Desc |
24
+ | :----------- | ------------ | ------- | ------- | ------------------------------------------------------------ |
25
+ | folderPath | String\|Path | true | /dist | Path to the compressed folder |
26
+ | outPath | String\|Path | true | / | Compressed package output path |
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 |
29
+ | deleteFolder | Boolean | false | false | Whether to delete source files after compression is completed |
30
+
31
+
32
+ # Options(中文)
33
+
34
+
35
+ | 参数 | 类型 | 必填 | 默认值 | 说明 |
36
+ | :----------- | ------------ | ---- | ------ | ------------------------------------------------------- |
37
+ | folderPath | String\|Path | 是 | /dist | 需要被压缩的源文件夹 |
38
+ | outPath | String\|Path | 是 | / | 压缩包输出路径 |
39
+ | zipName | String | 否 | dist | 压缩包名称 |
40
+ | enabled | Boolean | 否 | true | 用于控制插件是否启用, 通常用于根据环境判断是否压缩文件 |
41
+ | deleteFolder | Boolean | 否 | false | 压缩完成后是否删除源文件 |
42
+
43
+
44
+
29
45
 
30
46
 
31
47
 
package/lib/index.cjs CHANGED
@@ -1 +1 @@
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;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("path"),n=require("fs"),P=require("node:module"),F=P.createRequire(typeof document>"u"?new(require("url")).URL("file:"+__filename).href:document.currentScript&&document.currentScript.src||new URL("index.cjs",document.baseURI).href),r=t.sep,{cwd:h}=process,Z={enabled:!0,folderPath:t.join(h(),"/dist"),outPath:t.resolve(h()),zipName:"",deleteFolder:!1},z=v=>{let g={...Z,...v},{enabled:f,folderPath:c,outPath:s,zipName:o,deleteFolder:b}=g;if(f=Boolean(f),!c||!s)throw new Error("config.folderPath and config.outPath is required.");c=t.resolve(c),s=t.resolve(s),o=o||c.split(r).pop()+".zip";const j=()=>{const q=F("jszip"),p=new q,a=function(e,i,l=""){const d=n.readdirSync(i);l+=i.split(r).pop()+r,d.forEach(m=>{const u=t.join(i,r,m);n.statSync(u).isDirectory()?a(e,u,l):e.file(l+m,n.readFileSync(u))})},y=(e=o)=>{const i=t.join(s,r+e);n.existsSync(i)&&n.unlinkSync(i)},S=e=>{n.readdirSync(e).forEach(l=>{const d=e+r+l;n.statSync(d).isDirectory()?S(d):n.unlinkSync(d)}),n.rmdirSync(e)},w=function(){a(p,c),p.generateAsync({type:"nodebuffer",compression:"DEFLATE",compressionOptions:{level:9}}).then(e=>{y(o),n.writeFileSync(t.join(s,r,o),e),b&&S(c)})};y(o),w()};return{name:"vite-plugin-zip-file",apply:"build",closeBundle(){f&&j()}}};exports.viteZip=z;
package/lib/index.mjs CHANGED
@@ -1,31 +1,37 @@
1
- import e from "path";
2
- import i from "fs";
1
+ import t from "path";
2
+ import o from "fs";
3
3
  import { createRequire as z } from "node:module";
4
- const P = z(import.meta.url), s = e.sep, { cwd: h } = process, Z = {
4
+ const E = z(import.meta.url), r = t.sep, { cwd: h } = process, Z = {
5
5
  enabled: !0,
6
- folderPath: e.join(h(), "/dist"),
7
- outPath: e.resolve(h()),
8
- zipName: ""
9
- }, k = (y) => {
10
- let S = {
6
+ folderPath: t.join(h(), "/dist"),
7
+ outPath: t.resolve(h()),
8
+ zipName: "",
9
+ deleteFolder: !1
10
+ }, A = (v) => {
11
+ let g = {
11
12
  ...Z,
12
- ...y
13
- }, { enabled: p, folderPath: r, outPath: c, zipName: o } = S;
14
- if (p = Boolean(p), !r || !c)
13
+ ...v
14
+ }, { enabled: f, folderPath: s, outPath: c, zipName: n, deleteFolder: F } = g;
15
+ if (f = Boolean(f), !s || !c)
15
16
  throw new Error("config.folderPath and config.outPath is required.");
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));
17
+ s = t.resolve(s), c = t.resolve(c), n = n || s.split(r).pop() + ".zip";
18
+ const P = () => {
19
+ const j = E("jszip"), d = new j(), u = function(e, i, l = "") {
20
+ const p = o.readdirSync(i);
21
+ l += i.split(r).pop() + r, p.forEach((S) => {
22
+ const a = t.join(i, r, S);
23
+ o.statSync(a).isDirectory() ? u(e, a, l) : e.file(l + S, o.readFileSync(a));
23
24
  });
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({
25
+ }, m = (e = n) => {
26
+ const i = t.join(c, r + e);
27
+ o.existsSync(i) && o.unlinkSync(i);
28
+ }, y = (e) => {
29
+ o.readdirSync(e).forEach((l) => {
30
+ const p = e + r + l;
31
+ o.statSync(p).isDirectory() ? y(p) : o.unlinkSync(p);
32
+ }), o.rmdirSync(e);
33
+ }, w = function() {
34
+ u(d, s), d.generateAsync({
29
35
  type: "nodebuffer",
30
36
  // 压缩类型
31
37
  compression: "DEFLATE",
@@ -34,20 +40,20 @@ const P = z(import.meta.url), s = e.sep, { cwd: h } = process, Z = {
34
40
  // 压缩级别
35
41
  level: 9
36
42
  }
37
- }).then((t) => {
38
- u(o), i.writeFileSync(e.join(c, s, o), t);
43
+ }).then((e) => {
44
+ m(n), o.writeFileSync(t.join(c, r, n), e), F && y(s);
39
45
  });
40
46
  };
41
- u(o), j();
47
+ m(n), w();
42
48
  };
43
49
  return {
44
50
  name: "vite-plugin-zip-file",
45
51
  apply: "build",
46
52
  closeBundle() {
47
- p && v();
53
+ f && P();
48
54
  }
49
55
  };
50
56
  };
51
57
  export {
52
- k as viteZip
58
+ A as viteZip
53
59
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-plugin-zip-file",
3
- "version": "2.1.1",
3
+ "version": "2.2.0",
4
4
  "description": "zip files at build time.",
5
5
  "type": "module",
6
6
  "main": "lib/index.cjs",