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