vite-plugin-spire.officejs-test 1.0.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 ADDED
@@ -0,0 +1,44 @@
1
+ # vite-plugin-spire.officejs
2
+
3
+ 一个作用于`spire-officejs`的服务与打包插件。
4
+
5
+ # 安装
6
+
7
+ ```bash
8
+ npm install vite-plugin-spire.officejs
9
+ ```
10
+
11
+ # 使用方式
12
+
13
+ ```js
14
+ // vite.config.js
15
+ import vue from '@vitejs/plugin-vue'
16
+ import { defineConfig } from 'vite'
17
+ import officejsPlugin from 'vite-plugin-spire.officejs'
18
+
19
+ // 默认参数
20
+ export default defineConfig({
21
+ plugins: [
22
+ vue(),
23
+ officejsPlugin()
24
+ ],
25
+ })
26
+
27
+ // 带参数
28
+ export default defineConfig({
29
+ plugins: [
30
+ vue(),
31
+ officejsPlugin({
32
+ name: 'vite-plugin-spire.officejs',
33
+ port: 3001
34
+ })
35
+ ],
36
+ })
37
+ ```
38
+
39
+
40
+ # 参数
41
+ | 属性 | 说明 | 类型 | 默认 |
42
+ | -------- | ----------- | --------------- | ------------------------------ |
43
+ | port | 服务端口 | `number` | 3001 |
44
+ | name | 服务名称 | `string` | `'vite-plugin-spire.officejs'` |
package/lib/index.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ declare const plugin: (...args: any[]) => any;
2
+ export default plugin;
package/lib/index.mjs ADDED
@@ -0,0 +1,89 @@
1
+ import { fileURLToPath as n } from "node:url";
2
+ import { dirname as a } from "node:path";
3
+ import c from "path";
4
+ import f from "./utils/initserver.mjs";
5
+ import p from "./utils/bundle.mjs";
6
+ a(n(import.meta.url));
7
+ function v(s = {}) {
8
+ const i = [
9
+ {
10
+ package: "spireofficejs-document",
11
+ path: "/spireword",
12
+ route: "/service/spireword",
13
+ name: "spireword",
14
+ build: "/service/spireword"
15
+ },
16
+ {
17
+ package: "spireofficejs-spreadsheet",
18
+ path: "/spireexcel",
19
+ route: "/service/spireexcel",
20
+ name: "spireexcel",
21
+ build: "/service/spireexcel"
22
+ },
23
+ {
24
+ package: "spireofficejs-presentation",
25
+ path: "/spirepowerpoint",
26
+ route: "/service/spirepowerpoint",
27
+ name: "spirepowerpoint",
28
+ build: "/service/spirepowerpoint"
29
+ },
30
+ {
31
+ package: "spireofficejs-pdf",
32
+ path: "/spireword",
33
+ route: "/service/spireword",
34
+ name: "pdf",
35
+ build: "/service/spireword"
36
+ },
37
+ {
38
+ package: "spireofficejs-common",
39
+ path: "/lib",
40
+ route: "/service/spirecommon",
41
+ name: "spirecommon",
42
+ build: "/service/spirecommon"
43
+ },
44
+ {
45
+ package: "spireofficejs-editors",
46
+ path: "/lib",
47
+ route: "/editors",
48
+ name: "editors",
49
+ build: "/editors"
50
+ },
51
+ {
52
+ package: "spireofficejs-externs",
53
+ path: "/lib",
54
+ route: "/externs",
55
+ name: "externs",
56
+ build: "/externs"
57
+ },
58
+ {
59
+ package: "spireofficejs-fonts",
60
+ path: "/lib",
61
+ route: "/fontsweb",
62
+ name: "fontsweb",
63
+ build: "/fontsweb"
64
+ }
65
+ ], {
66
+ port: t = 3001,
67
+ name: o = "vite-plugin-spire-officejs"
68
+ } = s;
69
+ let r = "";
70
+ return {
71
+ name: o,
72
+ configResolved(e) {
73
+ r = e.root, c.resolve(r, e.build.outDir);
74
+ },
75
+ // 开发环境
76
+ // 创建一个子进程来提供officeJS的静态资源
77
+ configureServer(e) {
78
+ f(e, i, t, o);
79
+ },
80
+ // 生产环境
81
+ // 将officeJS的静态资源拷贝到输出目录中
82
+ async writeBundle(e, m) {
83
+ console.log("bundle", p), await p(e, r, i);
84
+ }
85
+ };
86
+ }
87
+ export {
88
+ v as default
89
+ };
@@ -0,0 +1,12 @@
1
+ interface interface_options {
2
+ dir: string;
3
+ }
4
+ interface interface_mapping {
5
+ package: string;
6
+ path: string;
7
+ route: string;
8
+ name: string;
9
+ build: string;
10
+ }
11
+ declare const _default: (options: interface_options, projectRoot: string, mappings: Array<interface_mapping>) => Promise<void>;
12
+ export default _default;
@@ -0,0 +1,25 @@
1
+ import r from "path";
2
+ import { copyFile as h } from "./copyFile.mjs";
3
+ const k = [
4
+ "README.md",
5
+ "package.json",
6
+ "index.js",
7
+ "index.d.ts",
8
+ "editors/spireapi/SpireCloudEditor.module.js"
9
+ ], y = async (a, s, t) => {
10
+ const l = a.dir, o = "spire-officejs";
11
+ try {
12
+ const n = (await import("module").then((e) => e.createRequire))(s + "/node_modules/");
13
+ for (let e = 0; e < t.length; e++) {
14
+ let i = t[e].package, d = t[e].path, u = o + t[e].build;
15
+ const p = n.resolve(`${i}/package.json`), g = r.dirname(p) + d, f = r.join(l, u);
16
+ console.log(`copying ${i} ......`), await h(g, f, k);
17
+ }
18
+ console.log(`✅ successfully copied to: ${o}`);
19
+ } catch (c) {
20
+ throw c;
21
+ }
22
+ };
23
+ export {
24
+ y as default
25
+ };
@@ -0,0 +1 @@
1
+ export declare const copyFile: (src: string, dest: string, excludes: Array<string>) => Promise<void>;
@@ -0,0 +1,13 @@
1
+ import { readdir as f, mkdir as l, cp as m } from "fs/promises";
2
+ import { join as c, relative as d } from "path";
3
+ const h = async (t, o, s) => {
4
+ const u = await f(t, { withFileTypes: !0 });
5
+ await l(o, { recursive: !0 });
6
+ for (const i of u) {
7
+ const r = c(t, i.name), n = c(o, i.name), a = d(t, r);
8
+ s.some((e) => typeof e == "string" ? a.includes(e) || i.name === e : e instanceof RegExp ? e.test(a) : !1) || (i.isDirectory() ? await h(r, n, s) : await m(r, n, { recursive: !0 }));
9
+ }
10
+ };
11
+ export {
12
+ h as copyFile
13
+ };
@@ -0,0 +1,8 @@
1
+ interface mapping_inter {
2
+ package: string;
3
+ path: string;
4
+ route: string;
5
+ name: string;
6
+ }
7
+ declare const _default: (viteServer: any, mappings: Array<mapping_inter>, port: Number, name: String) => void;
8
+ export default _default;
@@ -0,0 +1,59 @@
1
+ import { createServer as P } from "node:http";
2
+ import { fileURLToPath as j } from "node:url";
3
+ import { dirname as x, resolve as y, join as k } from "node:path";
4
+ import { access as S } from "node:fs/promises";
5
+ import { statSync as C, createReadStream as H } from "node:fs";
6
+ const A = (g, c, l, f) => {
7
+ var p;
8
+ let r;
9
+ r = P(async (o, e) => {
10
+ var m;
11
+ const i = new URL(o.url, `http://${o.headers.host}`).pathname;
12
+ let a = {};
13
+ if (i.includes("Spire.Pdf.Base") ? a = c.find((t) => t.name == "pdf") : a = c.find((t) => i.startsWith(t.route)), !a) {
14
+ e.writeHead(404, { "Content-Type": "text/plain" }), e.end("Resource not found");
15
+ return;
16
+ }
17
+ e.setHeader("Access-Control-Allow-Origin", "*");
18
+ try {
19
+ let t;
20
+ try {
21
+ const s = await import.meta.resolve(`${a.package}/package.json`);
22
+ t = x(s);
23
+ } catch {
24
+ t = y(process.cwd(), "node_modules", a.package);
25
+ }
26
+ const u = j(t), w = i.replace(a.route, "") || "/index.html", n = k(u, a.path, w);
27
+ await S(n);
28
+ const v = C(n), d = (m = n.split(".").pop()) == null ? void 0 : m.toLowerCase(), $ = {
29
+ html: "text/html",
30
+ js: "application/javascript",
31
+ css: "text/css",
32
+ json: "application/json",
33
+ png: "image/png",
34
+ jpg: "image/jpeg",
35
+ svg: "image/svg+xml",
36
+ wasm: "application/wasm"
37
+ };
38
+ e.writeHead(200, {
39
+ "Content-Type": d && $[d] || "application/octet-stream",
40
+ "Content-Length": v.size
41
+ });
42
+ const h = H(n);
43
+ h.pipe(e), h.on("error", (s) => {
44
+ console.error(`Stream error for ${n}:`, s), e.writeHead(500), e.end("Internal server error");
45
+ });
46
+ } catch (t) {
47
+ t.code === "ENOENT" ? (e.writeHead(404, { "Content-Type": "text/plain" }), e.end(`File not found: ${o.url}`)) : (console.error(`Error serving ${o.url}:`, t), e.writeHead(500), e.end("Internal server error"));
48
+ }
49
+ }), r.listen(l, () => {
50
+ console.log(`📦 [${f}] NPM包静态资源服务已启动:`), console.log(` - 服务地址: http://localhost:${l}`), c.forEach((o) => {
51
+ console.log(` - 映射 ${o.package}${o.path} -> http://localhost:${l}${o.route}`);
52
+ });
53
+ }), (p = g.httpServer) == null || p.on("close", () => {
54
+ r == null || r.close();
55
+ });
56
+ };
57
+ export {
58
+ A as default
59
+ };
package/package.json ADDED
@@ -0,0 +1,17 @@
1
+ {
2
+ "name": "vite-plugin-spire.officejs-test",
3
+ "version": "1.0.1",
4
+ "description": "",
5
+ "main": "./lib/index.mjs",
6
+ "files": [
7
+ "lib"
8
+ ],
9
+ "keywords": [
10
+ "vite",
11
+ "spire.officejs"
12
+ ],
13
+ "author": "",
14
+ "license": "MIT",
15
+ "type": "module",
16
+ "types": "./lib/index.d.ts"
17
+ }