vite-plugin-prism-design 0.1.1 → 0.1.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/dist/index.js +17 -13
- package/package.json +10 -8
package/dist/index.js
CHANGED
|
@@ -1,17 +1,12 @@
|
|
|
1
|
-
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
2
|
-
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
3
|
-
}) : x)(function(x) {
|
|
4
|
-
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
5
|
-
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
6
|
-
});
|
|
7
|
-
|
|
8
1
|
// src/index.ts
|
|
9
2
|
import { spawn } from "child_process";
|
|
3
|
+
import { createRequire } from "module";
|
|
10
4
|
import path from "path";
|
|
11
5
|
import fs from "fs";
|
|
6
|
+
var require2 = createRequire(import.meta.url);
|
|
12
7
|
function findWidgetScript() {
|
|
13
8
|
try {
|
|
14
|
-
const widgetPkg =
|
|
9
|
+
const widgetPkg = require2.resolve("prism-design-widget/package.json");
|
|
15
10
|
const widgetDir = path.dirname(widgetPkg);
|
|
16
11
|
const iifeFile = path.join(widgetDir, "dist", "prism-design-widget.iife.js");
|
|
17
12
|
if (fs.existsSync(iifeFile)) return iifeFile;
|
|
@@ -116,8 +111,8 @@ function prismDesign(options = {}) {
|
|
|
116
111
|
agentProcess = null;
|
|
117
112
|
});
|
|
118
113
|
const actualPort = await portPromise;
|
|
119
|
-
agentUrl = `
|
|
120
|
-
config.logger.info(`[PrismDesign] Agent ready
|
|
114
|
+
agentUrl = `__AGENT_PORT__:${actualPort}`;
|
|
115
|
+
config.logger.info(`[PrismDesign] Agent ready on port ${actualPort}`);
|
|
121
116
|
} else {
|
|
122
117
|
config.logger.warn("[PrismDesign] Agent CLI not found. Install prism-design-agent or run agent manually.");
|
|
123
118
|
config.logger.info("[PrismDesign] Widget will show connection form for manual URL input.");
|
|
@@ -135,10 +130,19 @@ function prismDesign(options = {}) {
|
|
|
135
130
|
},
|
|
136
131
|
transformIndexHtml() {
|
|
137
132
|
const initOptions = {};
|
|
138
|
-
if (agentUrl) initOptions.agentUrl = agentUrl;
|
|
139
133
|
if (position !== "bottom-right") initOptions.position = position;
|
|
140
134
|
if (locale) initOptions.locale = locale;
|
|
141
|
-
|
|
135
|
+
let initScript;
|
|
136
|
+
if (agentUrl.startsWith("__AGENT_PORT__:")) {
|
|
137
|
+
const port = agentUrl.split(":")[1];
|
|
138
|
+
const optionsJson = JSON.stringify(initOptions);
|
|
139
|
+
initScript = `(function(){var o=${optionsJson};o.agentUrl="http://"+location.hostname+":${port}";PrismDesignWidget.init(o)})();`;
|
|
140
|
+
} else if (agentUrl) {
|
|
141
|
+
initOptions.agentUrl = agentUrl;
|
|
142
|
+
initScript = `PrismDesignWidget.init(${JSON.stringify(initOptions)});`;
|
|
143
|
+
} else {
|
|
144
|
+
initScript = `PrismDesignWidget.init(${JSON.stringify(initOptions)});`;
|
|
145
|
+
}
|
|
142
146
|
return [
|
|
143
147
|
{
|
|
144
148
|
tag: "script",
|
|
@@ -147,7 +151,7 @@ function prismDesign(options = {}) {
|
|
|
147
151
|
},
|
|
148
152
|
{
|
|
149
153
|
tag: "script",
|
|
150
|
-
children:
|
|
154
|
+
children: initScript,
|
|
151
155
|
injectTo: "body"
|
|
152
156
|
}
|
|
153
157
|
];
|
package/package.json
CHANGED
|
@@ -1,17 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vite-plugin-prism-design",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
8
|
-
"files": [
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
"dev": "tsup --watch"
|
|
12
|
-
},
|
|
8
|
+
"files": [
|
|
9
|
+
"dist"
|
|
10
|
+
],
|
|
13
11
|
"dependencies": {
|
|
14
|
-
"prism-design-widget": "
|
|
12
|
+
"prism-design-widget": "0.1.2"
|
|
15
13
|
},
|
|
16
14
|
"peerDependencies": {
|
|
17
15
|
"vite": ">=5.0.0"
|
|
@@ -20,5 +18,9 @@
|
|
|
20
18
|
"tsup": "^8.3.0",
|
|
21
19
|
"typescript": "^5.6.0",
|
|
22
20
|
"vite": "^6.0.0"
|
|
21
|
+
},
|
|
22
|
+
"scripts": {
|
|
23
|
+
"build": "tsup",
|
|
24
|
+
"dev": "tsup --watch"
|
|
23
25
|
}
|
|
24
|
-
}
|
|
26
|
+
}
|