@luna-park/plugin 1.0.3 → 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/README.md CHANGED
@@ -18,22 +18,19 @@ The primary way to define a plugin is using the `makePlugin` helper function. Th
18
18
  import { makePlugin, ELogicType } from "@luna-park/plugin";
19
19
  import awesomeIcon from "./awesome-icon.svg"; // Icon URL
20
20
 
21
- // Define your plugin's configuration schema (optional)
22
- const config = LogicType.object({
23
- apiKey: LogicType.string(),
24
- theme: LogicType.string({enum: ["light", "dark"], default: "dark"}),
25
- }) satisfies TSchema;
26
-
27
21
  export default makePlugin({
28
22
  id: "my-awesome-plugin",
29
23
  name: "My Awesome Plugin",
30
24
  icon: awesomeIcon, // Icon URL
31
25
  description: "Adds amazing capabilities to Luna Park.",
32
26
 
33
- // Plugin configuration schema
34
- config: ConfigSchema,
27
+ // Plugin configuration schema (optional)
28
+ config: LogicType.object({
29
+ apiKey: LogicType.string(),
30
+ theme: LogicType.string({enum: ["light", "dark"], default: "dark"}),
31
+ }),
35
32
 
36
- // Lifecycle hooks
33
+ // Lifecycle hooks (optional)
37
34
  lifecycle: {
38
35
  mount: async (env) => {
39
36
  console.log("Plugin mounted", env.config.apiKey);
@@ -48,7 +45,7 @@ export default makePlugin({
48
45
 
49
46
  // Extend the editor
50
47
  editor: {
51
- // Register custom Vue components for the editor
48
+ // Register custom Vue components for the editor (optional)
52
49
  components: [
53
50
  {
54
51
  name: "Element/Avatar",
@@ -63,7 +60,8 @@ export default makePlugin({
63
60
  }
64
61
  // ... component definitions
65
62
  ],
66
- // Register custom logic nodes
63
+
64
+ // Register custom logic nodes (optional)
67
65
  nodes: [
68
66
  makeLogicNode({
69
67
  name: "log/stuff",
@@ -86,10 +84,12 @@ export default makePlugin({
86
84
  })
87
85
  // ... node definitions
88
86
  ],
89
- wrapper : MyWrapperComponent, // Custom wrapper component for the editor
87
+
88
+ // Register wrapper for the editor (optional)
89
+ wrapper : MyWrapperComponent,
90
90
  },
91
91
 
92
- // Code injection options
92
+ // Code injection options (optional)
93
93
  inject: {
94
94
  css: "body { background-color: #000; }",
95
95
  js: "console.log('Hello world!')"
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
+ });
@@ -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;
@@ -0,0 +1,7 @@
1
+ export declare function startPreviewServer(config: {
2
+ dist: string;
3
+ externals: Array<string>;
4
+ port: number;
5
+ }): Promise<void>;
6
+
7
+ export { }
@@ -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,12 +1,15 @@
1
1
  {
2
2
  "name": "@luna-park/plugin",
3
- "version": "1.0.3",
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
- "url": "https://github.com/lunapark"
12
+ "url": "https://github.com/lunapark/lunapark"
10
13
  },
11
14
  "author": {
12
15
  "name": "Luna Park",
@@ -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.10",
43
+ "@vitest/ui": "^4.0.12",
43
44
  "eslint": "^9.39.1",
44
- "rimraf": "^6.1.0",
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
- "vitest": "^4.0.10",
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/utils": "^2.0.0",
51
- "@luna-park/shared": "^1.0.0"
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
  }