-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdev-build.js
More file actions
327 lines (294 loc) · 8.42 KB
/
dev-build.js
File metadata and controls
327 lines (294 loc) · 8.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
import esbuild from "esbuild";
import fs from "fs";
import path from "path";
import { fileURLToPath } from "url";
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const devDistPath = path.join(__dirname, ".dev");
const assetsPath = path.join(devDistPath, "assets");
const packageJson = JSON.parse(fs.readFileSync(path.join(__dirname, "package.json"), "utf8"));
const nodePaths = [
path.join(__dirname, ".plugin-deps", "node_modules"),
path.join(__dirname, "node_modules"),
];
const appNodeModulesPath = path.join(__dirname, "node_modules");
const reactAliases = {
react: path.join(appNodeModulesPath, "react"),
"react/jsx-runtime": path.join(appNodeModulesPath, "react", "jsx-runtime.js"),
"react/jsx-dev-runtime": path.join(appNodeModulesPath, "react", "jsx-dev-runtime.js"),
"react-dom": path.join(appNodeModulesPath, "react-dom"),
"react-dom/client": path.join(appNodeModulesPath, "react-dom", "client.js"),
};
function ensureDir(dirPath) {
if (!fs.existsSync(dirPath)) {
fs.mkdirSync(dirPath, { recursive: true });
}
}
function writeFile(filePath, contents) {
ensureDir(path.dirname(filePath));
fs.writeFileSync(filePath, contents);
}
function cleanDevDist() {
if (fs.existsSync(devDistPath)) {
fs.rmSync(devDistPath, { recursive: true, force: true });
}
ensureDir(assetsPath);
}
function buildPluginFrameHtml() {
return `<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Plugin Preview</title>
<script>
const parentConfig = window.parent && window.parent !== window ? window.parent.__PLUGIN_DEV_CONFIG__ : null;
window.__PLUGIN_CONFIG__ = parentConfig || {
theme: "light",
language: "es",
fluxProxy: { targetOrigin: window.location.origin },
plugin: { installedPluginId: "dev-installed-plugin", pluginId: "dev-tasks-plugin", version: "0.1.0" }
};
</script>
<link rel="stylesheet" href="./assets/plugin.css" />
</head>
<body>
<div id="root"></div>
<script src="./assets/plugin.js"></script>
</body>
</html>`;
}
function buildHostHtml(pluginVersion) {
return `<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Flitware Plugin Dev Host</title>
<style>
:root {
color-scheme: light;
--host-bg: #f3f4f6;
--host-surface: #ffffff;
--host-surface-alt: #f9fafb;
--host-border: #d5dbdb;
--host-text: #111111;
--host-muted: #5f6b7a;
--host-accent: #000000;
}
:root[data-theme="dark"] {
color-scheme: dark;
--host-bg: #0b0b0c;
--host-surface: #141416;
--host-surface-alt: #1b1c20;
--host-border: #2a2c30;
--host-text: #f5f5f5;
--host-muted: #a3a3ad;
--host-accent: #ffffff;
}
* { box-sizing: border-box; }
body {
margin: 0;
font-family: Inter, system-ui, sans-serif;
background: var(--host-bg);
color: var(--host-text);
}
.dev-shell {
min-height: 100vh;
display: grid;
grid-template-rows: auto 1fr;
}
.dev-toolbar {
display: flex;
gap: 16px;
align-items: center;
justify-content: space-between;
padding: 16px 20px;
background: var(--host-surface);
border-bottom: 1px solid var(--host-border);
position: sticky;
top: 0;
z-index: 10;
}
.dev-title {
display: flex;
flex-direction: column;
gap: 4px;
}
.dev-title h1 {
margin: 0;
font-size: 20px;
}
.dev-title p {
margin: 0;
color: var(--host-muted);
font-size: 13px;
}
.dev-controls {
display: flex;
align-items: center;
gap: 12px;
flex-wrap: wrap;
justify-content: flex-end;
}
.dev-control {
display: flex;
flex-direction: column;
gap: 6px;
font-size: 12px;
color: var(--host-muted);
}
.dev-control select,
.dev-control button,
.dev-badge {
min-height: 36px;
border-radius: 10px;
border: 1px solid var(--host-border);
background: var(--host-surface-alt);
color: var(--host-text);
padding: 0 12px;
font: inherit;
}
.dev-control button {
cursor: pointer;
}
.dev-badge {
display: inline-flex;
align-items: center;
justify-content: center;
font-weight: 600;
color: var(--host-accent);
}
.dev-preview {
padding: 20px;
}
.dev-frame {
width: 100%;
height: calc(100vh - 108px);
border: 1px solid var(--host-border);
border-radius: 18px;
background: var(--host-surface);
}
@media (max-width: 900px) {
.dev-toolbar {
align-items: flex-start;
flex-direction: column;
}
.dev-controls {
width: 100%;
justify-content: flex-start;
}
.dev-frame {
height: calc(100vh - 180px);
}
}
</style>
<script>
window.__PLUGIN_DEV_BOOTSTRAP__ = {
runtime: {
theme: "light",
language: "es",
pluginVersion: ${JSON.stringify(pluginVersion)}
}
};
</script>
</head>
<body>
<div class="dev-shell">
<div class="dev-toolbar">
<div class="dev-title">
<h1>Flitware Plugin Dev Host</h1>
<p id="host-status">Inicializando host local...</p>
</div>
<div class="dev-controls">
<label class="dev-control">
Theme
<select id="theme-select">
<option value="light">Light</option>
<option value="dark">Dark</option>
</select>
</label>
<label class="dev-control">
Language
<select id="language-select">
<option value="es">Español</option>
<option value="en">English</option>
</select>
</label>
<span class="dev-control">
Plugin version
<span class="dev-badge" id="plugin-version"></span>
</span>
<span class="dev-control">
Actions
<span style="display:flex;gap:12px;">
<button id="reload-plugin" type="button">Reload plugin</button>
<button id="reset-mocks" type="button">Reset mocks</button>
</span>
</span>
</div>
</div>
<div class="dev-preview">
<iframe
id="plugin-preview"
class="dev-frame"
src="./plugin-frame.html"
title="Plugin preview"
></iframe>
</div>
</div>
<script src="./assets/host.js"></script>
</body>
</html>`;
}
async function buildDevArtifacts() {
cleanDevDist();
console.log("🔨 Compilando host local de desarrollo...");
await esbuild.build({
entryPoints: [path.join(__dirname, "index.tsx")],
bundle: true,
format: "iife",
jsx: "automatic",
target: ["es2020"],
outfile: path.join(assetsPath, "plugin.js"),
sourcemap: true,
minify: false,
treeShaking: true,
nodePaths,
alias: reactAliases,
loader: {
".css": "css",
".svg": "dataurl",
".png": "dataurl",
".jpg": "dataurl",
".jpeg": "dataurl",
".gif": "dataurl",
".webp": "dataurl",
".woff": "dataurl",
".woff2": "dataurl",
},
});
await esbuild.build({
entryPoints: [path.join(__dirname, "dev", "host.ts")],
bundle: true,
format: "iife",
target: ["es2020"],
outfile: path.join(assetsPath, "host.js"),
sourcemap: true,
minify: false,
treeShaking: true,
nodePaths,
alias: reactAliases,
});
const cssOutputPath = path.join(assetsPath, "plugin.css");
if (!fs.existsSync(cssOutputPath)) {
writeFile(cssOutputPath, "");
}
writeFile(path.join(devDistPath, "plugin-frame.html"), buildPluginFrameHtml());
writeFile(path.join(devDistPath, "index.html"), buildHostHtml(packageJson.version ?? "0.1.0"));
console.log("✅ Host local disponible en .dev/index.html");
}
buildDevArtifacts().catch((error) => {
console.error("❌ Error compilando el host local:", error);
process.exitCode = 1;
});