vite-plugin-zip-file 1.0.2 → 1.0.3

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/lib/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const v=require("path"),g=require("fs"),j=require("node:module"),m=e=>e&&typeof e=="object"&&"default"in e?e:{default:e},r=m(v),i=m(g),q=j.createRequire(typeof document>"u"?new(require("url")).URL("file:"+__filename).href:document.currentScript&&document.currentScript.src||new URL("index.cjs",document.baseURI).href),b=(e={folderPath:null,outPath:null,zipName:null})=>{let{folderPath:l,outPath:u,zipName:t}=e;if(!l||!u)throw new Error("config.folderPath and config.outPath is required.");l=r.default.resolve(l),u=r.default.resolve(u),t=t||l.split("/").pop()+".zip";const y=()=>{const h=q("jszip"),f=new h,a=function(n,o,c=""){const _=i.default.readdirSync(o);c+=o.split("/").pop()+"/",_.forEach(p=>{const s=r.default.join(o,"/",p);i.default.statSync(s).isDirectory()?a(n,s,c):n.file(c+p,i.default.readFileSync(s))})},d=(n=t)=>{const o=r.default.join(u,"/"+n);i.default.existsSync(o)&&i.default.unlinkSync(o)},S=function(){a(f,l),f.generateAsync({type:"nodebuffer",compression:"DEFLATE",compressionOptions:{level:9}}).then(n=>{d(t),i.default.writeFileSync(r.default.join(u,"/",t),n)})};d(t),S()};return{name:"vite-plugin-zip-file",apply:"build",closeBundle(){y()}}};exports.viteZip=b;
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const g=require("path"),j=require("fs"),q=require("node:module"),m=e=>e&&typeof e=="object"&&"default"in e?e:{default:e},u=m(g),i=m(j),b=q.createRequire(typeof document>"u"?new(require("url")).URL("file:"+__filename).href:document.currentScript&&document.currentScript.src||new URL("index.cjs",document.baseURI).href),l=u.default.sep,w=(e={folderPath:null,outPath:null,zipName:null})=>{let{folderPath:r,outPath:s,zipName:t}=e;if(!r||!s)throw new Error("config.folderPath and config.outPath is required.");r=u.default.resolve(r),s=u.default.resolve(s),t=t||r.split(l).pop()+".zip";const y=()=>{const S=b("jszip"),f=new S,d=function(n,o,c=""){const v=i.default.readdirSync(o);c+=o.split(l).pop()+l,v.forEach(h=>{const a=u.default.join(o,l,h);i.default.statSync(a).isDirectory()?d(n,a,c):n.file(c+h,i.default.readFileSync(a))})},p=(n=t)=>{const o=u.default.join(s,l+n);i.default.existsSync(o)&&i.default.unlinkSync(o)},_=function(){d(f,r),f.generateAsync({type:"nodebuffer",compression:"DEFLATE",compressionOptions:{level:9}}).then(n=>{p(t),i.default.writeFileSync(u.default.join(s,l,t),n)})};p(t),_()};return{name:"vite-plugin-zip-file",apply:"build",closeBundle(){y()}}};exports.viteZip=w;
package/lib/index.mjs CHANGED
@@ -1,42 +1,42 @@
1
- import s from "path";
1
+ import r from "path";
2
2
  import n from "fs";
