@daye-cli/unplugin-build-zip 0.1.11

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021 Anthony Fu <https://github.com/antfu>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/dist/astro.cjs ADDED
@@ -0,0 +1,13 @@
1
+ const require_src = require('./src-5QrpkfPX.cjs');
2
+
3
+ //#region src/astro.ts
4
+ var astro_default = (options) => ({
5
+ name: "unplugin-starter",
6
+ hooks: { "astro:config:setup": async (astro) => {
7
+ astro.config.vite.plugins ||= [];
8
+ astro.config.vite.plugins.push(require_src.src_default.vite(options));
9
+ } }
10
+ });
11
+
12
+ //#endregion
13
+ module.exports = astro_default;
@@ -0,0 +1,7 @@
1
+ import { Options } from "./types-8iNPxSlS.cjs";
2
+
3
+ //#region src/astro.d.ts
4
+ declare const _default: (options: Options) => any;
5
+
6
+ //#endregion
7
+ export { _default as default };
@@ -0,0 +1,7 @@
1
+ import { Options } from "./types-DFa4qdKR.js";
2
+
3
+ //#region src/astro.d.ts
4
+ declare const _default: (options: Options) => any;
5
+
6
+ //#endregion
7
+ export { _default as default };
package/dist/astro.js ADDED
@@ -0,0 +1,13 @@
1
+ import { src_default } from "./src-CICFYScb.js";
2
+
3
+ //#region src/astro.ts
4
+ var astro_default = (options) => ({
5
+ name: "unplugin-starter",
6
+ hooks: { "astro:config:setup": async (astro) => {
7
+ astro.config.vite.plugins ||= [];
8
+ astro.config.vite.plugins.push(src_default.vite(options));
9
+ } }
10
+ });
11
+
12
+ //#endregion
13
+ export { astro_default as default };
@@ -0,0 +1,8 @@
1
+ const require_src = require('./src-5QrpkfPX.cjs');
2
+ const unplugin = require_src.__toESM(require("unplugin"));
3
+
4
+ //#region src/esbuild.ts
5
+ var esbuild_default = (0, unplugin.createEsbuildPlugin)(require_src.unpluginFactory);
6
+
7
+ //#endregion
8
+ module.exports = esbuild_default;
@@ -0,0 +1,8 @@
1
+ import { Options } from "./types-8iNPxSlS.cjs";
2
+ import * as esbuild9 from "esbuild";
3
+
4
+ //#region src/esbuild.d.ts
5
+ declare const _default: (options?: Options | undefined) => esbuild9.Plugin;
6
+
7
+ //#endregion
8
+ export { _default as default };
@@ -0,0 +1,8 @@
1
+ import { Options } from "./types-DFa4qdKR.js";
2
+ import * as esbuild3 from "esbuild";
3
+
4
+ //#region src/esbuild.d.ts
5
+ declare const _default: (options?: Options | undefined) => esbuild3.Plugin;
6
+
7
+ //#endregion
8
+ export { _default as default };
@@ -0,0 +1,8 @@
1
+ import { unpluginFactory } from "./src-CICFYScb.js";
2
+ import { createEsbuildPlugin } from "unplugin";
3
+
4
+ //#region src/esbuild.ts
5
+ var esbuild_default = createEsbuildPlugin(unpluginFactory);
6
+
7
+ //#endregion
8
+ export { esbuild_default as default };
package/dist/farm.cjs ADDED
@@ -0,0 +1,8 @@
1
+ const require_src = require('./src-5QrpkfPX.cjs');
2
+ const unplugin = require_src.__toESM(require("unplugin"));
3
+
4
+ //#region src/farm.ts
5
+ var farm_default = (0, unplugin.createFarmPlugin)(require_src.unpluginFactory);
6
+
7
+ //#endregion
8
+ module.exports = farm_default;
@@ -0,0 +1,8 @@
1
+ import { Options } from "./types-8iNPxSlS.cjs";
2
+ import * as _farmfe_core13 from "@farmfe/core";
3
+
4
+ //#region src/farm.d.ts
5
+ declare const _default: (options?: Options | undefined) => _farmfe_core13.JsPlugin;
6
+
7
+ //#endregion
8
+ export { _default as default };
package/dist/farm.d.ts ADDED
@@ -0,0 +1,8 @@
1
+ import { Options } from "./types-DFa4qdKR.js";
2
+ import * as _farmfe_core1 from "@farmfe/core";
3
+
4
+ //#region src/farm.d.ts
5
+ declare const _default: (options?: Options | undefined) => _farmfe_core1.JsPlugin;
6
+
7
+ //#endregion
8
+ export { _default as default };
package/dist/farm.js ADDED
@@ -0,0 +1,8 @@
1
+ import { unpluginFactory } from "./src-CICFYScb.js";
2
+ import { createFarmPlugin } from "unplugin";
3
+
4
+ //#region src/farm.ts
5
+ var farm_default = createFarmPlugin(unpluginFactory);
6
+
7
+ //#endregion
8
+ export { farm_default as default };
package/dist/index.cjs ADDED
@@ -0,0 +1,5 @@
1
+ Object.defineProperty(exports, '__esModule', { value: true });
2
+ const require_src = require('./src-5QrpkfPX.cjs');
3
+
4
+ exports.default = require_src.src_default;
5
+ exports.unpluginFactory = require_src.unpluginFactory;
@@ -0,0 +1,10 @@
1
+ import { Options } from "./types-8iNPxSlS.cjs";
2
+ import * as unplugin14 from "unplugin";
3
+ import { UnpluginFactory } from "unplugin";
4
+
5
+ //#region src/core/index.d.ts
6
+ declare const unpluginFactory: UnpluginFactory<Options | undefined>;
7
+ declare const unplugin: unplugin14.UnpluginInstance<Options | undefined, boolean>;
8
+
9
+ //#endregion
10
+ export { unplugin as default, unpluginFactory };
@@ -0,0 +1,10 @@
1
+ import { Options } from "./types-DFa4qdKR.js";
2
+ import * as unplugin14 from "unplugin";
3
+ import { UnpluginFactory } from "unplugin";
4
+
5
+ //#region src/core/index.d.ts
6
+ declare const unpluginFactory: UnpluginFactory<Options | undefined>;
7
+ declare const unplugin: unplugin14.UnpluginInstance<Options | undefined, boolean>;
8
+
9
+ //#endregion
10
+ export { unplugin as default, unpluginFactory };
package/dist/index.js ADDED
@@ -0,0 +1,3 @@
1
+ import { src_default, unpluginFactory } from "./src-CICFYScb.js";
2
+
3
+ export { src_default as default, unpluginFactory };
package/dist/nuxt.cjs ADDED
@@ -0,0 +1,20 @@
1
+ const require_src = require('./src-5QrpkfPX.cjs');
2
+ const require_vite = require('./vite-R5HVQFub.cjs');
3
+ const require_webpack = require('./webpack-DjYcXVER.cjs');
4
+ const __nuxt_kit = require_src.__toESM(require("@nuxt/kit"));
5
+
6
+ //#region src/nuxt.ts
7
+ var nuxt_default = (0, __nuxt_kit.defineNuxtModule)({
8
+ meta: {
9
+ name: "nuxt-unplugin-starter",
10
+ configKey: "unpluginStarter"
11
+ },
12
+ defaults: {},
13
+ setup(options, _nuxt) {
14
+ (0, __nuxt_kit.addVitePlugin)(() => require_vite.vite_default(options));
15
+ (0, __nuxt_kit.addWebpackPlugin)(() => require_webpack.webpack_default(options));
16
+ }
17
+ });
18
+
19
+ //#endregion
20
+ module.exports = nuxt_default;
@@ -0,0 +1,9 @@
1
+ import { Options } from "./types-8iNPxSlS.cjs";
2
+ import * as _nuxt_schema1 from "@nuxt/schema";
3
+
4
+ //#region src/nuxt.d.ts
5
+ interface ModuleOptions extends Options {}
6
+ declare const _default: _nuxt_schema1.NuxtModule<ModuleOptions, ModuleOptions, false>;
7
+
8
+ //#endregion
9
+ export { ModuleOptions, _default as default };
package/dist/nuxt.d.ts ADDED
@@ -0,0 +1,9 @@
1
+ import { Options } from "./types-DFa4qdKR.js";
2
+ import * as _nuxt_schema13 from "@nuxt/schema";
3
+
4
+ //#region src/nuxt.d.ts
5
+ interface ModuleOptions extends Options {}
6
+ declare const _default: _nuxt_schema13.NuxtModule<ModuleOptions, ModuleOptions, false>;
7
+
8
+ //#endregion
9
+ export { ModuleOptions, _default as default };
package/dist/nuxt.js ADDED
@@ -0,0 +1,20 @@
1
+ import "./src-CICFYScb.js";
2
+ import { vite_default } from "./vite-CMvEtka2.js";
3
+ import { webpack_default } from "./webpack-BPGJN4Iw.js";
4
+ import { addVitePlugin, addWebpackPlugin, defineNuxtModule } from "@nuxt/kit";
5
+
6
+ //#region src/nuxt.ts
7
+ var nuxt_default = defineNuxtModule({
8
+ meta: {
9
+ name: "nuxt-unplugin-starter",
10
+ configKey: "unpluginStarter"
11
+ },
12
+ defaults: {},
13
+ setup(options, _nuxt) {
14
+ addVitePlugin(() => vite_default(options));
15
+ addWebpackPlugin(() => webpack_default(options));
16
+ }
17
+ });
18
+
19
+ //#endregion
20
+ export { nuxt_default as default };
@@ -0,0 +1,8 @@
1
+ const require_src = require('./src-5QrpkfPX.cjs');
2
+ const unplugin = require_src.__toESM(require("unplugin"));
3
+
4
+ //#region src/rollup.ts
5
+ var rollup_default = (0, unplugin.createRollupPlugin)(require_src.unpluginFactory);
6
+
7
+ //#endregion
8
+ module.exports = rollup_default;
@@ -0,0 +1,8 @@
1
+ import { Options } from "./types-8iNPxSlS.cjs";
2
+ import * as rollup3 from "rollup";
3
+
4
+ //#region src/rollup.d.ts
5
+ declare const _default: (options?: Options | undefined) => rollup3.Plugin<any> | rollup3.Plugin<any>[];
6
+
7
+ //#endregion
8
+ export { _default as default };
@@ -0,0 +1,8 @@
1
+ import { Options } from "./types-DFa4qdKR.js";
2
+ import * as rollup8 from "rollup";
3
+
4
+ //#region src/rollup.d.ts
5
+ declare const _default: (options?: Options | undefined) => rollup8.Plugin<any> | rollup8.Plugin<any>[];
6
+
7
+ //#endregion
8
+ export { _default as default };
package/dist/rollup.js ADDED
@@ -0,0 +1,8 @@
1
+ import { unpluginFactory } from "./src-CICFYScb.js";
2
+ import { createRollupPlugin } from "unplugin";
3
+
4
+ //#region src/rollup.ts
5
+ var rollup_default = createRollupPlugin(unpluginFactory);
6
+
7
+ //#endregion
8
+ export { rollup_default as default };
@@ -0,0 +1,8 @@
1
+ const require_src = require('./src-5QrpkfPX.cjs');
2
+ const unplugin = require_src.__toESM(require("unplugin"));
3
+
4
+ //#region src/rspack.ts
5
+ var rspack_default = (0, unplugin.createRspackPlugin)(require_src.unpluginFactory);
6
+
7
+ //#endregion
8
+ module.exports = rspack_default;
@@ -0,0 +1,7 @@
1
+ import { Options } from "./types-8iNPxSlS.cjs";
2
+
3
+ //#region src/rspack.d.ts
4
+ declare const _default: (options?: Options | undefined) => RspackPluginInstance;
5
+
6
+ //#endregion
7
+ export { _default as default };
@@ -0,0 +1,7 @@
1
+ import { Options } from "./types-DFa4qdKR.js";
2
+
3
+ //#region src/rspack.d.ts
4
+ declare const _default: (options?: Options | undefined) => RspackPluginInstance;
5
+
6
+ //#endregion
7
+ export { _default as default };
package/dist/rspack.js ADDED
@@ -0,0 +1,8 @@
1
+ import { unpluginFactory } from "./src-CICFYScb.js";
2
+ import { createRspackPlugin } from "unplugin";
3
+
4
+ //#region src/rspack.ts
5
+ var rspack_default = createRspackPlugin(unpluginFactory);
6
+
7
+ //#endregion
8
+ export { rspack_default as default };
@@ -0,0 +1,219 @@
1
+ //#region rolldown:runtime
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __copyProps = (to, from, except, desc) => {
9
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
10
+ key = keys[i];
11
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
12
+ get: ((k) => from[k]).bind(null, key),
13
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
14
+ });
15
+ }
16
+ return to;
17
+ };
18
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
19
+ value: mod,
20
+ enumerable: true
21
+ }) : target, mod));
22
+
23
+ //#endregion
24
+ const node_fs = __toESM(require("node:fs"));
25
+ const node_path = __toESM(require("node:path"));
26
+ const node_process = __toESM(require("node:process"));
27
+ const unplugin = __toESM(require("unplugin"));
28
+ const node_child_process = __toESM(require("node:child_process"));
29
+ const archiver = __toESM(require("archiver"));
30
+
31
+ //#region src/core/utils.ts
32
+ /**
33
+ * 压缩指定目录为 zip 文件
34
+ * @param sourceDir 源目录路径
35
+ * @param outputPath 输出路径
36
+ * @param folder zip 内嵌文件夹名称
37
+ * @returns Promise<void>
38
+ */
39
+ function zipDirectory(sourceDir, outputPath, folder) {
40
+ return new Promise((resolve, reject) => {
41
+ const output = node_fs.default.createWriteStream(outputPath);
42
+ const archive = (0, archiver.default)("zip", { zlib: { level: 9 } });
43
+ output.on("close", resolve);
44
+ archive.on("error", reject);
45
+ archive.pipe(output);
46
+ archive.directory(sourceDir, folder || false);
47
+ archive.finalize();
48
+ });
49
+ }
50
+ /**
51
+ * 将文件本身(文件拖放格式)复制到系统剪切板
52
+ * Windows: PowerShell SetFileDropList
53
+ * macOS: osascript
54
+ * Linux: xclip / xsel(需系统安装)
55
+ */
56
+ function copyFileToClipboard(filePath) {
57
+ try {
58
+ const platform = node_process.default.platform;
59
+ if (platform === "win32") {
60
+ const escaped = filePath.replace(/\\/g, "\\\\");
61
+ const ps = [
62
+ "Add-Type -AssemblyName System.Windows.Forms",
63
+ `$col = New-Object System.Collections.Specialized.StringCollection`,
64
+ `$col.Add('${escaped}')`,
65
+ "[System.Windows.Forms.Clipboard]::SetFileDropList($col)"
66
+ ].join("; ");
67
+ (0, node_child_process.execSync)(`powershell -NoProfile -NonInteractive -Command "${ps}"`, {
68
+ stdio: "ignore",
69
+ timeout: 6e3
70
+ });
71
+ } else if (platform === "darwin") {
72
+ const escaped = filePath.replace(/"/g, "\\\"");
73
+ (0, node_child_process.execSync)(`osascript -e 'set the clipboard to POSIX file "${escaped}"'`, {
74
+ stdio: "ignore",
75
+ timeout: 5e3
76
+ });
77
+ } else {
78
+ const uri = `file://${filePath}\n`;
79
+ try {
80
+ (0, node_child_process.execSync)(`echo -n '${uri}' | xclip -selection clipboard -t text/uri-list`, {
81
+ stdio: "ignore",
82
+ timeout: 5e3
83
+ });
84
+ } catch {
85
+ (0, node_child_process.execSync)(`echo -n '${uri}' | xsel --clipboard --input`, {
86
+ stdio: "ignore",
87
+ timeout: 5e3
88
+ });
89
+ }
90
+ }
91
+ return true;
92
+ } catch {
93
+ return false;
94
+ }
95
+ }
96
+ function sendSystemNotify(title, body) {
97
+ try {
98
+ const platform = node_process.default.platform;
99
+ if (platform === "win32") {
100
+ const safeTitle = title.split(`'`).join(`''`);
101
+ const safeBody = body.split(`'`).join(`''`);
102
+ const ps = [
103
+ `Add-Type -AssemblyName System.Windows.Forms`,
104
+ `$n = New-Object System.Windows.Forms.NotifyIcon`,
105
+ `$n.Icon = [System.Drawing.SystemIcons]::Information`,
106
+ `$n.BalloonTipIcon = [System.Windows.Forms.ToolTipIcon]::Info`,
107
+ `$n.BalloonTipTitle = '${safeTitle}'`,
108
+ `$n.BalloonTipText = '${safeBody}'`,
109
+ `$n.Visible = $true`,
110
+ `$n.ShowBalloonTip(4000)`,
111
+ `Start-Sleep -Milliseconds 4100`,
112
+ `$n.Dispose()`
113
+ ].join("; ");
114
+ (0, node_child_process.execSync)(`powershell -NoProfile -NonInteractive -Command "${ps}"`, {
115
+ stdio: "ignore",
116
+ timeout: 6e3
117
+ });
118
+ } else if (platform === "darwin") {
119
+ const safeTitle = title.replace(/"/g, "\\\"");
120
+ const safeBody = body.replace(/"/g, "\\\"");
121
+ (0, node_child_process.execSync)(`osascript -e 'display notification "${safeBody}" with title "${safeTitle}"'`, {
122
+ stdio: "ignore",
123
+ timeout: 5e3
124
+ });
125
+ } else {
126
+ const safeTitle = title.replace(/"/g, "\\\"");
127
+ const safeBody = body.replace(/"/g, "\\\"");
128
+ (0, node_child_process.execSync)(`notify-send "${safeTitle}" "${safeBody}"`, {
129
+ stdio: "ignore",
130
+ timeout: 5e3
131
+ });
132
+ }
133
+ } catch {}
134
+ }
135
+
136
+ //#endregion
137
+ //#region src/core/index.ts
138
+ const unpluginFactory = (options = {}) => {
139
+ const { filename: customFilename, folder, copyToClipboard = true, notify = true } = options;
140
+ let outDir = "dist";
141
+ let root = node_process.default.cwd();
142
+ let isViteBuild = false;
143
+ let isWebpackBuild = false;
144
+ const doZip = async (outDirAbsolute) => {
145
+ if (!node_fs.default.existsSync(outDirAbsolute)) {
146
+ console.warn(`\n \x1B[33m⚠\x1B[0m \x1B[1m[build-zip]\x1B[0m 输出目录不存在: ${outDirAbsolute}`);
147
+ return;
148
+ }
149
+ const filename = customFilename ?? node_path.default.basename(outDirAbsolute);
150
+ const zipPath = node_path.default.resolve(node_path.default.dirname(outDirAbsolute), `${filename}.zip`);
151
+ if (node_fs.default.existsSync(zipPath)) node_fs.default.unlinkSync(zipPath);
152
+ await zipDirectory(outDirAbsolute, zipPath, folder);
153
+ const display = node_path.default.relative(root, zipPath).replace(/\\/g, "/");
154
+ console.log(`\n \x1B[32m✓\x1B[0m \x1B[1m[build-zip]\x1B[0m 产物已压缩 → \x1B[36m${display}\x1B[0m`);
155
+ if (copyToClipboard) {
156
+ const ok = copyFileToClipboard(zipPath);
157
+ if (ok) console.log(` \x1B[90m↳ zip 文件已复制到剪切板(可直接粘贴到文件夹)\x1B[0m`);
158
+ }
159
+ if (notify) sendSystemNotify("Build Complete ✓", `已打包:${filename}.zip`);
160
+ };
161
+ return {
162
+ name: "@daye-cli/unplugin-build-zip",
163
+ vite: {
164
+ apply: "build",
165
+ configResolved(config) {
166
+ outDir = config.build.outDir || "dist";
167
+ root = config.root;
168
+ isViteBuild = config.command === "build";
169
+ },
170
+ async closeBundle() {
171
+ if (!isViteBuild) return;
172
+ const outDirAbsolute = node_path.default.isAbsolute(outDir) ? outDir : node_path.default.resolve(root, outDir);
173
+ await doZip(outDirAbsolute);
174
+ }
175
+ },
176
+ rollup: { async writeBundle(options$1) {
177
+ if (!options$1) return;
178
+ outDir = options$1.dir || "dist";
179
+ const outDirAbsolute = node_path.default.isAbsolute(outDir) ? outDir : node_path.default.resolve(root, outDir);
180
+ await doZip(outDirAbsolute);
181
+ } },
182
+ webpack(compiler) {
183
+ isWebpackBuild = compiler.options.mode === "production";
184
+ compiler.hooks.done.tapPromise("@daye-cli/unplugin-build-zip", async (stats) => {
185
+ if (stats.hasErrors()) return;
186
+ if (!isWebpackBuild) return;
187
+ outDir = compiler.options.output.path || node_path.default.resolve(node_process.default.cwd(), "dist");
188
+ root = compiler.context || node_process.default.cwd();
189
+ const outDirAbsolute = node_path.default.isAbsolute(outDir) ? outDir : node_path.default.resolve(root, outDir);
190
+ await doZip(outDirAbsolute);
191
+ });
192
+ }
193
+ };
194
+ };
195
+ const unplugin$1 = /* @__PURE__ */ (0, unplugin.createUnplugin)(unpluginFactory);
196
+
197
+ //#endregion
198
+ //#region src/index.ts
199
+ var src_default = unplugin$1;
200
+
201
+ //#endregion
202
+ Object.defineProperty(exports, '__toESM', {
203
+ enumerable: true,
204
+ get: function () {
205
+ return __toESM;
206
+ }
207
+ });
208
+ Object.defineProperty(exports, 'src_default', {
209
+ enumerable: true,
210
+ get: function () {
211
+ return src_default;
212
+ }
213
+ });
214
+ Object.defineProperty(exports, 'unpluginFactory', {
215
+ enumerable: true,
216
+ get: function () {
217
+ return unpluginFactory;
218
+ }
219
+ });
@@ -0,0 +1,179 @@
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+ import process from "node:process";
4
+ import { createUnplugin } from "unplugin";
5
+ import { execSync } from "node:child_process";
6
+ import archiver from "archiver";
7
+
8
+ //#region src/core/utils.ts
9
+ /**
10
+ * 压缩指定目录为 zip 文件
11
+ * @param sourceDir 源目录路径
12
+ * @param outputPath 输出路径
13
+ * @param folder zip 内嵌文件夹名称
14
+ * @returns Promise<void>
15
+ */
16
+ function zipDirectory(sourceDir, outputPath, folder) {
17
+ return new Promise((resolve, reject) => {
18
+ const output = fs.createWriteStream(outputPath);
19
+ const archive = archiver("zip", { zlib: { level: 9 } });
20
+ output.on("close", resolve);
21
+ archive.on("error", reject);
22
+ archive.pipe(output);
23
+ archive.directory(sourceDir, folder || false);
24
+ archive.finalize();
25
+ });
26
+ }
27
+ /**
28
+ * 将文件本身(文件拖放格式)复制到系统剪切板
29
+ * Windows: PowerShell SetFileDropList
30
+ * macOS: osascript
31
+ * Linux: xclip / xsel(需系统安装)
32
+ */
33
+ function copyFileToClipboard(filePath) {
34
+ try {
35
+ const platform = process.platform;
36
+ if (platform === "win32") {
37
+ const escaped = filePath.replace(/\\/g, "\\\\");
38
+ const ps = [
39
+ "Add-Type -AssemblyName System.Windows.Forms",
40
+ `$col = New-Object System.Collections.Specialized.StringCollection`,
41
+ `$col.Add('${escaped}')`,
42
+ "[System.Windows.Forms.Clipboard]::SetFileDropList($col)"
43
+ ].join("; ");
44
+ execSync(`powershell -NoProfile -NonInteractive -Command "${ps}"`, {
45
+ stdio: "ignore",
46
+ timeout: 6e3
47
+ });
48
+ } else if (platform === "darwin") {
49
+ const escaped = filePath.replace(/"/g, "\\\"");
50
+ execSync(`osascript -e 'set the clipboard to POSIX file "${escaped}"'`, {
51
+ stdio: "ignore",
52
+ timeout: 5e3
53
+ });
54
+ } else {
55
+ const uri = `file://${filePath}\n`;
56
+ try {
57
+ execSync(`echo -n '${uri}' | xclip -selection clipboard -t text/uri-list`, {
58
+ stdio: "ignore",
59
+ timeout: 5e3
60
+ });
61
+ } catch {
62
+ execSync(`echo -n '${uri}' | xsel --clipboard --input`, {
63
+ stdio: "ignore",
64
+ timeout: 5e3
65
+ });
66
+ }
67
+ }
68
+ return true;
69
+ } catch {
70
+ return false;
71
+ }
72
+ }
73
+ function sendSystemNotify(title, body) {
74
+ try {
75
+ const platform = process.platform;
76
+ if (platform === "win32") {
77
+ const safeTitle = title.split(`'`).join(`''`);
78
+ const safeBody = body.split(`'`).join(`''`);
79
+ const ps = [
80
+ `Add-Type -AssemblyName System.Windows.Forms`,
81
+ `$n = New-Object System.Windows.Forms.NotifyIcon`,
82
+ `$n.Icon = [System.Drawing.SystemIcons]::Information`,
83
+ `$n.BalloonTipIcon = [System.Windows.Forms.ToolTipIcon]::Info`,
84
+ `$n.BalloonTipTitle = '${safeTitle}'`,
85
+ `$n.BalloonTipText = '${safeBody}'`,
86
+ `$n.Visible = $true`,
87
+ `$n.ShowBalloonTip(4000)`,
88
+ `Start-Sleep -Milliseconds 4100`,
89
+ `$n.Dispose()`
90
+ ].join("; ");
91
+ execSync(`powershell -NoProfile -NonInteractive -Command "${ps}"`, {
92
+ stdio: "ignore",
93
+ timeout: 6e3
94
+ });
95
+ } else if (platform === "darwin") {
96
+ const safeTitle = title.replace(/"/g, "\\\"");
97
+ const safeBody = body.replace(/"/g, "\\\"");
98
+ execSync(`osascript -e 'display notification "${safeBody}" with title "${safeTitle}"'`, {
99
+ stdio: "ignore",
100
+ timeout: 5e3
101
+ });
102
+ } else {
103
+ const safeTitle = title.replace(/"/g, "\\\"");
104
+ const safeBody = body.replace(/"/g, "\\\"");
105
+ execSync(`notify-send "${safeTitle}" "${safeBody}"`, {
106
+ stdio: "ignore",
107
+ timeout: 5e3
108
+ });
109
+ }
110
+ } catch {}
111
+ }
112
+
113
+ //#endregion
114
+ //#region src/core/index.ts
115
+ const unpluginFactory = (options = {}) => {
116
+ const { filename: customFilename, folder, copyToClipboard = true, notify = true } = options;
117
+ let outDir = "dist";
118
+ let root = process.cwd();
119
+ let isViteBuild = false;
120
+ let isWebpackBuild = false;
121
+ const doZip = async (outDirAbsolute) => {
122
+ if (!fs.existsSync(outDirAbsolute)) {
123
+ console.warn(`\n \x1B[33m⚠\x1B[0m \x1B[1m[build-zip]\x1B[0m 输出目录不存在: ${outDirAbsolute}`);
124
+ return;
125
+ }
126
+ const filename = customFilename ?? path.basename(outDirAbsolute);
127
+ const zipPath = path.resolve(path.dirname(outDirAbsolute), `${filename}.zip`);
128
+ if (fs.existsSync(zipPath)) fs.unlinkSync(zipPath);
129
+ await zipDirectory(outDirAbsolute, zipPath, folder);
130
+ const display = path.relative(root, zipPath).replace(/\\/g, "/");
131
+ console.log(`\n \x1B[32m✓\x1B[0m \x1B[1m[build-zip]\x1B[0m 产物已压缩 → \x1B[36m${display}\x1B[0m`);
132
+ if (copyToClipboard) {
133
+ const ok = copyFileToClipboard(zipPath);
134
+ if (ok) console.log(` \x1B[90m↳ zip 文件已复制到剪切板(可直接粘贴到文件夹)\x1B[0m`);
135
+ }
136
+ if (notify) sendSystemNotify("Build Complete ✓", `已打包:${filename}.zip`);
137
+ };
138
+ return {
139
+ name: "@daye-cli/unplugin-build-zip",
140
+ vite: {
141
+ apply: "build",
142
+ configResolved(config) {
143
+ outDir = config.build.outDir || "dist";
144
+ root = config.root;
145
+ isViteBuild = config.command === "build";
146
+ },
147
+ async closeBundle() {
148
+ if (!isViteBuild) return;
149
+ const outDirAbsolute = path.isAbsolute(outDir) ? outDir : path.resolve(root, outDir);
150
+ await doZip(outDirAbsolute);
151
+ }
152
+ },
153
+ rollup: { async writeBundle(options$1) {
154
+ if (!options$1) return;
155
+ outDir = options$1.dir || "dist";
156
+ const outDirAbsolute = path.isAbsolute(outDir) ? outDir : path.resolve(root, outDir);
157
+ await doZip(outDirAbsolute);
158
+ } },
159
+ webpack(compiler) {
160
+ isWebpackBuild = compiler.options.mode === "production";
161
+ compiler.hooks.done.tapPromise("@daye-cli/unplugin-build-zip", async (stats) => {
162
+ if (stats.hasErrors()) return;
163
+ if (!isWebpackBuild) return;
164
+ outDir = compiler.options.output.path || path.resolve(process.cwd(), "dist");
165
+ root = compiler.context || process.cwd();
166
+ const outDirAbsolute = path.isAbsolute(outDir) ? outDir : path.resolve(root, outDir);
167
+ await doZip(outDirAbsolute);
168
+ });
169
+ }
170
+ };
171
+ };
172
+ const unplugin = /* @__PURE__ */ createUnplugin(unpluginFactory);
173
+
174
+ //#endregion
175
+ //#region src/index.ts
176
+ var src_default = unplugin;
177
+
178
+ //#endregion
179
+ export { src_default, unpluginFactory };
@@ -0,0 +1,24 @@
1
+ //#region src/core/types.d.ts
2
+ interface Options {
3
+ /**
4
+ * 压缩包文件名,不含 `.zip` 后缀
5
+ * 默认取 vite `build.outDir` 的 basename(通常为 `"dist"`)
6
+ */
7
+ filename?: string;
8
+ /**
9
+ * zip 内嵌文件夹名称
10
+ * 未配置时,保持当前行为:直接压缩输出目录中的文件
11
+ */
12
+ folder?: string;
13
+ /**
14
+ * 完成后将 zip 文件本身(文件拖放格式)复制到系统剪切板
15
+ * @default true
16
+ */
17
+ copyToClipboard?: boolean;
18
+ /**
19
+ * 完成后发送系统通知
20
+ * @default true
21
+ */
22
+ notify?: boolean;
23
+ } //#endregion
24
+ export { Options };
@@ -0,0 +1,24 @@
1
+ //#region src/core/types.d.ts
2
+ interface Options {
3
+ /**
4
+ * 压缩包文件名,不含 `.zip` 后缀
5
+ * 默认取 vite `build.outDir` 的 basename(通常为 `"dist"`)
6
+ */
7
+ filename?: string;
8
+ /**
9
+ * zip 内嵌文件夹名称
10
+ * 未配置时,保持当前行为:直接压缩输出目录中的文件
11
+ */
12
+ folder?: string;
13
+ /**
14
+ * 完成后将 zip 文件本身(文件拖放格式)复制到系统剪切板
15
+ * @default true
16
+ */
17
+ copyToClipboard?: boolean;
18
+ /**
19
+ * 完成后发送系统通知
20
+ * @default true
21
+ */
22
+ notify?: boolean;
23
+ } //#endregion
24
+ export { Options };
@@ -0,0 +1,8 @@
1
+ import { unpluginFactory } from "./src-CICFYScb.js";
2
+ import { createVitePlugin } from "unplugin";
3
+
4
+ //#region src/vite.ts
5
+ var vite_default = createVitePlugin(unpluginFactory);
6
+
7
+ //#endregion
8
+ export { vite_default };
@@ -0,0 +1,13 @@
1
+ const require_src = require('./src-5QrpkfPX.cjs');
2
+ const unplugin = require_src.__toESM(require("unplugin"));
3
+
4
+ //#region src/vite.ts
5
+ var vite_default = (0, unplugin.createVitePlugin)(require_src.unpluginFactory);
6
+
7
+ //#endregion
8
+ Object.defineProperty(exports, 'vite_default', {
9
+ enumerable: true,
10
+ get: function () {
11
+ return vite_default;
12
+ }
13
+ });
package/dist/vite.cjs ADDED
@@ -0,0 +1,4 @@
1
+ require('./src-5QrpkfPX.cjs');
2
+ const require_vite = require('./vite-R5HVQFub.cjs');
3
+
4
+ module.exports = require_vite.vite_default;
@@ -0,0 +1,8 @@
1
+ import { Options } from "./types-8iNPxSlS.cjs";
2
+ import * as vite6 from "vite";
3
+
4
+ //#region src/vite.d.ts
5
+ declare const _default: (options?: Options | undefined) => vite6.Plugin<any> | vite6.Plugin<any>[];
6
+
7
+ //#endregion
8
+ export { _default as default };
package/dist/vite.d.ts ADDED
@@ -0,0 +1,8 @@
1
+ import { Options } from "./types-DFa4qdKR.js";
2
+ import * as vite5 from "vite";
3
+
4
+ //#region src/vite.d.ts
5
+ declare const _default: (options?: Options | undefined) => vite5.Plugin<any> | vite5.Plugin<any>[];
6
+
7
+ //#endregion
8
+ export { _default as default };
package/dist/vite.js ADDED
@@ -0,0 +1,4 @@
1
+ import "./src-CICFYScb.js";
2
+ import { vite_default } from "./vite-CMvEtka2.js";
3
+
4
+ export { vite_default as default };
@@ -0,0 +1,8 @@
1
+ import { unpluginFactory } from "./src-CICFYScb.js";
2
+ import { createWebpackPlugin } from "unplugin";
3
+
4
+ //#region src/webpack.ts
5
+ var webpack_default = createWebpackPlugin(unpluginFactory);
6
+
7
+ //#endregion
8
+ export { webpack_default };
@@ -0,0 +1,13 @@
1
+ const require_src = require('./src-5QrpkfPX.cjs');
2
+ const unplugin = require_src.__toESM(require("unplugin"));
3
+
4
+ //#region src/webpack.ts
5
+ var webpack_default = (0, unplugin.createWebpackPlugin)(require_src.unpluginFactory);
6
+
7
+ //#endregion
8
+ Object.defineProperty(exports, 'webpack_default', {
9
+ enumerable: true,
10
+ get: function () {
11
+ return webpack_default;
12
+ }
13
+ });
@@ -0,0 +1,4 @@
1
+ require('./src-5QrpkfPX.cjs');
2
+ const require_webpack = require('./webpack-DjYcXVER.cjs');
3
+
4
+ module.exports = require_webpack.webpack_default;
@@ -0,0 +1,8 @@
1
+ import { Options } from "./types-8iNPxSlS.cjs";
2
+ import * as webpack11 from "webpack";
3
+
4
+ //#region src/webpack.d.ts
5
+ declare const _default: (options?: Options | undefined) => webpack11.WebpackPluginInstance;
6
+
7
+ //#endregion
8
+ export { _default as default };
@@ -0,0 +1,8 @@
1
+ import { Options } from "./types-DFa4qdKR.js";
2
+ import * as webpack11 from "webpack";
3
+
4
+ //#region src/webpack.d.ts
5
+ declare const _default: (options?: Options | undefined) => webpack11.WebpackPluginInstance;
6
+
7
+ //#endregion
8
+ export { _default as default };
@@ -0,0 +1,4 @@
1
+ import "./src-CICFYScb.js";
2
+ import { webpack_default } from "./webpack-BPGJN4Iw.js";
3
+
4
+ export { webpack_default as default };
package/package.json ADDED
@@ -0,0 +1,150 @@
1
+ {
2
+ "name": "@daye-cli/unplugin-build-zip",
3
+ "type": "module",
4
+ "version": "0.1.11",
5
+ "description": "An unplugin that zips the build output directory after a successful build",
6
+ "license": "MIT",
7
+ "homepage": "https://github.com/DaYePython/unplugin-build-zip#readme",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/DaYePython/unplugin-build-zip.git"
11
+ },
12
+ "bugs": {
13
+ "url": "https://github.com/DaYePython/unplugin-build-zip/issues"
14
+ },
15
+ "keywords": [
16
+ "unplugin",
17
+ "vite",
18
+ "webpack",
19
+ "rollup",
20
+ "build",
21
+ "zip"
22
+ ],
23
+ "exports": {
24
+ ".": {
25
+ "types": "./dist/index.d.ts",
26
+ "import": "./dist/index.js",
27
+ "require": "./dist/index.cjs"
28
+ },
29
+ "./astro": {
30
+ "types": "./dist/astro.d.ts",
31
+ "import": "./dist/astro.js",
32
+ "require": "./dist/astro.cjs"
33
+ },
34
+ "./esbuild": {
35
+ "types": "./dist/esbuild.d.ts",
36
+ "import": "./dist/esbuild.js",
37
+ "require": "./dist/esbuild.cjs"
38
+ },
39
+ "./farm": {
40
+ "types": "./dist/farm.d.ts",
41
+ "import": "./dist/farm.js",
42
+ "require": "./dist/farm.cjs"
43
+ },
44
+ "./nuxt": {
45
+ "types": "./dist/nuxt.d.ts",
46
+ "import": "./dist/nuxt.js",
47
+ "require": "./dist/nuxt.cjs"
48
+ },
49
+ "./rollup": {
50
+ "types": "./dist/rollup.d.ts",
51
+ "import": "./dist/rollup.js",
52
+ "require": "./dist/rollup.cjs"
53
+ },
54
+ "./rspack": {
55
+ "types": "./dist/rspack.d.ts",
56
+ "import": "./dist/rspack.js",
57
+ "require": "./dist/rspack.cjs"
58
+ },
59
+ "./types": {
60
+ "types": "./dist/types.d.ts",
61
+ "import": "./dist/types.js",
62
+ "require": "./dist/types.cjs"
63
+ },
64
+ "./vite": {
65
+ "types": "./dist/vite.d.ts",
66
+ "import": "./dist/vite.js",
67
+ "require": "./dist/vite.cjs"
68
+ },
69
+ "./webpack": {
70
+ "types": "./dist/webpack.d.ts",
71
+ "import": "./dist/webpack.js",
72
+ "require": "./dist/webpack.cjs"
73
+ },
74
+ "./package.json": "./package.json"
75
+ },
76
+ "main": "./dist/index.cjs",
77
+ "module": "./dist/index.js",
78
+ "types": "./dist/index.d.ts",
79
+ "typesVersions": {
80
+ "*": {
81
+ "*": [
82
+ "./dist/*",
83
+ "./*"
84
+ ]
85
+ }
86
+ },
87
+ "files": [
88
+ "dist"
89
+ ],
90
+ "peerDependencies": {
91
+ "@farmfe/core": ">=1",
92
+ "@nuxt/kit": "^3",
93
+ "@nuxt/schema": "^3",
94
+ "esbuild": "*",
95
+ "rollup": "^3",
96
+ "vite": ">=3",
97
+ "webpack": "^4 || ^5"
98
+ },
99
+ "peerDependenciesMeta": {
100
+ "@farmfe/core": {
101
+ "optional": true
102
+ },
103
+ "@nuxt/kit": {
104
+ "optional": true
105
+ },
106
+ "@nuxt/schema": {
107
+ "optional": true
108
+ },
109
+ "esbuild": {
110
+ "optional": true
111
+ },
112
+ "rollup": {
113
+ "optional": true
114
+ },
115
+ "vite": {
116
+ "optional": true
117
+ },
118
+ "webpack": {
119
+ "optional": true
120
+ }
121
+ },
122
+ "dependencies": {
123
+ "archiver": "^7.0.1",
124
+ "unplugin": "^2.3.4"
125
+ },
126
+ "devDependencies": {
127
+ "@antfu/eslint-config": "^4.13.2",
128
+ "@nuxt/kit": "^3.17.4",
129
+ "@nuxt/schema": "^3.17.4",
130
+ "@types/archiver": "^7.0.0",
131
+ "@types/node": "^22.15.21",
132
+ "eslint": "^9.27.0",
133
+ "nodemon": "^3.1.10",
134
+ "rollup": "^4.41.0",
135
+ "tsdown": "^0.12.0",
136
+ "tsx": "^4.19.4",
137
+ "typescript": "^5.8.3",
138
+ "vite": "^6.3.5",
139
+ "vitest": "^3.1.4",
140
+ "webpack": "^5.99.9"
141
+ },
142
+ "scripts": {
143
+ "build": "tsdown",
144
+ "dev": "tsdown -w",
145
+ "lint": "eslint .",
146
+ "play": "npm -C playground run dev",
147
+ "start": "tsx src/index.ts",
148
+ "test": "vitest"
149
+ }
150
+ }