@rozenite/vite-plugin 1.0.0-alpha.0
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 +20 -0
- package/dist/client-plugin.d.ts +3 -0
- package/dist/client-plugin.d.ts.map +1 -0
- package/dist/index.cjs +282 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +281 -0
- package/dist/load-config.d.ts +9 -0
- package/dist/load-config.d.ts.map +1 -0
- package/dist/package-json.d.ts +7 -0
- package/dist/package-json.d.ts.map +1 -0
- package/dist/react-native-plugin.d.ts +3 -0
- package/dist/react-native-plugin.d.ts.map +1 -0
- package/dist/server-plugin.d.ts +3 -0
- package/dist/server-plugin.d.ts.map +1 -0
- package/dist/utils.d.ts +3 -0
- package/dist/utils.d.ts.map +1 -0
- package/package.json +57 -0
- package/templates/panel.ejs +42 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Szymon Chmal
|
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
6
|
+
in the Software without restriction, including without limitation the rights
|
|
7
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
9
|
+
furnished to do so, subject to the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be included in all
|
|
12
|
+
copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
20
|
+
SOFTWARE.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client-plugin.d.ts","sourceRoot":"","sources":["../src/client-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAiB,MAAM,MAAM,CAAC;AAyBlD,eAAO,MAAM,oBAAoB,QAAO,MA4KvC,CAAC"}
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const react = require("@vitejs/plugin-react");
|
|
4
|
+
const viteRequire = require("vite-require");
|
|
5
|
+
const reactNativeWeb = require("vite-plugin-react-native-web");
|
|
6
|
+
const process$1 = require("node:process");
|
|
7
|
+
const fs = require("node:fs");
|
|
8
|
+
const path = require("node:path");
|
|
9
|
+
const ejs = require("ejs");
|
|
10
|
+
const node_url = require("node:url");
|
|
11
|
+
const vite = require("vite");
|
|
12
|
+
const fs$1 = require("node:fs/promises");
|
|
13
|
+
const dtsPlugin = require("vite-plugin-dts");
|
|
14
|
+
var _documentCurrentScript = typeof document !== "undefined" ? document.currentScript : null;
|
|
15
|
+
const resolveFileWithExtensions = (directory, baseName) => {
|
|
16
|
+
const extensions = [".tsx", ".ts", ".jsx", ".js"];
|
|
17
|
+
for (const ext of extensions) {
|
|
18
|
+
const filePath = path.join(directory, baseName + ext);
|
|
19
|
+
if (fs.existsSync(filePath)) {
|
|
20
|
+
return filePath;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return null;
|
|
24
|
+
};
|
|
25
|
+
const rozeniteServerPlugin = () => {
|
|
26
|
+
return {
|
|
27
|
+
name: "rozenite-server-plugin",
|
|
28
|
+
config(config) {
|
|
29
|
+
var _a;
|
|
30
|
+
const projectRoot = config.root ?? process$1.cwd();
|
|
31
|
+
const backgroundFilePath = resolveFileWithExtensions(
|
|
32
|
+
projectRoot,
|
|
33
|
+
"background"
|
|
34
|
+
);
|
|
35
|
+
if (!backgroundFilePath) {
|
|
36
|
+
throw new Error("Background file not found");
|
|
37
|
+
}
|
|
38
|
+
config.build ?? (config.build = {});
|
|
39
|
+
(_a = config.build).rollupOptions ?? (_a.rollupOptions = {});
|
|
40
|
+
config.build.rollupOptions.input = backgroundFilePath;
|
|
41
|
+
config.build.ssr = true;
|
|
42
|
+
config.build.rollupOptions.output = {
|
|
43
|
+
format: "cjs"
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
const loadConfig = async (configPath) => {
|
|
49
|
+
const absoluteConfigPath = path.resolve(process.cwd(), configPath);
|
|
50
|
+
if (!fs.existsSync(absoluteConfigPath)) {
|
|
51
|
+
throw new Error(`Configuration file not found: ${absoluteConfigPath}`);
|
|
52
|
+
}
|
|
53
|
+
try {
|
|
54
|
+
const configContent = await fs.promises.readFile(
|
|
55
|
+
absoluteConfigPath,
|
|
56
|
+
"utf-8"
|
|
57
|
+
);
|
|
58
|
+
const result = await vite.transformWithEsbuild(
|
|
59
|
+
configContent,
|
|
60
|
+
absoluteConfigPath,
|
|
61
|
+
{
|
|
62
|
+
loader: "ts",
|
|
63
|
+
format: "cjs",
|
|
64
|
+
target: "esnext"
|
|
65
|
+
}
|
|
66
|
+
);
|
|
67
|
+
const moduleExports = {};
|
|
68
|
+
const module2 = { exports: moduleExports };
|
|
69
|
+
const exports2 = moduleExports;
|
|
70
|
+
const moduleFunction = new Function("module", "exports", result.code);
|
|
71
|
+
moduleFunction(module2, exports2);
|
|
72
|
+
const configModule = module2.exports;
|
|
73
|
+
const config = configModule.default || configModule;
|
|
74
|
+
if (!config || typeof config !== "object") {
|
|
75
|
+
throw new Error("Configuration must export an object");
|
|
76
|
+
}
|
|
77
|
+
return config;
|
|
78
|
+
} catch (error) {
|
|
79
|
+
if (error instanceof Error) {
|
|
80
|
+
throw new Error(
|
|
81
|
+
`Failed to load configuration from ${configPath}: ${error.message}`
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
throw new Error(`Failed to load configuration from ${configPath}`);
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
const getPackageJSON = async (projectRoot) => {
|
|
88
|
+
const packageJSONPath = path.join(projectRoot, "package.json");
|
|
89
|
+
const packageJSON = await fs$1.readFile(packageJSONPath, "utf8");
|
|
90
|
+
return JSON.parse(packageJSON);
|
|
91
|
+
};
|
|
92
|
+
const TEMPLATES_DIR = path.resolve(
|
|
93
|
+
node_url.fileURLToPath(typeof document === "undefined" ? require("url").pathToFileURL(__filename).href : _documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === "SCRIPT" && _documentCurrentScript.src || new URL("index.cjs", document.baseURI).href),
|
|
94
|
+
"..",
|
|
95
|
+
"..",
|
|
96
|
+
"templates"
|
|
97
|
+
);
|
|
98
|
+
const PANELS_DIR = "./panels";
|
|
99
|
+
const rozeniteClientPlugin = () => {
|
|
100
|
+
let projectRoot = process$1.cwd();
|
|
101
|
+
let viteServer = null;
|
|
102
|
+
let rozeniteConfig = null;
|
|
103
|
+
const getRozeniteConfig = () => {
|
|
104
|
+
if (!rozeniteConfig) {
|
|
105
|
+
throw new Error("rozenite.config.ts not found");
|
|
106
|
+
}
|
|
107
|
+
return rozeniteConfig;
|
|
108
|
+
};
|
|
109
|
+
const getPanels = () => {
|
|
110
|
+
return getRozeniteConfig().panels.map((entry) => {
|
|
111
|
+
const name = path.basename(entry.source, path.extname(entry.source));
|
|
112
|
+
return {
|
|
113
|
+
name,
|
|
114
|
+
label: entry.name,
|
|
115
|
+
sourceFile: path.resolve(projectRoot, entry.source),
|
|
116
|
+
htmlFile: name + ".html"
|
|
117
|
+
};
|
|
118
|
+
});
|
|
119
|
+
};
|
|
120
|
+
const PANEL_TEMPLATE = path.join(TEMPLATES_DIR, "panel.ejs");
|
|
121
|
+
const generatePanelHtmlContent = (panel) => {
|
|
122
|
+
const template = fs.readFileSync(PANEL_TEMPLATE, "utf-8");
|
|
123
|
+
const relativePath = path.relative(projectRoot, panel.sourceFile);
|
|
124
|
+
return ejs.render(template, {
|
|
125
|
+
panelName: panel.name,
|
|
126
|
+
panelFile: relativePath
|
|
127
|
+
});
|
|
128
|
+
};
|
|
129
|
+
return {
|
|
130
|
+
name: "rozenite-client-plugin",
|
|
131
|
+
async config(config) {
|
|
132
|
+
var _a;
|
|
133
|
+
if (config.root) {
|
|
134
|
+
projectRoot = config.root;
|
|
135
|
+
}
|
|
136
|
+
rozeniteConfig = await loadConfig(
|
|
137
|
+
path.resolve(projectRoot, "rozenite.config.ts")
|
|
138
|
+
);
|
|
139
|
+
const panels = getPanels();
|
|
140
|
+
config.server ?? (config.server = {});
|
|
141
|
+
config.server.open = false;
|
|
142
|
+
config.server.port = 8888;
|
|
143
|
+
config.build ?? (config.build = {});
|
|
144
|
+
(_a = config.build).rollupOptions ?? (_a.rollupOptions = {});
|
|
145
|
+
config.build.rollupOptions.input = {
|
|
146
|
+
...config.build.rollupOptions.input,
|
|
147
|
+
...Object.fromEntries(
|
|
148
|
+
panels.map((panel) => [panel.name, panel.htmlFile])
|
|
149
|
+
)
|
|
150
|
+
};
|
|
151
|
+
},
|
|
152
|
+
resolveId(id) {
|
|
153
|
+
const isPanel = getPanels().some((panel) => panel.htmlFile === id);
|
|
154
|
+
if (isPanel) {
|
|
155
|
+
return id;
|
|
156
|
+
}
|
|
157
|
+
return null;
|
|
158
|
+
},
|
|
159
|
+
load(id) {
|
|
160
|
+
const panel = getPanels().find((panel2) => panel2.htmlFile === id);
|
|
161
|
+
if (panel) {
|
|
162
|
+
return generatePanelHtmlContent(panel);
|
|
163
|
+
}
|
|
164
|
+
return null;
|
|
165
|
+
},
|
|
166
|
+
async configureServer(server) {
|
|
167
|
+
viteServer = server;
|
|
168
|
+
const packageJSON = await getPackageJSON(projectRoot);
|
|
169
|
+
server.middlewares.use((req, res, next) => {
|
|
170
|
+
res.setHeader("Access-Control-Allow-Origin", "*");
|
|
171
|
+
res.setHeader("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS");
|
|
172
|
+
res.setHeader("Access-Control-Allow-Headers", "Content-Type, Authorization");
|
|
173
|
+
if (req.method === "OPTIONS") {
|
|
174
|
+
res.statusCode = 200;
|
|
175
|
+
res.end();
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
const panels = getPanels();
|
|
179
|
+
const url = req.url || "/";
|
|
180
|
+
if (url === "/rozenite.json") {
|
|
181
|
+
res.setHeader("Content-Type", "application/json");
|
|
182
|
+
res.end(JSON.stringify({
|
|
183
|
+
name: packageJSON.name,
|
|
184
|
+
version: packageJSON.version,
|
|
185
|
+
description: packageJSON.description,
|
|
186
|
+
panels: panels.map((panel2) => ({
|
|
187
|
+
name: panel2.label,
|
|
188
|
+
source: panel2.htmlFile
|
|
189
|
+
}))
|
|
190
|
+
}, null, 2));
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
const panel = panels.find((panel2) => "/" + panel2.htmlFile === url);
|
|
194
|
+
if (panel) {
|
|
195
|
+
const htmlContent = generatePanelHtmlContent(panel);
|
|
196
|
+
server.transformIndexHtml(req.url || "/", htmlContent).then((html) => {
|
|
197
|
+
res.setHeader("Content-Type", "text/html");
|
|
198
|
+
res.end(html);
|
|
199
|
+
}).catch((err) => {
|
|
200
|
+
next(err);
|
|
201
|
+
});
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
next();
|
|
205
|
+
});
|
|
206
|
+
},
|
|
207
|
+
watchChange(id, change) {
|
|
208
|
+
if (change.event !== "create" && change.event !== "delete") {
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
const relativePath = path.relative(projectRoot, id);
|
|
212
|
+
if (!relativePath.startsWith(PANELS_DIR)) {
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
viteServer == null ? void 0 : viteServer.ws.send({
|
|
216
|
+
type: "full-reload",
|
|
217
|
+
path: "/"
|
|
218
|
+
});
|
|
219
|
+
},
|
|
220
|
+
async generateBundle() {
|
|
221
|
+
const panels = getPanels();
|
|
222
|
+
const packageJSON = await getPackageJSON(projectRoot);
|
|
223
|
+
this.emitFile({
|
|
224
|
+
type: "asset",
|
|
225
|
+
fileName: "rozenite.json",
|
|
226
|
+
source: JSON.stringify({
|
|
227
|
+
name: packageJSON.name,
|
|
228
|
+
version: packageJSON.version,
|
|
229
|
+
description: packageJSON.description,
|
|
230
|
+
panels: panels.map((panel) => ({
|
|
231
|
+
name: panel.label,
|
|
232
|
+
source: panel.htmlFile
|
|
233
|
+
}))
|
|
234
|
+
})
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
};
|
|
238
|
+
};
|
|
239
|
+
const rozeniteReactNativePlugin = () => {
|
|
240
|
+
return {
|
|
241
|
+
name: "rozenite-react-native-plugin",
|
|
242
|
+
config(config) {
|
|
243
|
+
var _a;
|
|
244
|
+
const projectRoot = config.root ?? process.cwd();
|
|
245
|
+
config.build ?? (config.build = {});
|
|
246
|
+
(_a = config.build).rollupOptions ?? (_a.rollupOptions = {});
|
|
247
|
+
config.build.lib = {
|
|
248
|
+
entry: path.resolve(projectRoot, "react-native.ts"),
|
|
249
|
+
formats: ["es", "cjs"],
|
|
250
|
+
fileName: (format) => `react-native.${format === "es" ? "js" : "cjs"}`
|
|
251
|
+
};
|
|
252
|
+
config.build.rollupOptions.external = (id) => {
|
|
253
|
+
if (id.startsWith("node:")) {
|
|
254
|
+
return true;
|
|
255
|
+
}
|
|
256
|
+
return !id.startsWith(".") && !path.isAbsolute(id);
|
|
257
|
+
};
|
|
258
|
+
delete config.build.rollupOptions.input;
|
|
259
|
+
}
|
|
260
|
+
};
|
|
261
|
+
};
|
|
262
|
+
const rozenitePlugin = () => {
|
|
263
|
+
const isServer = process.env.VITE_ROZENITE_TARGET === "server";
|
|
264
|
+
const isReactNative = process.env.VITE_ROZENITE_TARGET === "react-native";
|
|
265
|
+
if (isServer) {
|
|
266
|
+
return [rozeniteServerPlugin()];
|
|
267
|
+
} else if (isReactNative) {
|
|
268
|
+
return [
|
|
269
|
+
react(),
|
|
270
|
+
viteRequire.viteRequire(),
|
|
271
|
+
rozeniteReactNativePlugin(),
|
|
272
|
+
dtsPlugin({ rollupTypes: true })
|
|
273
|
+
];
|
|
274
|
+
}
|
|
275
|
+
return [
|
|
276
|
+
react(),
|
|
277
|
+
// @ts-expect-error: TypeScript gets confused by the dual export
|
|
278
|
+
reactNativeWeb(),
|
|
279
|
+
rozeniteClientPlugin()
|
|
280
|
+
];
|
|
281
|
+
};
|
|
282
|
+
exports.rozenitePlugin = rozenitePlugin;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,MAAM,CAAC;AASzC,eAAO,MAAM,cAAc,QAAO,YAAY,EAqB7C,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
import react from "@vitejs/plugin-react";
|
|
2
|
+
import { viteRequire } from "vite-require";
|
|
3
|
+
import reactNativeWeb from "vite-plugin-react-native-web";
|
|
4
|
+
import process$1 from "node:process";
|
|
5
|
+
import fs from "node:fs";
|
|
6
|
+
import path from "node:path";
|
|
7
|
+
import ejs from "ejs";
|
|
8
|
+
import { fileURLToPath } from "node:url";
|
|
9
|
+
import { transformWithEsbuild } from "vite";
|
|
10
|
+
import fs$1 from "node:fs/promises";
|
|
11
|
+
import dtsPlugin from "vite-plugin-dts";
|
|
12
|
+
const resolveFileWithExtensions = (directory, baseName) => {
|
|
13
|
+
const extensions = [".tsx", ".ts", ".jsx", ".js"];
|
|
14
|
+
for (const ext of extensions) {
|
|
15
|
+
const filePath = path.join(directory, baseName + ext);
|
|
16
|
+
if (fs.existsSync(filePath)) {
|
|
17
|
+
return filePath;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return null;
|
|
21
|
+
};
|
|
22
|
+
const rozeniteServerPlugin = () => {
|
|
23
|
+
return {
|
|
24
|
+
name: "rozenite-server-plugin",
|
|
25
|
+
config(config) {
|
|
26
|
+
var _a;
|
|
27
|
+
const projectRoot = config.root ?? process$1.cwd();
|
|
28
|
+
const backgroundFilePath = resolveFileWithExtensions(
|
|
29
|
+
projectRoot,
|
|
30
|
+
"background"
|
|
31
|
+
);
|
|
32
|
+
if (!backgroundFilePath) {
|
|
33
|
+
throw new Error("Background file not found");
|
|
34
|
+
}
|
|
35
|
+
config.build ?? (config.build = {});
|
|
36
|
+
(_a = config.build).rollupOptions ?? (_a.rollupOptions = {});
|
|
37
|
+
config.build.rollupOptions.input = backgroundFilePath;
|
|
38
|
+
config.build.ssr = true;
|
|
39
|
+
config.build.rollupOptions.output = {
|
|
40
|
+
format: "cjs"
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
const loadConfig = async (configPath) => {
|
|
46
|
+
const absoluteConfigPath = path.resolve(process.cwd(), configPath);
|
|
47
|
+
if (!fs.existsSync(absoluteConfigPath)) {
|
|
48
|
+
throw new Error(`Configuration file not found: ${absoluteConfigPath}`);
|
|
49
|
+
}
|
|
50
|
+
try {
|
|
51
|
+
const configContent = await fs.promises.readFile(
|
|
52
|
+
absoluteConfigPath,
|
|
53
|
+
"utf-8"
|
|
54
|
+
);
|
|
55
|
+
const result = await transformWithEsbuild(
|
|
56
|
+
configContent,
|
|
57
|
+
absoluteConfigPath,
|
|
58
|
+
{
|
|
59
|
+
loader: "ts",
|
|
60
|
+
format: "cjs",
|
|
61
|
+
target: "esnext"
|
|
62
|
+
}
|
|
63
|
+
);
|
|
64
|
+
const moduleExports = {};
|
|
65
|
+
const module = { exports: moduleExports };
|
|
66
|
+
const exports = moduleExports;
|
|
67
|
+
const moduleFunction = new Function("module", "exports", result.code);
|
|
68
|
+
moduleFunction(module, exports);
|
|
69
|
+
const configModule = module.exports;
|
|
70
|
+
const config = configModule.default || configModule;
|
|
71
|
+
if (!config || typeof config !== "object") {
|
|
72
|
+
throw new Error("Configuration must export an object");
|
|
73
|
+
}
|
|
74
|
+
return config;
|
|
75
|
+
} catch (error) {
|
|
76
|
+
if (error instanceof Error) {
|
|
77
|
+
throw new Error(
|
|
78
|
+
`Failed to load configuration from ${configPath}: ${error.message}`
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
throw new Error(`Failed to load configuration from ${configPath}`);
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
const getPackageJSON = async (projectRoot) => {
|
|
85
|
+
const packageJSONPath = path.join(projectRoot, "package.json");
|
|
86
|
+
const packageJSON = await fs$1.readFile(packageJSONPath, "utf8");
|
|
87
|
+
return JSON.parse(packageJSON);
|
|
88
|
+
};
|
|
89
|
+
const TEMPLATES_DIR = path.resolve(
|
|
90
|
+
fileURLToPath(import.meta.url),
|
|
91
|
+
"..",
|
|
92
|
+
"..",
|
|
93
|
+
"templates"
|
|
94
|
+
);
|
|
95
|
+
const PANELS_DIR = "./panels";
|
|
96
|
+
const rozeniteClientPlugin = () => {
|
|
97
|
+
let projectRoot = process$1.cwd();
|
|
98
|
+
let viteServer = null;
|
|
99
|
+
let rozeniteConfig = null;
|
|
100
|
+
const getRozeniteConfig = () => {
|
|
101
|
+
if (!rozeniteConfig) {
|
|
102
|
+
throw new Error("rozenite.config.ts not found");
|
|
103
|
+
}
|
|
104
|
+
return rozeniteConfig;
|
|
105
|
+
};
|
|
106
|
+
const getPanels = () => {
|
|
107
|
+
return getRozeniteConfig().panels.map((entry) => {
|
|
108
|
+
const name = path.basename(entry.source, path.extname(entry.source));
|
|
109
|
+
return {
|
|
110
|
+
name,
|
|
111
|
+
label: entry.name,
|
|
112
|
+
sourceFile: path.resolve(projectRoot, entry.source),
|
|
113
|
+
htmlFile: name + ".html"
|
|
114
|
+
};
|
|
115
|
+
});
|
|
116
|
+
};
|
|
117
|
+
const PANEL_TEMPLATE = path.join(TEMPLATES_DIR, "panel.ejs");
|
|
118
|
+
const generatePanelHtmlContent = (panel) => {
|
|
119
|
+
const template = fs.readFileSync(PANEL_TEMPLATE, "utf-8");
|
|
120
|
+
const relativePath = path.relative(projectRoot, panel.sourceFile);
|
|
121
|
+
return ejs.render(template, {
|
|
122
|
+
panelName: panel.name,
|
|
123
|
+
panelFile: relativePath
|
|
124
|
+
});
|
|
125
|
+
};
|
|
126
|
+
return {
|
|
127
|
+
name: "rozenite-client-plugin",
|
|
128
|
+
async config(config) {
|
|
129
|
+
var _a;
|
|
130
|
+
if (config.root) {
|
|
131
|
+
projectRoot = config.root;
|
|
132
|
+
}
|
|
133
|
+
rozeniteConfig = await loadConfig(
|
|
134
|
+
path.resolve(projectRoot, "rozenite.config.ts")
|
|
135
|
+
);
|
|
136
|
+
const panels = getPanels();
|
|
137
|
+
config.server ?? (config.server = {});
|
|
138
|
+
config.server.open = false;
|
|
139
|
+
config.server.port = 8888;
|
|
140
|
+
config.build ?? (config.build = {});
|
|
141
|
+
(_a = config.build).rollupOptions ?? (_a.rollupOptions = {});
|
|
142
|
+
config.build.rollupOptions.input = {
|
|
143
|
+
...config.build.rollupOptions.input,
|
|
144
|
+
...Object.fromEntries(
|
|
145
|
+
panels.map((panel) => [panel.name, panel.htmlFile])
|
|
146
|
+
)
|
|
147
|
+
};
|
|
148
|
+
},
|
|
149
|
+
resolveId(id) {
|
|
150
|
+
const isPanel = getPanels().some((panel) => panel.htmlFile === id);
|
|
151
|
+
if (isPanel) {
|
|
152
|
+
return id;
|
|
153
|
+
}
|
|
154
|
+
return null;
|
|
155
|
+
},
|
|
156
|
+
load(id) {
|
|
157
|
+
const panel = getPanels().find((panel2) => panel2.htmlFile === id);
|
|
158
|
+
if (panel) {
|
|
159
|
+
return generatePanelHtmlContent(panel);
|
|
160
|
+
}
|
|
161
|
+
return null;
|
|
162
|
+
},
|
|
163
|
+
async configureServer(server) {
|
|
164
|
+
viteServer = server;
|
|
165
|
+
const packageJSON = await getPackageJSON(projectRoot);
|
|
166
|
+
server.middlewares.use((req, res, next) => {
|
|
167
|
+
res.setHeader("Access-Control-Allow-Origin", "*");
|
|
168
|
+
res.setHeader("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS");
|
|
169
|
+
res.setHeader("Access-Control-Allow-Headers", "Content-Type, Authorization");
|
|
170
|
+
if (req.method === "OPTIONS") {
|
|
171
|
+
res.statusCode = 200;
|
|
172
|
+
res.end();
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
const panels = getPanels();
|
|
176
|
+
const url = req.url || "/";
|
|
177
|
+
if (url === "/rozenite.json") {
|
|
178
|
+
res.setHeader("Content-Type", "application/json");
|
|
179
|
+
res.end(JSON.stringify({
|
|
180
|
+
name: packageJSON.name,
|
|
181
|
+
version: packageJSON.version,
|
|
182
|
+
description: packageJSON.description,
|
|
183
|
+
panels: panels.map((panel2) => ({
|
|
184
|
+
name: panel2.label,
|
|
185
|
+
source: panel2.htmlFile
|
|
186
|
+
}))
|
|
187
|
+
}, null, 2));
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
const panel = panels.find((panel2) => "/" + panel2.htmlFile === url);
|
|
191
|
+
if (panel) {
|
|
192
|
+
const htmlContent = generatePanelHtmlContent(panel);
|
|
193
|
+
server.transformIndexHtml(req.url || "/", htmlContent).then((html) => {
|
|
194
|
+
res.setHeader("Content-Type", "text/html");
|
|
195
|
+
res.end(html);
|
|
196
|
+
}).catch((err) => {
|
|
197
|
+
next(err);
|
|
198
|
+
});
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
next();
|
|
202
|
+
});
|
|
203
|
+
},
|
|
204
|
+
watchChange(id, change) {
|
|
205
|
+
if (change.event !== "create" && change.event !== "delete") {
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
const relativePath = path.relative(projectRoot, id);
|
|
209
|
+
if (!relativePath.startsWith(PANELS_DIR)) {
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
viteServer == null ? void 0 : viteServer.ws.send({
|
|
213
|
+
type: "full-reload",
|
|
214
|
+
path: "/"
|
|
215
|
+
});
|
|
216
|
+
},
|
|
217
|
+
async generateBundle() {
|
|
218
|
+
const panels = getPanels();
|
|
219
|
+
const packageJSON = await getPackageJSON(projectRoot);
|
|
220
|
+
this.emitFile({
|
|
221
|
+
type: "asset",
|
|
222
|
+
fileName: "rozenite.json",
|
|
223
|
+
source: JSON.stringify({
|
|
224
|
+
name: packageJSON.name,
|
|
225
|
+
version: packageJSON.version,
|
|
226
|
+
description: packageJSON.description,
|
|
227
|
+
panels: panels.map((panel) => ({
|
|
228
|
+
name: panel.label,
|
|
229
|
+
source: panel.htmlFile
|
|
230
|
+
}))
|
|
231
|
+
})
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
};
|
|
235
|
+
};
|
|
236
|
+
const rozeniteReactNativePlugin = () => {
|
|
237
|
+
return {
|
|
238
|
+
name: "rozenite-react-native-plugin",
|
|
239
|
+
config(config) {
|
|
240
|
+
var _a;
|
|
241
|
+
const projectRoot = config.root ?? process.cwd();
|
|
242
|
+
config.build ?? (config.build = {});
|
|
243
|
+
(_a = config.build).rollupOptions ?? (_a.rollupOptions = {});
|
|
244
|
+
config.build.lib = {
|
|
245
|
+
entry: path.resolve(projectRoot, "react-native.ts"),
|
|
246
|
+
formats: ["es", "cjs"],
|
|
247
|
+
fileName: (format) => `react-native.${format === "es" ? "js" : "cjs"}`
|
|
248
|
+
};
|
|
249
|
+
config.build.rollupOptions.external = (id) => {
|
|
250
|
+
if (id.startsWith("node:")) {
|
|
251
|
+
return true;
|
|
252
|
+
}
|
|
253
|
+
return !id.startsWith(".") && !path.isAbsolute(id);
|
|
254
|
+
};
|
|
255
|
+
delete config.build.rollupOptions.input;
|
|
256
|
+
}
|
|
257
|
+
};
|
|
258
|
+
};
|
|
259
|
+
const rozenitePlugin = () => {
|
|
260
|
+
const isServer = process.env.VITE_ROZENITE_TARGET === "server";
|
|
261
|
+
const isReactNative = process.env.VITE_ROZENITE_TARGET === "react-native";
|
|
262
|
+
if (isServer) {
|
|
263
|
+
return [rozeniteServerPlugin()];
|
|
264
|
+
} else if (isReactNative) {
|
|
265
|
+
return [
|
|
266
|
+
react(),
|
|
267
|
+
viteRequire(),
|
|
268
|
+
rozeniteReactNativePlugin(),
|
|
269
|
+
dtsPlugin({ rollupTypes: true })
|
|
270
|
+
];
|
|
271
|
+
}
|
|
272
|
+
return [
|
|
273
|
+
react(),
|
|
274
|
+
// @ts-expect-error: TypeScript gets confused by the dual export
|
|
275
|
+
reactNativeWeb(),
|
|
276
|
+
rozeniteClientPlugin()
|
|
277
|
+
];
|
|
278
|
+
};
|
|
279
|
+
export {
|
|
280
|
+
rozenitePlugin
|
|
281
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"load-config.d.ts","sourceRoot":"","sources":["../src/load-config.ts"],"names":[],"mappings":"AAIA,MAAM,MAAM,UAAU,GAAG;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG;IAC3B,MAAM,EAAE,UAAU,EAAE,CAAC;CACtB,CAAC;AAEF,eAAO,MAAM,UAAU,GACrB,YAAY,MAAM,KACjB,OAAO,CAAC,cAAc,CA8CxB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"package-json.d.ts","sourceRoot":"","sources":["../src/package-json.ts"],"names":[],"mappings":"AAGA,MAAM,MAAM,WAAW,GAAG;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,eAAO,MAAM,cAAc,GAAU,aAAa,MAAM,KAAG,OAAO,CAAC,WAAW,CAI7E,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"react-native-plugin.d.ts","sourceRoot":"","sources":["../src/react-native-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAG9B,eAAO,MAAM,yBAAyB,QAAO,MA0B5C,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server-plugin.d.ts","sourceRoot":"","sources":["../src/server-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAInC,eAAO,MAAM,oBAAoB,QAAO,MAwBvC,CAAC"}
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,yBAAyB,GACpC,WAAW,MAAM,EACjB,UAAU,MAAM,KACf,MAAM,GAAG,IAYX,CAAC;AAEF,eAAO,MAAM,IAAI,GAAI,CAAC,EAAE,IAAI,MAAM,CAAC,KAAG,CAAC,MAAM,CAAC,CAU7C,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@rozenite/vite-plugin",
|
|
3
|
+
"version": "1.0.0-alpha.0",
|
|
4
|
+
"description": "Vite plugin for developing React Native DevTools plugins with hot reload and development tools",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.cjs",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"files": [
|
|
10
|
+
"dist",
|
|
11
|
+
"templates"
|
|
12
|
+
],
|
|
13
|
+
"keywords": [
|
|
14
|
+
"react-native",
|
|
15
|
+
"devtools",
|
|
16
|
+
"vite",
|
|
17
|
+
"plugin"
|
|
18
|
+
],
|
|
19
|
+
"homepage": "https://github.com/callstackincubator/rozenite#readme",
|
|
20
|
+
"bugs": {
|
|
21
|
+
"url": "https://github.com/callstackincubator/rozenite/issues"
|
|
22
|
+
},
|
|
23
|
+
"repository": {
|
|
24
|
+
"type": "git",
|
|
25
|
+
"url": "https://github.com/callstackincubator/rozenite.git"
|
|
26
|
+
},
|
|
27
|
+
"author": "Szymon Chmal <szymon.chmal@callstack.com>",
|
|
28
|
+
"license": "MIT",
|
|
29
|
+
"exports": {
|
|
30
|
+
"./package.json": "./package.json",
|
|
31
|
+
".": {
|
|
32
|
+
"development": "./src/index.ts",
|
|
33
|
+
"types": "./dist/index.d.ts",
|
|
34
|
+
"import": "./dist/index.js",
|
|
35
|
+
"default": "./dist/index.cjs"
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"@vitejs/plugin-react": "^4.3.4",
|
|
40
|
+
"ejs": "^3.1.9",
|
|
41
|
+
"vite-plugin-dts": "~4.5.0",
|
|
42
|
+
"vite-plugin-react-native-web": "^2.1.1",
|
|
43
|
+
"vite-require": "^0.2.3"
|
|
44
|
+
},
|
|
45
|
+
"peerDependencies": {
|
|
46
|
+
"vite": "^6.0.0"
|
|
47
|
+
},
|
|
48
|
+
"devDependencies": {
|
|
49
|
+
"@types/ejs": "^3.1.5"
|
|
50
|
+
},
|
|
51
|
+
"engines": {
|
|
52
|
+
"node": ">=22"
|
|
53
|
+
},
|
|
54
|
+
"scripts": {
|
|
55
|
+
"build": "vite build"
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8" />
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
6
|
+
<title><%= panelName %> Panel</title>
|
|
7
|
+
<style>
|
|
8
|
+
html,
|
|
9
|
+
body {
|
|
10
|
+
height: 100%;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
body {
|
|
14
|
+
overflow: hidden;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
#root {
|
|
18
|
+
display: flex;
|
|
19
|
+
height: 100%;
|
|
20
|
+
}
|
|
21
|
+
</style>
|
|
22
|
+
<script>
|
|
23
|
+
var __ROZENITE_PANEL__ = true;
|
|
24
|
+
</script>
|
|
25
|
+
</head>
|
|
26
|
+
<body>
|
|
27
|
+
<div id="root"></div>
|
|
28
|
+
<script type="module">
|
|
29
|
+
import { AppRegistry } from 'react-native';
|
|
30
|
+
import PanelComponent from '/<%= panelFile %>';
|
|
31
|
+
|
|
32
|
+
const panelName = '<%= panelName %>';
|
|
33
|
+
|
|
34
|
+
AppRegistry.registerComponent(panelName, () => PanelComponent);
|
|
35
|
+
|
|
36
|
+
AppRegistry.runApplication(panelName, {
|
|
37
|
+
initialProps: {},
|
|
38
|
+
rootTag: document.getElementById('root'),
|
|
39
|
+
});
|
|
40
|
+
</script>
|
|
41
|
+
</body>
|
|
42
|
+
</html>
|