3
- import { createRequire as v } from "node:module";
4
- const z = v(import.meta.url), w = (m = { folderPath: null, outPath: null, zipName: null }) => {
5
- let { folderPath: i, outPath: r, zipName: e } = m;
6
- if (!i || !r)
3
+ import { createRequire as z } from "node:module";
4
+ const P = z(import.meta.url), i = r.sep, E = (d = { folderPath: null, outPath: null, zipName: null }) => {
5
+ let { folderPath: s, outPath: p, zipName: e } = d;
6
+ if (!s || !p)
7
7
  throw new Error("config.folderPath and config.outPath is required.");
8
- i = s.resolve(i), r = s.resolve(r), e = e || i.split("/").pop() + ".zip";
9
- const d = () => {
10
- const y = z("jszip"), p = new y(), f = function(o, t, l = "") {
11
- const S = n.readdirSync(t);
12
- l += t.split("/").pop() + "/", S.forEach((u) => {
13
- const c = s.join(t, "/", u);
14
- n.statSync(c).isDirectory() ? f(o, c, l) : o.file(l + u, n.readFileSync(c));
8
+ s = r.resolve(s), p = r.resolve(p), e = e || s.split(i).pop() + ".zip";
9
+ const h = () => {
10
+ const y = P("jszip"), a = new y(), f = function(o, t, c = "") {
11
+ const v = n.readdirSync(t);
12
+ c += t.split(i).pop() + i, v.forEach((m) => {
13
+ const l = r.join(t, i, m);
14
+ n.statSync(l).isDirectory() ? f(o, l, c) : o.file(c + m, n.readFileSync(l));
15
15
  });
16
- }, a = (o = e) => {
17
- const t = s.join(r, "/" + o);
16
+ }, u = (o = e) => {
17
+ const t = r.join(p, i + o);
18
18
  n.existsSync(t) && n.unlinkSync(t);
19
- }, h = function() {
20
- f(p, i), p.generateAsync({
19
+ }, S = function() {
20
+ f(a, s), a.generateAsync({
21
21
  type: "nodebuffer",
22
22
  compression: "DEFLATE",
23
23
  compressionOptions: {
24
24
  level: 9
25
25
  }
26
26
  }).then((o) => {
27
- a(e), n.writeFileSync(s.join(r, "/", e), o);
27
+ u(e), n.writeFileSync(r.join(p, i, e), o);
28
28
  });
29
29
  };
30
- a(e), h();
30
+ u(e), S();
31
31
  };
32
32
  return {
33
33
  name: "vite-plugin-zip-file",
34
34
  apply: "build",
35
35
  closeBundle() {
36
- d();
36
+ h();
37
37
  }
38
38
  };
39
39
  };
40
40
  export {
41
- w as viteZip
41
+ E as viteZip
42
42
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-plugin-zip-file",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "description": "zip files at build time.",
5
5
  "type": "module",
6
6
  "main": "lib/index.cjs",
@@ -8,6 +8,7 @@ import path from 'path';
8
8
  import fs from 'fs';
9
9
  import { createRequire } from 'node:module'
10
10
  const requireds = createRequire(import.meta.url);
11
+ const pathSep = path.sep;
11
12
 
12
13
  export const viteZip = (config = { folderPath: null, outPath: null, zipName: null }) => {
13
14
  let { folderPath, outPath, zipName } = config;
@@ -16,7 +17,7 @@ export const viteZip = (config = { folderPath: null, outPath: null, zipName: nul
16
17
  }
17
18
  folderPath = path.resolve(folderPath);
18
19
  outPath = path.resolve(outPath);
19
- zipName = zipName? zipName: folderPath.split('/').pop() + '.zip';
20
+ zipName = zipName? zipName: folderPath.split(pathSep).pop() + '.zip';
20
21
  const makeZip = () => {
21
22
  const JSZip = requireds('jszip');
22
23
  const zip = new JSZip();
@@ -25,9 +26,9 @@ export const viteZip = (config = { folderPath: null, outPath: null, zipName: nul
25
26
  const readDir = function (zip, dirPath, fileDir = '') {
26
27
  // 读取组件下的根文件目录
27
28
  const files = fs.readdirSync(dirPath);
28
- fileDir += dirPath.split('/').pop() + '/';
29
+ fileDir += dirPath.split(pathSep).pop() + pathSep;
29
30
  files.forEach(fileName => {
30
- const fillPath = path.join(dirPath, "/", fileName)
31
+ const fillPath = path.join(dirPath, pathSep, fileName)
31
32
  const file = fs.statSync(fillPath);
32
33
  // 如果是文件夹的话需要递归遍历下面的子文件
33
34
  if (file.isDirectory()) {
@@ -41,7 +42,7 @@ export const viteZip = (config = { folderPath: null, outPath: null, zipName: nul
41
42
  }
42
43
 
43
44
  const removeZip = (name = zipName) => {
44
- const dest = path.join(outPath, '/' + name)
45
+ const dest = path.join(outPath, pathSep + name)
45
46
  if (fs.existsSync(dest)) {
46
47
  fs.unlinkSync(dest)
47
48
  }
@@ -58,7 +59,7 @@ export const viteZip = (config = { folderPath: null, outPath: null, zipName: nul
58
59
  }
59
60
  }).then(content => {
60
61
  removeZip(zipName)
61
- fs.writeFileSync(path.join(outPath,'/' ,zipName), content);
62
+ fs.writeFileSync(path.join(outPath,pathSep ,zipName), content);
62
63
  });
63
64
  }
64
65
 
@@ -72,4 +73,4 @@ export const viteZip = (config = { folderPath: null, outPath: null, zipName: nul
72
73
  makeZip();
73
74
  }
74
75
  }
75
- }
76
+ }
package/vite.config.js CHANGED
@@ -9,13 +9,13 @@
9
9
  import { defineConfig } from 'vite'
10
10
  import path from 'path';
11
11
  import { fileURLToPath } from 'url';
12
- // import { vitePluginZip } from './src/utils/vite-plugin-zip-file.js';
13
- import { vitePluginZip } from './lib/index.es.js';
12
+ // import { viteZip } from './src/utils/vite-plugin-zip-flie';
13
+ import { viteZip } from './lib/index.mjs';
14
14
  const __dirname = path.dirname(fileURLToPath(import.meta.url));
15
15
  export default defineConfig({
16
16
  publicDir: false,
17
17
  plugins: [
18
- vitePluginZip({
18
+ viteZip({
19
19
  folderPath: path.resolve(__dirname, 'dist'),
20
20
  outPath: path.resolve(__dirname)
21
21
  })