@luna-park/plugin 1.0.4 → 1.0.5
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/bin/preview.js +50 -0
- package/dist/preview.cjs +1 -0
- package/dist/preview.d.ts +7 -0
- package/dist/preview.js +39 -0
- package/package.json +20 -12
package/bin/preview.js
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { parseArgs } from "node:util";
|
|
3
|
+
|
|
4
|
+
import { resolve } from "path";
|
|
5
|
+
|
|
6
|
+
import { startPreviewServer } from "../dist/preview.js";
|
|
7
|
+
|
|
8
|
+
const cwd = process.cwd();
|
|
9
|
+
|
|
10
|
+
// Parse CLI arguments
|
|
11
|
+
const { values } = parseArgs({
|
|
12
|
+
options: {
|
|
13
|
+
dist: {
|
|
14
|
+
default: "dist",
|
|
15
|
+
short: "d",
|
|
16
|
+
type: "string"
|
|
17
|
+
},
|
|
18
|
+
help: {
|
|
19
|
+
default: false,
|
|
20
|
+
short: "h",
|
|
21
|
+
type: "boolean"
|
|
22
|
+
},
|
|
23
|
+
port: {
|
|
24
|
+
default: "2084",
|
|
25
|
+
short: "p",
|
|
26
|
+
type: "string"
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
if (values.help) {
|
|
32
|
+
console.log(`
|
|
33
|
+
Usage: luna-preview [options]
|
|
34
|
+
|
|
35
|
+
Options:
|
|
36
|
+
-p, --port <port> Port to run the server on (default: 2084)
|
|
37
|
+
-d, --dist <dir> Distribution directory to serve (default: dist)
|
|
38
|
+
-h, --help Show this help message
|
|
39
|
+
`);
|
|
40
|
+
process.exit(0);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const dist = resolve(cwd, values.dist);
|
|
44
|
+
const port = parseInt(values.port);
|
|
45
|
+
|
|
46
|
+
startPreviewServer({
|
|
47
|
+
dist,
|
|
48
|
+
externals: ["vue", "vue-router"],
|
|
49
|
+
port
|
|
50
|
+
});
|
package/dist/preview.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("@fastify/cors"),p=require("@fastify/static"),f=require("fastify"),a=require("fs"),o=require("path");function d(t,e){return t.replace(/import\s+(.*?)\s+from\s+['"]([^.'/][^'"]*)['"]/g,(r,s,n)=>e.includes(n)?r:`import ${s} from 'https://esm.sh/${n}'`).replace(/import\s+['"]([^.'/][^'"]*)['"]/g,(r,s)=>e.includes(s)?r:`import 'https://esm.sh/${s}'`)}async function m(t){const e=f({logger:!1});e.register(l,{origin:["https://luna-park.app",/localhost:[0-9]+/,/127\.0\.0\.1:[0-9]+/]}),e.addHook("onRequest",async(r,s)=>{const n=r.url==="/"?"/index.js":r.url;let i=o.join(t.dist,n);if(!a.existsSync(i)&&!o.extname(r.url)&&(i=o.join(t.dist,"index.js")),!a.existsSync(i))return;if(o.extname(i)===".js"){const c=a.readFileSync(i,"utf-8"),u=d(c,t.externals);return s.type("application/javascript").send(u),s}}),e.register(p,{prefix:"/",root:t.dist}),await e.listen({host:"127.0.0.1",port:t.port}),console.log(`Preview server started at http://127.0.0.1:${t.port}`)}exports.startPreviewServer=m;
|
package/dist/preview.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import l from "@fastify/cors";
|
|
2
|
+
import c from "@fastify/static";
|
|
3
|
+
import u from "fastify";
|
|
4
|
+
import { existsSync as n, readFileSync as d } from "fs";
|
|
5
|
+
import { join as a, extname as p } from "path";
|
|
6
|
+
function h(t, r) {
|
|
7
|
+
return t.replace(
|
|
8
|
+
/import\s+(.*?)\s+from\s+['"]([^.'/][^'"]*)['"]/g,
|
|
9
|
+
(e, s, i) => r.includes(i) ? e : `import ${s} from 'https://esm.sh/${i}'`
|
|
10
|
+
).replace(
|
|
11
|
+
/import\s+['"]([^.'/][^'"]*)['"]/g,
|
|
12
|
+
(e, s) => r.includes(s) ? e : `import 'https://esm.sh/${s}'`
|
|
13
|
+
);
|
|
14
|
+
}
|
|
15
|
+
async function w(t) {
|
|
16
|
+
const r = u({ logger: !1 });
|
|
17
|
+
r.register(l, {
|
|
18
|
+
origin: [
|
|
19
|
+
"https://luna-park.app",
|
|
20
|
+
/localhost:[0-9]+/,
|
|
21
|
+
/127\.0\.0\.1:[0-9]+/
|
|
22
|
+
]
|
|
23
|
+
}), r.addHook("onRequest", async (e, s) => {
|
|
24
|
+
const i = e.url === "/" ? "/index.js" : e.url;
|
|
25
|
+
let o = a(t.dist, i);
|
|
26
|
+
if (!n(o) && !p(e.url) && (o = a(t.dist, "index.js")), !n(o))
|
|
27
|
+
return;
|
|
28
|
+
if (p(o) === ".js") {
|
|
29
|
+
const f = d(o, "utf-8"), m = h(f, t.externals);
|
|
30
|
+
return s.type("application/javascript").send(m), s;
|
|
31
|
+
}
|
|
32
|
+
}), r.register(c, {
|
|
33
|
+
prefix: "/",
|
|
34
|
+
root: t.dist
|
|
35
|
+
}), await r.listen({ host: "127.0.0.1", port: t.port }), console.log(`Preview server started at http://127.0.0.1:${t.port}`);
|
|
36
|
+
}
|
|
37
|
+
export {
|
|
38
|
+
w as startPreviewServer
|
|
39
|
+
};
|
package/package.json
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@luna-park/plugin",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.5",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Plugin helper for Luna Park.",
|
|
6
6
|
"homepage": "https://luna-park.app",
|
|
7
|
+
"bin": {
|
|
8
|
+
"luna-preview": "./bin/preview.js"
|
|
9
|
+
},
|
|
7
10
|
"repository": {
|
|
8
11
|
"type": "git",
|
|
9
12
|
"url": "https://github.com/lunapark/lunapark"
|
|
@@ -31,27 +34,31 @@
|
|
|
31
34
|
"files": [
|
|
32
35
|
"dist/**"
|
|
33
36
|
],
|
|
34
|
-
"dependencies": {
|
|
35
|
-
"@fortawesome/fontawesome-svg-core": "^7.1.0",
|
|
36
|
-
"vite": "^7.2.2",
|
|
37
|
-
"vue": "^3.5.24"
|
|
38
|
-
},
|
|
39
37
|
"devDependencies": {
|
|
38
|
+
"@fastify/cors": "^11.1.0",
|
|
39
|
+
"@fastify/static": "^8.3.0",
|
|
40
|
+
"@fortawesome/fontawesome-svg-core": "^7.1.0",
|
|
40
41
|
"@luna-park/eslint-config": "^1.0.2",
|
|
41
42
|
"@microsoft/api-extractor": "^7.55.0",
|
|
42
|
-
"@vitest/ui": "^4.0.
|
|
43
|
+
"@vitest/ui": "^4.0.12",
|
|
43
44
|
"eslint": "^9.39.1",
|
|
44
|
-
"
|
|
45
|
+
"fastify": "^5.6.2",
|
|
46
|
+
"rimraf": "^6.1.2",
|
|
45
47
|
"typescript": "^5.9.3",
|
|
46
48
|
"typescript-eslint": "^8.47.0",
|
|
47
49
|
"unplugin-dts": "1.0.0-beta.6",
|
|
48
|
-
"
|
|
50
|
+
"vite": "^7.2.4",
|
|
51
|
+
"vitest": "^4.0.12",
|
|
52
|
+
"vue": "^3.5.24",
|
|
49
53
|
"@luna-park/logicnodes": "^2.0.0",
|
|
50
|
-
"@luna-park/
|
|
51
|
-
"@luna-park/
|
|
54
|
+
"@luna-park/shared": "^1.0.0",
|
|
55
|
+
"@luna-park/utils": "^2.0.0"
|
|
52
56
|
},
|
|
53
57
|
"peerDependencies": {
|
|
58
|
+
"@fastify/cors": "^11.1.0",
|
|
59
|
+
"@fastify/static": "^8.3.0",
|
|
54
60
|
"@fortawesome/fontawesome-svg-core": "^7.1.0",
|
|
61
|
+
"fastify": "^5.6.2",
|
|
55
62
|
"typescript": "^5.9.3",
|
|
56
63
|
"vite": "^7.2.1",
|
|
57
64
|
"vue": "^3.5.23"
|
|
@@ -60,6 +67,7 @@
|
|
|
60
67
|
"build": "rimraf dist && vite build",
|
|
61
68
|
"dev": "vite build --watch --minify=false",
|
|
62
69
|
"dev:test": "vitest --ui",
|
|
63
|
-
"test": "vitest"
|
|
70
|
+
"test": "vitest",
|
|
71
|
+
"test:preview": "node bin/preview.js"
|
|
64
72
|
}
|
|
65
73
|
}
|