vaderjs 1.4.1-lv56aadeg5 → 1.4.2-bml56
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/.editorconfig +11 -0
- package/.vscode/c_cpp_properties.json +21 -0
- package/.vscode/settings.json +12 -0
- package/README.md +35 -198
- package/binaries/Kalix/index.js +668 -0
- package/binaries/compiler/main.js +461 -0
- package/binaries/vader.js +74 -0
- package/binaries/watcher/hmr.js +40 -0
- package/client/index.d.ts +226 -0
- package/client/runtime/index.js +417 -0
- package/client/runtime/router.js +235 -0
- package/config/index.ts +68 -0
- package/index.ts +344 -0
- package/package.json +14 -25
- package/plugins/cloudflare/functions/index.js +98 -0
- package/plugins/cloudflare/toCopy/@server/Kalix/index.js +625 -0
- package/plugins/cloudflare/toCopy/@server/cloudflare_ssr/index.js +85 -0
- package/plugins/cloudflare/toCopy/node_modules/vaderjs/server/index.js +99 -0
- package/plugins/cloudflare/toCopy/src/client.js +432 -0
- package/plugins/cloudflare/toCopy/src/router.js +235 -0
- package/plugins/ssg/index.js +127 -0
- package/plugins/vercel/functions/index.ts +8 -0
- package/router/index.ts +181 -0
- package/server/index.js +129 -0
- package/vader_dev.js +177 -0
- package/@integrations/ssg.js +0 -163
- package/LICENSE +0 -21
- package/binaries/IPC/index.js +0 -277
- package/binaries/main.js +0 -1328
- package/binaries/readme.md +0 -4
- package/binaries/watcher.js +0 -74
- package/binaries/win32/check.ps1 +0 -7
- package/client/index.js +0 -441
- package/config/index.js +0 -36
- package/logo.png +0 -0
- package/runtime/router.js +0 -1
- package/runtime/vader.js +0 -1
- package/vader.js +0 -230
package/binaries/main.js
DELETED
|
@@ -1,1328 +0,0 @@
|
|
|
1
|
-
import { Glob } from "bun";
|
|
2
|
-
|
|
3
|
-
import fs from "fs";
|
|
4
|
-
|
|
5
|
-
import * as Bun from "bun";
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
let config = await import(process.cwd() + "/vader.config.js")
|
|
9
|
-
.then((m) => (m ? m.default : {}))
|
|
10
|
-
.catch((e) => {
|
|
11
|
-
return {};
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
async function checkIFUptodate() {
|
|
15
|
-
let lts = await fetch("https://registry.npmjs.org/vaderjs").then((res) =>
|
|
16
|
-
res.json()
|
|
17
|
-
);
|
|
18
|
-
let latest = lts["dist-tags"].latest;
|
|
19
|
-
let current = JSON.parse(
|
|
20
|
-
fs.readFileSync(process.cwd() + "/node_modules/vaderjs/package.json")
|
|
21
|
-
).version;
|
|
22
|
-
return {
|
|
23
|
-
latest,
|
|
24
|
-
current,
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
import IPCServer from "vaderjs/binaries/IPC/index.js";
|
|
29
|
-
|
|
30
|
-
const IPC = IPCServer;
|
|
31
|
-
|
|
32
|
-
globalThis.isVader = true;
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
|
|
36
|
-
* @description - Call functions when the integration is triggered
|
|
37
|
-
|
|
38
|
-
* @param {function} fn
|
|
39
|
-
|
|
40
|
-
* @param {args} args
|
|
41
|
-
|
|
42
|
-
*/
|
|
43
|
-
|
|
44
|
-
globalThis.call = async (fn, args) => {
|
|
45
|
-
return (await fn(args)) || void 0;
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
/**@description - Used to store hmr websocket clients */
|
|
49
|
-
|
|
50
|
-
globalThis.clients = [];
|
|
51
|
-
|
|
52
|
-
/**@description - Used to keep track of routes */
|
|
53
|
-
|
|
54
|
-
globalThis.routes = [];
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
|
|
58
|
-
* @description - Used to keep track of the mode
|
|
59
|
-
|
|
60
|
-
*/
|
|
61
|
-
|
|
62
|
-
globalThis.mode = "";
|
|
63
|
-
|
|
64
|
-
/**@usedby @transForm */
|
|
65
|
-
|
|
66
|
-
globalThis.isBuilding = false;
|
|
67
|
-
|
|
68
|
-
globalThis.hasGenerated = [];
|
|
69
|
-
|
|
70
|
-
let currentState = "";
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
|
|
74
|
-
* @description - Used to keep track of the bundle size
|
|
75
|
-
|
|
76
|
-
*/
|
|
77
|
-
|
|
78
|
-
let bundleSize = 0;
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
|
|
82
|
-
* @description - variables used to generate arrays of paths recursively
|
|
83
|
-
|
|
84
|
-
*/
|
|
85
|
-
|
|
86
|
-
const glob = new Glob("/pages/**/**/*.{,tsx,js,jsx,md}", {
|
|
87
|
-
absolute: true,
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
const vaderGlob = new Glob("/node_modules/vaderjs/runtime/**/**/*.{,tsx,js}", {
|
|
91
|
-
absolute: true,
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
const srcGlob = new Glob("/src/**/**/*.{jsx,ts,tsx,js}", {
|
|
95
|
-
absolute: true,
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
const publicGlob = new Glob(
|
|
99
|
-
"/public/**/**/*.{css,js,html,jpg,png,gif,svg,ico,video,webm,mp4,jpeg}",
|
|
100
|
-
{
|
|
101
|
-
absolute: true,
|
|
102
|
-
}
|
|
103
|
-
);
|
|
104
|
-
|
|
105
|
-
const distPages = new Glob("/dist/pages/**/**/*.{tsx,js,jsx}", {
|
|
106
|
-
absolute: true,
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
const distSrc = new Glob("/dist/src/**/**/*.{tsx,js,jsx}", {
|
|
110
|
-
absolute: true,
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
const distPublic = new Glob(
|
|
114
|
-
"/dist/public/**/**/*.{css,js,html,jpg,png,gif,svg,ico,video,webm,mp4,jpeg}",
|
|
115
|
-
{
|
|
116
|
-
absolute: true,
|
|
117
|
-
}
|
|
118
|
-
);
|
|
119
|
-
|
|
120
|
-
const router = new Bun.FileSystemRouter({
|
|
121
|
-
style: "nextjs",
|
|
122
|
-
|
|
123
|
-
dir: process.cwd() + "/pages",
|
|
124
|
-
|
|
125
|
-
origin: process.env.ORIGIN || "http://localhost:3000",
|
|
126
|
-
|
|
127
|
-
assetPrefix: "_next/static/",
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
/**
|
|
131
|
-
|
|
132
|
-
* @function handleReplaceMents
|
|
133
|
-
|
|
134
|
-
* @description - replaces data to be compatible with Vader.js
|
|
135
|
-
|
|
136
|
-
* @param {*} data
|
|
137
|
-
|
|
138
|
-
* @returns
|
|
139
|
-
|
|
140
|
-
*/
|
|
141
|
-
const cssToObj = (css) => {
|
|
142
|
-
let styles = {};
|
|
143
|
-
let currentSelector = "";
|
|
144
|
-
|
|
145
|
-
css.split("\n").forEach((line) => {
|
|
146
|
-
line = line.trim();
|
|
147
|
-
|
|
148
|
-
if (line.endsWith("{")) {
|
|
149
|
-
// Start of a block, extract the selector
|
|
150
|
-
currentSelector = line.slice(0, -1).trim();
|
|
151
|
-
currentSelector = currentSelector.replace(/-./g, (x) => x[1].toUpperCase());
|
|
152
|
-
currentSelector =currentSelector.replace('.', '')
|
|
153
|
-
styles[currentSelector] = {};
|
|
154
|
-
} else if (line.endsWith("}")) {
|
|
155
|
-
// End of a block
|
|
156
|
-
currentSelector = "";
|
|
157
|
-
} else if (line.includes(":") && currentSelector) {
|
|
158
|
-
// Inside a block and contains key-value pair
|
|
159
|
-
let [key, value] = line.split(":").map((part) => part.trim());
|
|
160
|
-
key = key.replace(/-./g, (x) => x[1].toUpperCase());
|
|
161
|
-
styles[currentSelector][key] = value;
|
|
162
|
-
}
|
|
163
|
-
});
|
|
164
|
-
|
|
165
|
-
return styles;
|
|
166
|
-
};
|
|
167
|
-
|
|
168
|
-
function handleReplaceMents(data) {
|
|
169
|
-
data.split("\n").forEach(async (line, index) => {
|
|
170
|
-
switch (true) {
|
|
171
|
-
case line.includes("import") && line.includes("module.css"):
|
|
172
|
-
let path = line.split("from")[1].trim().split(";")[0].trim();
|
|
173
|
-
let name = line.split("import")[1].split("from")[0].trim();
|
|
174
|
-
path = path.replace(";", "");
|
|
175
|
-
path = path.replace(/'/g, "").trim().replace(/"/g, "").trim();
|
|
176
|
-
path = path.replaceAll(".jsx", ".js");
|
|
177
|
-
path = path.replaceAll("../", "");
|
|
178
|
-
let css = fs.readFileSync(process.cwd() + "/" + path, "utf8");
|
|
179
|
-
let styles = cssToObj(css);
|
|
180
|
-
let style = JSON.stringify(styles);
|
|
181
|
-
let newLine = `let ${name} = ${style}`;
|
|
182
|
-
data = data.replace(line, newLine);
|
|
183
|
-
|
|
184
|
-
break;
|
|
185
|
-
|
|
186
|
-
case line.includes("useReducer") && !line.includes("import"):
|
|
187
|
-
line = line.replaceAll(/\s+/g, " ");
|
|
188
|
-
|
|
189
|
-
let varTypereducer = line.split("=")[0].trim().split("[")[0].trim();
|
|
190
|
-
|
|
191
|
-
let keyreducer = line
|
|
192
|
-
.split("=")[0]
|
|
193
|
-
.trim()
|
|
194
|
-
.split("[")[1]
|
|
195
|
-
.trim()
|
|
196
|
-
.split(",")[0]
|
|
197
|
-
.trim();
|
|
198
|
-
|
|
199
|
-
let setKeyreducer = line
|
|
200
|
-
.split("=")[0]
|
|
201
|
-
.trim()
|
|
202
|
-
.split(",")[1]
|
|
203
|
-
.trim()
|
|
204
|
-
.replace("]", "");
|
|
205
|
-
|
|
206
|
-
let reducer = line.split("=")[1].split("useReducer(")[1];
|
|
207
|
-
|
|
208
|
-
let newStatereducer = `${varTypereducer} [${keyreducer}, ${setKeyreducer}] = this.useReducer('${keyreducer}', ${
|
|
209
|
-
line.includes("=>") ? reducer + "=>{" : reducer
|
|
210
|
-
}`;
|
|
211
|
-
|
|
212
|
-
data = data.replace(line, newStatereducer);
|
|
213
|
-
|
|
214
|
-
break;
|
|
215
|
-
|
|
216
|
-
case line.includes("useState") && !line.includes("import"):
|
|
217
|
-
let varType = line.split("[")[0];
|
|
218
|
-
|
|
219
|
-
if (!line.split("=")[0].split(",")[1]) {
|
|
220
|
-
throw new Error(
|
|
221
|
-
"You forgot to value selector (useState) " +
|
|
222
|
-
" at " +
|
|
223
|
-
`${file}:${string.split(line)[0].split("\n").length}`
|
|
224
|
-
);
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
let key = line.split("=")[0].split(",")[0].trim().split("[")[1];
|
|
228
|
-
|
|
229
|
-
if (!line.split("=")[0].split(",")[1]) {
|
|
230
|
-
throw new Error(
|
|
231
|
-
"You forgot to add a setter (useState) " +
|
|
232
|
-
" at " +
|
|
233
|
-
`${file}:${string.split(line)[0].split("\n").length}`
|
|
234
|
-
);
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
let setKey = line.split("=")[0].split(",")[1].trim().replace("]", "");
|
|
238
|
-
|
|
239
|
-
key = key.replace("[", "").replace(",", "");
|
|
240
|
-
|
|
241
|
-
let valuestate = line.split("=")[1].split("useState(")[1];
|
|
242
|
-
|
|
243
|
-
let regex = /useState\((.*)\)/gs;
|
|
244
|
-
|
|
245
|
-
valuestate = valuestate.match(regex)
|
|
246
|
-
? valuestate
|
|
247
|
-
.match(regex)[0]
|
|
248
|
-
.split("useState(")[1]
|
|
249
|
-
.split(")")[0]
|
|
250
|
-
.trim()
|
|
251
|
-
: valuestate;
|
|
252
|
-
|
|
253
|
-
let newState = `${varType} [${key}, ${setKey}] = this.useState('${key}', ${valuestate}`;
|
|
254
|
-
|
|
255
|
-
data = data.replace(line, newState);
|
|
256
|
-
|
|
257
|
-
break;
|
|
258
|
-
|
|
259
|
-
case line.includes("useRef") && !line.includes("import"):
|
|
260
|
-
line = line.trim();
|
|
261
|
-
|
|
262
|
-
let typeref = line.split(" ")[0];
|
|
263
|
-
|
|
264
|
-
let keyref = line
|
|
265
|
-
.split(typeref)[1]
|
|
266
|
-
.split("=")[0]
|
|
267
|
-
.trim()
|
|
268
|
-
.replace("[", "")
|
|
269
|
-
.replace(",", "");
|
|
270
|
-
|
|
271
|
-
let valueref = line.split("=")[1].split("useRef(")[1];
|
|
272
|
-
|
|
273
|
-
let newStateref = `${typeref} ${keyref} = this.useRef('${keyref}', ${valueref}`;
|
|
274
|
-
|
|
275
|
-
data = data.replace(line, newStateref);
|
|
276
|
-
|
|
277
|
-
case (line.includes(".jsx") && line.includes("import")) ||
|
|
278
|
-
(line.includes(".tsx") && line.includes("import")):
|
|
279
|
-
let old = line;
|
|
280
|
-
|
|
281
|
-
line = line.replace(".jsx", ".js");
|
|
282
|
-
|
|
283
|
-
line = line.replace(".tsx", ".js");
|
|
284
|
-
|
|
285
|
-
data = data.replace(old, line);
|
|
286
|
-
|
|
287
|
-
break;
|
|
288
|
-
}
|
|
289
|
-
});
|
|
290
|
-
|
|
291
|
-
data = data.replaceAll("jsxDEV", "Vader.createElement");
|
|
292
|
-
|
|
293
|
-
data = data.replaceAll("jsx", "Vader.createElement");
|
|
294
|
-
|
|
295
|
-
data = data.replaceAll("vaderjs/client", "/vader.js");
|
|
296
|
-
|
|
297
|
-
data = data.replaceAll(".tsx", ".js");
|
|
298
|
-
|
|
299
|
-
let reactImportMatch = data.match(/import React/g);
|
|
300
|
-
|
|
301
|
-
if (reactImportMatch) {
|
|
302
|
-
let fullmatch = data.match(/import React from "react"/g);
|
|
303
|
-
|
|
304
|
-
if (fullmatch) {
|
|
305
|
-
data = data.replaceAll('import React from "react"', "");
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
data = data.replaceAll(".ts", ".js");
|
|
310
|
-
|
|
311
|
-
// check if Vader is imported
|
|
312
|
-
|
|
313
|
-
let vaderImport = data.match(/import Vader/g);
|
|
314
|
-
|
|
315
|
-
if (!vaderImport) {
|
|
316
|
-
data = `import Vader from "/vader.js";\n` + data;
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
return data;
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
/**
|
|
323
|
-
|
|
324
|
-
* @function ContentType
|
|
325
|
-
|
|
326
|
-
* @description - returns the content type based on the file extension
|
|
327
|
-
|
|
328
|
-
* @param {*} url
|
|
329
|
-
|
|
330
|
-
* @returns
|
|
331
|
-
|
|
332
|
-
*/
|
|
333
|
-
|
|
334
|
-
const ContentType = (url) => {
|
|
335
|
-
switch (url.split(".").pop()) {
|
|
336
|
-
case "css":
|
|
337
|
-
return "text/css";
|
|
338
|
-
|
|
339
|
-
case "js":
|
|
340
|
-
return "text/javascript";
|
|
341
|
-
|
|
342
|
-
case "json":
|
|
343
|
-
return "application/json";
|
|
344
|
-
|
|
345
|
-
case "html":
|
|
346
|
-
return "text/html";
|
|
347
|
-
|
|
348
|
-
case "jpg":
|
|
349
|
-
return "image/jpg";
|
|
350
|
-
|
|
351
|
-
case "png":
|
|
352
|
-
return "image/png";
|
|
353
|
-
|
|
354
|
-
case "gif":
|
|
355
|
-
return "image/gif";
|
|
356
|
-
|
|
357
|
-
case "svg":
|
|
358
|
-
return "image/svg+xml";
|
|
359
|
-
|
|
360
|
-
case "webp":
|
|
361
|
-
return "image/webp";
|
|
362
|
-
case "ico":
|
|
363
|
-
return "image/x-icon";
|
|
364
|
-
|
|
365
|
-
default:
|
|
366
|
-
return "text/html";
|
|
367
|
-
}
|
|
368
|
-
};
|
|
369
|
-
|
|
370
|
-
/**
|
|
371
|
-
|
|
372
|
-
* @function Server
|
|
373
|
-
|
|
374
|
-
* @description - Creates a hmr development server
|
|
375
|
-
|
|
376
|
-
* @param {Number} port
|
|
377
|
-
|
|
378
|
-
*/
|
|
379
|
-
|
|
380
|
-
function Server(port) {
|
|
381
|
-
Bun.serve({
|
|
382
|
-
port: port,
|
|
383
|
-
|
|
384
|
-
async fetch(req, res) {
|
|
385
|
-
const url = new URL(req.url);
|
|
386
|
-
|
|
387
|
-
const success = res.upgrade(req);
|
|
388
|
-
|
|
389
|
-
if (success) {
|
|
390
|
-
return new Response("Connected", {
|
|
391
|
-
headers: {
|
|
392
|
-
"Content-Type": "text/html",
|
|
393
|
-
},
|
|
394
|
-
});
|
|
395
|
-
}
|
|
396
|
-
|
|
397
|
-
if (req.url.includes(".")) {
|
|
398
|
-
if (!fs.existsSync(process.cwd() + "/dist" + url.pathname)) {
|
|
399
|
-
return new Response("Not Found", {
|
|
400
|
-
status: 404,
|
|
401
|
-
|
|
402
|
-
headers: {
|
|
403
|
-
"Content-Type": "text/html",
|
|
404
|
-
},
|
|
405
|
-
});
|
|
406
|
-
}
|
|
407
|
-
|
|
408
|
-
console.log(`HTTP GET: ${url.pathname} -> ${ContentType(req.url)}`);
|
|
409
|
-
return new Response(
|
|
410
|
-
fs.readFileSync(process.cwd() + "/dist" + url.pathname),
|
|
411
|
-
{
|
|
412
|
-
headers: {
|
|
413
|
-
"Content-Type": ContentType(req.url),
|
|
414
|
-
},
|
|
415
|
-
}
|
|
416
|
-
);
|
|
417
|
-
}
|
|
418
|
-
|
|
419
|
-
let matchedRoute =
|
|
420
|
-
router.match(url.pathname) ||
|
|
421
|
-
fs.existsSync(process.cwd() + "/dist" + url.pathname)
|
|
422
|
-
? {
|
|
423
|
-
filePath: process.cwd() + "/dist" + url.pathname,
|
|
424
|
-
isAbsolute: true,
|
|
425
|
-
}
|
|
426
|
-
: null;
|
|
427
|
-
|
|
428
|
-
if (matchedRoute) {
|
|
429
|
-
let { filePath, kind, name, params, pathname, query, isAbsolute } =
|
|
430
|
-
matchedRoute;
|
|
431
|
-
|
|
432
|
-
let folder = filePath.split("pages/").pop().split("index.js").shift();
|
|
433
|
-
folder = folder
|
|
434
|
-
.split("/")
|
|
435
|
-
.filter((f) => f !== "dist")
|
|
436
|
-
.join("/");
|
|
437
|
-
let jsFile = filePath.split("pages/").pop().split(".").shift() + ".js";
|
|
438
|
-
|
|
439
|
-
let pageContent = isAbsolute
|
|
440
|
-
? fs.readFileSync(filePath + "/index.html")
|
|
441
|
-
: fs.readFileSync(
|
|
442
|
-
process.cwd() + "/dist/" + folder + "/index.html",
|
|
443
|
-
"utf8"
|
|
444
|
-
);
|
|
445
|
-
|
|
446
|
-
globalThis.mode === "dev"
|
|
447
|
-
? (pageContent += `
|
|
448
|
-
|
|
449
|
-
<script type="module">
|
|
450
|
-
|
|
451
|
-
let ws = new WebSocket('ws://localhost:${port}');
|
|
452
|
-
|
|
453
|
-
ws.onmessage = async (e) => {
|
|
454
|
-
|
|
455
|
-
if(e.data === 'reload'){
|
|
456
|
-
|
|
457
|
-
window.location.reload()
|
|
458
|
-
|
|
459
|
-
console.log('Reloading...')
|
|
460
|
-
|
|
461
|
-
}
|
|
462
|
-
|
|
463
|
-
}
|
|
464
|
-
|
|
465
|
-
</script>
|
|
466
|
-
|
|
467
|
-
`)
|
|
468
|
-
: void 0;
|
|
469
|
-
|
|
470
|
-
return new Response(pageContent, {
|
|
471
|
-
headers: {
|
|
472
|
-
"Content-Type": "text/html",
|
|
473
|
-
|
|
474
|
-
"X-Powered-By": "Vader.js v1.3.3",
|
|
475
|
-
},
|
|
476
|
-
});
|
|
477
|
-
}
|
|
478
|
-
|
|
479
|
-
return new Response("Not Found", {
|
|
480
|
-
status: 404,
|
|
481
|
-
|
|
482
|
-
headers: {
|
|
483
|
-
"Content-Type": "text/html",
|
|
484
|
-
},
|
|
485
|
-
});
|
|
486
|
-
},
|
|
487
|
-
|
|
488
|
-
websocket: {
|
|
489
|
-
open(ws) {
|
|
490
|
-
clients.push(ws);
|
|
491
|
-
},
|
|
492
|
-
},
|
|
493
|
-
});
|
|
494
|
-
}
|
|
495
|
-
|
|
496
|
-
/**
|
|
497
|
-
|
|
498
|
-
* @function write
|
|
499
|
-
|
|
500
|
-
* @description - Writes data to a file
|
|
501
|
-
|
|
502
|
-
* @returns {void} 0
|
|
503
|
-
|
|
504
|
-
* @param {string} file
|
|
505
|
-
|
|
506
|
-
* @param {any} data
|
|
507
|
-
|
|
508
|
-
* @returns
|
|
509
|
-
|
|
510
|
-
*/
|
|
511
|
-
|
|
512
|
-
const write = (file, data) => {
|
|
513
|
-
try {
|
|
514
|
-
if (!fs.existsSync("./dist")) {
|
|
515
|
-
fs.mkdirSync("./dist");
|
|
516
|
-
}
|
|
517
|
-
|
|
518
|
-
Bun.write(file, data);
|
|
519
|
-
} catch (error) {
|
|
520
|
-
console.error(error);
|
|
521
|
-
}
|
|
522
|
-
};
|
|
523
|
-
|
|
524
|
-
/**
|
|
525
|
-
|
|
526
|
-
* @function read
|
|
527
|
-
|
|
528
|
-
* @param {path} file
|
|
529
|
-
|
|
530
|
-
* @returns {Promise<string>}
|
|
531
|
-
|
|
532
|
-
*/
|
|
533
|
-
|
|
534
|
-
const read = async (file) => {
|
|
535
|
-
return await Bun.file(file).text();
|
|
536
|
-
};
|
|
537
|
-
|
|
538
|
-
/**
|
|
539
|
-
|
|
540
|
-
* @object integrationStates
|
|
541
|
-
|
|
542
|
-
* @description - Used to store integration states
|
|
543
|
-
|
|
544
|
-
*/
|
|
545
|
-
|
|
546
|
-
globalThis.integrationStates = [];
|
|
547
|
-
|
|
548
|
-
/**
|
|
549
|
-
|
|
550
|
-
* @description a boolean value that checks if vader is being used - useful for running toplevel code at integration start
|
|
551
|
-
|
|
552
|
-
*/
|
|
553
|
-
|
|
554
|
-
globalThis.context = {
|
|
555
|
-
vader: true,
|
|
556
|
-
};
|
|
557
|
-
|
|
558
|
-
/**
|
|
559
|
-
|
|
560
|
-
* @function handleIntegrations
|
|
561
|
-
|
|
562
|
-
* @description - Handles module integrations that add more functionality to Vader.js
|
|
563
|
-
|
|
564
|
-
* @returns {void} 0
|
|
565
|
-
|
|
566
|
-
*/
|
|
567
|
-
|
|
568
|
-
function handleIntegrations() {
|
|
569
|
-
if (config?.integrations) {
|
|
570
|
-
config.integrations.forEach((integration) => {
|
|
571
|
-
let int = integration;
|
|
572
|
-
|
|
573
|
-
globalThis.integrationStates.push(int);
|
|
574
|
-
});
|
|
575
|
-
}
|
|
576
|
-
|
|
577
|
-
return void 0;
|
|
578
|
-
}
|
|
579
|
-
|
|
580
|
-
handleIntegrations();
|
|
581
|
-
|
|
582
|
-
/**
|
|
583
|
-
|
|
584
|
-
* @function generateProviderRoutes
|
|
585
|
-
|
|
586
|
-
* @description - Generates routes for hosting provders ie: vercel, cloudflare
|
|
587
|
-
|
|
588
|
-
* @returns {void} 0
|
|
589
|
-
|
|
590
|
-
*/
|
|
591
|
-
|
|
592
|
-
async function generateProviderRoutes() {
|
|
593
|
-
if (!config?.host?.provider) {
|
|
594
|
-
console.warn(
|
|
595
|
-
"No provider found in vader.config.js ignoring route generation..."
|
|
596
|
-
);
|
|
597
|
-
|
|
598
|
-
return void 0;
|
|
599
|
-
}
|
|
600
|
-
|
|
601
|
-
let providerType = [
|
|
602
|
-
{
|
|
603
|
-
provider: "vercel",
|
|
604
|
-
|
|
605
|
-
file: "vercel.json",
|
|
606
|
-
|
|
607
|
-
out: process.cwd() + "/vercel.json",
|
|
608
|
-
|
|
609
|
-
obj: {
|
|
610
|
-
rewrites: [],
|
|
611
|
-
},
|
|
612
|
-
},
|
|
613
|
-
{
|
|
614
|
-
provider: "cloudflare",
|
|
615
|
-
|
|
616
|
-
file: "_redirects",
|
|
617
|
-
|
|
618
|
-
out: "dist/_redirects",
|
|
619
|
-
},
|
|
620
|
-
];
|
|
621
|
-
|
|
622
|
-
let provider = providerType.find((p) => p.provider === config.host.provider);
|
|
623
|
-
|
|
624
|
-
if (provider) {
|
|
625
|
-
let prev = null;
|
|
626
|
-
|
|
627
|
-
switch (provider.provider) {
|
|
628
|
-
case "vercel":
|
|
629
|
-
if (!fs.existsSync(provider.out)) {
|
|
630
|
-
fs.writeFileSync(
|
|
631
|
-
provider.out,
|
|
632
|
-
JSON.stringify({
|
|
633
|
-
rewrites: [],
|
|
634
|
-
})
|
|
635
|
-
);
|
|
636
|
-
}
|
|
637
|
-
|
|
638
|
-
prev = await read(provider.out);
|
|
639
|
-
|
|
640
|
-
if (!prev) {
|
|
641
|
-
prev = [];
|
|
642
|
-
} else {
|
|
643
|
-
prev = JSON.parse(prev).rewrites;
|
|
644
|
-
}
|
|
645
|
-
|
|
646
|
-
routes.forEach((r) => {
|
|
647
|
-
let previous = prev.find((p) => p.source.includes(r.path));
|
|
648
|
-
|
|
649
|
-
if (previous) {
|
|
650
|
-
return void 0;
|
|
651
|
-
}
|
|
652
|
-
|
|
653
|
-
prev.push({
|
|
654
|
-
source: "/" + r.path,
|
|
655
|
-
|
|
656
|
-
destination: "/" + r.path + "/index.html",
|
|
657
|
-
});
|
|
658
|
-
|
|
659
|
-
if (r.params.length > 0) {
|
|
660
|
-
r.params.forEach((param) => {
|
|
661
|
-
if (!param.paramData) {
|
|
662
|
-
return void 0;
|
|
663
|
-
}
|
|
664
|
-
|
|
665
|
-
let parampath = Object.keys(param.paramData)
|
|
666
|
-
.map((p) => `:${p}`)
|
|
667
|
-
.join("/");
|
|
668
|
-
|
|
669
|
-
prev.push({
|
|
670
|
-
source: "/" + r.path + "/" + parampath,
|
|
671
|
-
|
|
672
|
-
destination: "/" + r.path + "/index.html",
|
|
673
|
-
});
|
|
674
|
-
});
|
|
675
|
-
}
|
|
676
|
-
|
|
677
|
-
fs.writeFileSync(
|
|
678
|
-
provider.out,
|
|
679
|
-
JSON.stringify(
|
|
680
|
-
{
|
|
681
|
-
rewrites: prev,
|
|
682
|
-
},
|
|
683
|
-
null,
|
|
684
|
-
2
|
|
685
|
-
)
|
|
686
|
-
);
|
|
687
|
-
});
|
|
688
|
-
|
|
689
|
-
provider.obj.rewrites = prev;
|
|
690
|
-
|
|
691
|
-
write(provider.out, JSON.stringify(provider.obj, null, 2));
|
|
692
|
-
|
|
693
|
-
break;
|
|
694
|
-
|
|
695
|
-
case "cloudflare":
|
|
696
|
-
console.warn(
|
|
697
|
-
"Cloudflare is not supported yet refer to their documentation for more information:https://developers.cloudflare.com/pages/configuration/redirects/"
|
|
698
|
-
);
|
|
699
|
-
|
|
700
|
-
break;
|
|
701
|
-
}
|
|
702
|
-
}
|
|
703
|
-
|
|
704
|
-
return void 0;
|
|
705
|
-
}
|
|
706
|
-
|
|
707
|
-
/**
|
|
708
|
-
|
|
709
|
-
* @function transform
|
|
710
|
-
|
|
711
|
-
* @description - Transforms the jsx files to js files based on file paths
|
|
712
|
-
|
|
713
|
-
*/
|
|
714
|
-
|
|
715
|
-
async function transForm() {
|
|
716
|
-
return new Promise(async (resolve, reject) => {
|
|
717
|
-
globalThis.isBuilding = true;
|
|
718
|
-
|
|
719
|
-
router.reload();
|
|
720
|
-
|
|
721
|
-
for await (var file of glob.scan(".")) {
|
|
722
|
-
file = file.replace(/\\/g, "/");
|
|
723
|
-
|
|
724
|
-
let isBasePath = file.split("pages/")?.[1]?.split("/").length === 1;
|
|
725
|
-
|
|
726
|
-
let folder =
|
|
727
|
-
file.split("pages/")?.[1]?.split("/").slice(0, -1).join("/") || null;
|
|
728
|
-
|
|
729
|
-
if (isBasePath) {
|
|
730
|
-
folder = "/";
|
|
731
|
-
}
|
|
732
|
-
|
|
733
|
-
if (file.endsWith(".md")) {
|
|
734
|
-
let data = await read(file);
|
|
735
|
-
if (
|
|
736
|
-
integrationStates.find((int) => int?._df && int?._df === "i18mdf")
|
|
737
|
-
) {
|
|
738
|
-
console.log(
|
|
739
|
-
`Using markdown parser ${
|
|
740
|
-
integrationStates.find((int) => int?._df && int?._df === "i18mdf")
|
|
741
|
-
.name
|
|
742
|
-
} v${
|
|
743
|
-
integrationStates.find((int) => int?._df && int?._df === "i18mdf")
|
|
744
|
-
.version
|
|
745
|
-
}`
|
|
746
|
-
);
|
|
747
|
-
let parser = integrationStates.find(
|
|
748
|
-
(int) => int?._df && int?._df === "i18mdf"
|
|
749
|
-
);
|
|
750
|
-
|
|
751
|
-
parser.parse(data);
|
|
752
|
-
parser._class.stylesheets.forEach((sheet) => {
|
|
753
|
-
parser._class.output =
|
|
754
|
-
`<link rel="stylesheet" href="${sheet}">` + parser._class.output;
|
|
755
|
-
});
|
|
756
|
-
let output = `./dist/${
|
|
757
|
-
isBasePath ? "index.html" : folder + "/index.html"
|
|
758
|
-
}`;
|
|
759
|
-
write(output, parser._class.output);
|
|
760
|
-
}
|
|
761
|
-
continue;
|
|
762
|
-
}
|
|
763
|
-
|
|
764
|
-
let route = isBasePath ? router.match("/") : router.match("/" + folder);
|
|
765
|
-
|
|
766
|
-
if (route) {
|
|
767
|
-
let { filePath, kind, name, params, pathname, query } = route;
|
|
768
|
-
|
|
769
|
-
let data = await read(filePath);
|
|
770
|
-
|
|
771
|
-
try {
|
|
772
|
-
data = new Bun.Transpiler({
|
|
773
|
-
loader: "tsx",
|
|
774
|
-
target: "browser",
|
|
775
|
-
}).transformSync(data);
|
|
776
|
-
} catch (e) {
|
|
777
|
-
console.error(e);
|
|
778
|
-
}
|
|
779
|
-
|
|
780
|
-
let out = `./dist/${isBasePath ? "index.js" : folder + "/index.js"}`;
|
|
781
|
-
|
|
782
|
-
isBasePath ? (folder = "/") : null;
|
|
783
|
-
|
|
784
|
-
data = handleReplaceMents(data);
|
|
785
|
-
|
|
786
|
-
let isAparam = null;
|
|
787
|
-
|
|
788
|
-
if (folder === "") {
|
|
789
|
-
return;
|
|
790
|
-
}
|
|
791
|
-
|
|
792
|
-
switch (true) {
|
|
793
|
-
case kind === "dynamic":
|
|
794
|
-
isAparam = true;
|
|
795
|
-
|
|
796
|
-
break;
|
|
797
|
-
|
|
798
|
-
case kind === "catch-all":
|
|
799
|
-
isAparam = true;
|
|
800
|
-
|
|
801
|
-
break;
|
|
802
|
-
|
|
803
|
-
case kind === "optional-catch-all":
|
|
804
|
-
isAparam = true;
|
|
805
|
-
|
|
806
|
-
break;
|
|
807
|
-
}
|
|
808
|
-
|
|
809
|
-
routes.push({
|
|
810
|
-
path: folder,
|
|
811
|
-
file: out,
|
|
812
|
-
isParam: isAparam,
|
|
813
|
-
params: params,
|
|
814
|
-
query,
|
|
815
|
-
pathname,
|
|
816
|
-
});
|
|
817
|
-
|
|
818
|
-
write(out, data);
|
|
819
|
-
|
|
820
|
-
bundleSize += data.length;
|
|
821
|
-
}
|
|
822
|
-
}
|
|
823
|
-
|
|
824
|
-
for await (var file of srcGlob.scan(".")) {
|
|
825
|
-
if (!fs.existsSync(process.cwd() + "/dist/src/")) {
|
|
826
|
-
fs.mkdirSync(process.cwd() + "/dist/src/");
|
|
827
|
-
}
|
|
828
|
-
|
|
829
|
-
file = file.replace(/\\/g, "/");
|
|
830
|
-
|
|
831
|
-
switch (file.split(".").pop()) {
|
|
832
|
-
case "ts":
|
|
833
|
-
let transpiler = new Bun.Transpiler({
|
|
834
|
-
loader: "ts",
|
|
835
|
-
target: "browser",
|
|
836
|
-
});
|
|
837
|
-
|
|
838
|
-
let data = await read(file);
|
|
839
|
-
|
|
840
|
-
try {
|
|
841
|
-
data = transpiler.transformSync(data);
|
|
842
|
-
} catch (error) {
|
|
843
|
-
console.error(error);
|
|
844
|
-
}
|
|
845
|
-
|
|
846
|
-
file = file.replace(".ts", ".js");
|
|
847
|
-
|
|
848
|
-
let path = process.cwd() + "/dist/src/" + file.split("src/").pop();
|
|
849
|
-
|
|
850
|
-
write(path, data);
|
|
851
|
-
|
|
852
|
-
bundleSize += data.length;
|
|
853
|
-
|
|
854
|
-
break;
|
|
855
|
-
|
|
856
|
-
case "tsx":
|
|
857
|
-
let transpilerx = new Bun.Transpiler({
|
|
858
|
-
loader: "tsx",
|
|
859
|
-
target: "browser",
|
|
860
|
-
});
|
|
861
|
-
|
|
862
|
-
let datax = await read(file);
|
|
863
|
-
|
|
864
|
-
try {
|
|
865
|
-
datax = transpilerx.transformSync(datax);
|
|
866
|
-
} catch (error) {
|
|
867
|
-
console.error(error);
|
|
868
|
-
}
|
|
869
|
-
|
|
870
|
-
datax = handleReplaceMents(datax);
|
|
871
|
-
|
|
872
|
-
file = file.replace(".tsx", ".js");
|
|
873
|
-
|
|
874
|
-
let pathx = process.cwd() + "/dist/src/" + file.split("src/").pop();
|
|
875
|
-
|
|
876
|
-
write(pathx, datax);
|
|
877
|
-
|
|
878
|
-
break;
|
|
879
|
-
|
|
880
|
-
case "jsx":
|
|
881
|
-
let transpilerjx = new Bun.Transpiler({
|
|
882
|
-
loader: "jsx",
|
|
883
|
-
target: "browser",
|
|
884
|
-
});
|
|
885
|
-
|
|
886
|
-
let datajx = await read(file);
|
|
887
|
-
|
|
888
|
-
let source = transpilerjx.scan(datajx);
|
|
889
|
-
|
|
890
|
-
try {
|
|
891
|
-
datajx = transpilerjx.transformSync(datajx);
|
|
892
|
-
} catch (error) {
|
|
893
|
-
console.error(error);
|
|
894
|
-
}
|
|
895
|
-
|
|
896
|
-
datajx = handleReplaceMents(datajx);
|
|
897
|
-
|
|
898
|
-
file = file.replace(".jsx", ".js");
|
|
899
|
-
|
|
900
|
-
let pathjx = process.cwd() + "/dist/src/" + file.split("src/").pop();
|
|
901
|
-
|
|
902
|
-
write(pathjx, datajx);
|
|
903
|
-
|
|
904
|
-
bundleSize += datajx.length;
|
|
905
|
-
|
|
906
|
-
break;
|
|
907
|
-
default:
|
|
908
|
-
break;
|
|
909
|
-
}
|
|
910
|
-
}
|
|
911
|
-
|
|
912
|
-
for await (var file of publicGlob.scan(".")) {
|
|
913
|
-
// works
|
|
914
|
-
|
|
915
|
-
let data = null;
|
|
916
|
-
let isBuff = false;
|
|
917
|
-
file = file.replace(/\\/g, "/");
|
|
918
|
-
if (
|
|
919
|
-
file.endsWith(".png") ||
|
|
920
|
-
file.endsWith(".jpg") ||
|
|
921
|
-
file.endsWith(".jpeg") ||
|
|
922
|
-
file.endsWith(".gif") ||
|
|
923
|
-
file.endsWith(".svg") ||
|
|
924
|
-
file.endsWith(".webp") ||
|
|
925
|
-
file.endsWith(".ico") ||
|
|
926
|
-
file.endsWith(".mp4") ||
|
|
927
|
-
file.endsWith(".webm")
|
|
928
|
-
) {
|
|
929
|
-
data = Buffer.from(fs.readFileSync(file)).toString("base64");
|
|
930
|
-
isBuff = true;
|
|
931
|
-
}
|
|
932
|
-
data = data || (await read(file));
|
|
933
|
-
|
|
934
|
-
let path = process.cwd() + "/dist/public/" + file.split("public/").pop();
|
|
935
|
-
fs.writeFileSync(path, data, isBuff ? "base64" : "utf8");
|
|
936
|
-
|
|
937
|
-
bundleSize += data.length;
|
|
938
|
-
}
|
|
939
|
-
|
|
940
|
-
for await (var file of vaderGlob.scan(".")) {
|
|
941
|
-
file = file.replace(/\\/g, "/");
|
|
942
|
-
if (
|
|
943
|
-
fs.existsSync(
|
|
944
|
-
process.cwd() +
|
|
945
|
-
"/dist/" +
|
|
946
|
-
file.split("node_modules/vaderjs/runtime/").pop()
|
|
947
|
-
)
|
|
948
|
-
) {
|
|
949
|
-
return;
|
|
950
|
-
}
|
|
951
|
-
let data = await read(file);
|
|
952
|
-
|
|
953
|
-
file = file.replace(/\\/g, "/");
|
|
954
|
-
|
|
955
|
-
write(
|
|
956
|
-
process.cwd() +
|
|
957
|
-
"/dist/" +
|
|
958
|
-
file.split("node_modules/vaderjs/runtime/").pop(),
|
|
959
|
-
data
|
|
960
|
-
);
|
|
961
|
-
|
|
962
|
-
bundleSize += fs.statSync(
|
|
963
|
-
process.cwd() +
|
|
964
|
-
"/dist/" +
|
|
965
|
-
file.split("node_modules/vaderjs/runtime/").pop()
|
|
966
|
-
).size;
|
|
967
|
-
}
|
|
968
|
-
|
|
969
|
-
// clean dist folder
|
|
970
|
-
|
|
971
|
-
for await (var file of distPages.scan(".")) {
|
|
972
|
-
file = file.replace(/\\/g, "/");
|
|
973
|
-
|
|
974
|
-
let path = process.cwd() + "/pages/" + file.split("dist/pages/").pop();
|
|
975
|
-
|
|
976
|
-
path = path.replace(".js", config?.files?.mimeType || ".jsx");
|
|
977
|
-
|
|
978
|
-
if (!fs.existsSync(path)) {
|
|
979
|
-
fs.unlinkSync(file);
|
|
980
|
-
}
|
|
981
|
-
}
|
|
982
|
-
|
|
983
|
-
/**
|
|
984
|
-
|
|
985
|
-
* @function organizeRoutes
|
|
986
|
-
|
|
987
|
-
* @description - Organizes routes that have param paths
|
|
988
|
-
|
|
989
|
-
*/
|
|
990
|
-
|
|
991
|
-
const organizeRoutes = () => {
|
|
992
|
-
// if path starts with the same path and is dynamic then they are the same route and push params to the same route
|
|
993
|
-
|
|
994
|
-
let newRoutes = [];
|
|
995
|
-
|
|
996
|
-
routes.forEach((route) => {
|
|
997
|
-
let exists = routes.find((r) => {
|
|
998
|
-
if (r.path.includes("[")) {
|
|
999
|
-
r.path = r.path.split("[").shift();
|
|
1000
|
-
}
|
|
1001
|
-
|
|
1002
|
-
r.path = r.path
|
|
1003
|
-
.split("/")
|
|
1004
|
-
.filter((p) => p !== "")
|
|
1005
|
-
.join("/");
|
|
1006
|
-
|
|
1007
|
-
if (r.isParam) {
|
|
1008
|
-
return r.path === route.path && r.isParam;
|
|
1009
|
-
}
|
|
1010
|
-
});
|
|
1011
|
-
|
|
1012
|
-
if (exists) {
|
|
1013
|
-
let b4Params = route.params;
|
|
1014
|
-
|
|
1015
|
-
route.params = [];
|
|
1016
|
-
|
|
1017
|
-
route.params.push(b4Params);
|
|
1018
|
-
|
|
1019
|
-
route.params.push({
|
|
1020
|
-
jsFile: "/" + exists.path + "/index.js",
|
|
1021
|
-
|
|
1022
|
-
folder: "/" + exists.path,
|
|
1023
|
-
|
|
1024
|
-
paramData: exists.params,
|
|
1025
|
-
});
|
|
1026
|
-
|
|
1027
|
-
route.query = exists.query;
|
|
1028
|
-
|
|
1029
|
-
newRoutes.push(route);
|
|
1030
|
-
} else if (!exists && !route.isParam) {
|
|
1031
|
-
newRoutes.push(route);
|
|
1032
|
-
}
|
|
1033
|
-
|
|
1034
|
-
//remove param route that matched
|
|
1035
|
-
|
|
1036
|
-
routes = routes.filter((r) => (exists ? r.path !== exists.path : true));
|
|
1037
|
-
});
|
|
1038
|
-
|
|
1039
|
-
globalThis.routes = newRoutes;
|
|
1040
|
-
};
|
|
1041
|
-
|
|
1042
|
-
organizeRoutes();
|
|
1043
|
-
|
|
1044
|
-
generateProviderRoutes();
|
|
1045
|
-
|
|
1046
|
-
globalThis.isBuilding = false;
|
|
1047
|
-
|
|
1048
|
-
if (!fs.existsSync(process.cwd() + "/_dev/meta")) {
|
|
1049
|
-
fs.mkdirSync(process.cwd() + "/_dev/meta");
|
|
1050
|
-
}
|
|
1051
|
-
|
|
1052
|
-
fs.writeFileSync(
|
|
1053
|
-
process.cwd() + "/_dev/meta/routes.json",
|
|
1054
|
-
JSON.stringify(routes, null, 2)
|
|
1055
|
-
);
|
|
1056
|
-
|
|
1057
|
-
console.log(`Finished building ${Math.round(bundleSize / 1000)}kb`);
|
|
1058
|
-
|
|
1059
|
-
bundleSize = 0;
|
|
1060
|
-
|
|
1061
|
-
resolve();
|
|
1062
|
-
});
|
|
1063
|
-
}
|
|
1064
|
-
|
|
1065
|
-
let port = 3000;
|
|
1066
|
-
let hasRan = [];
|
|
1067
|
-
|
|
1068
|
-
switch (true) {
|
|
1069
|
-
case process.argv.includes("dev") &&
|
|
1070
|
-
!process.argv.includes("build") &&
|
|
1071
|
-
!process.argv.includes("start"):
|
|
1072
|
-
port = process.argv.includes("-p")
|
|
1073
|
-
? process.argv[process.argv.indexOf("-p") + 1]
|
|
1074
|
-
: config?.dev?.port || 3000;
|
|
1075
|
-
|
|
1076
|
-
globalThis.oneAndDone = false;
|
|
1077
|
-
let v = await checkIFUptodate();
|
|
1078
|
-
|
|
1079
|
-
console.log(`
|
|
1080
|
-
|
|
1081
|
-
${
|
|
1082
|
-
v.current !== v.latest
|
|
1083
|
-
? `Update available: ${v.latest} (current: ${v.current})`
|
|
1084
|
-
: `Vader.js v${v.current}`
|
|
1085
|
-
}
|
|
1086
|
-
- Watching for changes in ./pages
|
|
1087
|
-
- Watching for changes in ./src
|
|
1088
|
-
- Watching for changes in ./public
|
|
1089
|
-
- Serving on port http://localhost:${port}
|
|
1090
|
-
|
|
1091
|
-
`);
|
|
1092
|
-
|
|
1093
|
-
globalThis.mode = "dev";
|
|
1094
|
-
|
|
1095
|
-
Server(port);
|
|
1096
|
-
for (var ints in integrationStates) {
|
|
1097
|
-
if (
|
|
1098
|
-
integrationStates &&
|
|
1099
|
-
integrationStates[ints]?.on &&
|
|
1100
|
-
integrationStates[ints].on.includes("dev") &&
|
|
1101
|
-
!hasRan.includes(integrationStates[ints].name)
|
|
1102
|
-
) {
|
|
1103
|
-
console.log("Starting integration...");
|
|
1104
|
-
|
|
1105
|
-
let int = integrationStates[ints];
|
|
1106
|
-
|
|
1107
|
-
let { name, version, useRuntime, entryPoint, onAction, doOn } = int;
|
|
1108
|
-
|
|
1109
|
-
globalThis[`isRunning${name}`] = true;
|
|
1110
|
-
console.log(`Using integration: ${name} v${version}`);
|
|
1111
|
-
|
|
1112
|
-
Bun.spawn({
|
|
1113
|
-
cwd: process.cwd(),
|
|
1114
|
-
|
|
1115
|
-
isVader: true,
|
|
1116
|
-
|
|
1117
|
-
env: {
|
|
1118
|
-
PWD: process.cwd(),
|
|
1119
|
-
|
|
1120
|
-
isVader: true,
|
|
1121
|
-
|
|
1122
|
-
FOLDERS: "pages,src,public",
|
|
1123
|
-
|
|
1124
|
-
onExit: (code) => {
|
|
1125
|
-
globalThis.isBuilding = false;
|
|
1126
|
-
|
|
1127
|
-
globalThis[`isRunning${name}`] = false;
|
|
1128
|
-
},
|
|
1129
|
-
},
|
|
1130
|
-
|
|
1131
|
-
cmd: [useRuntime || "node", entryPoint],
|
|
1132
|
-
});
|
|
1133
|
-
|
|
1134
|
-
hasRan.push(integrationStates[ints].name);
|
|
1135
|
-
}
|
|
1136
|
-
}
|
|
1137
|
-
|
|
1138
|
-
transForm();
|
|
1139
|
-
|
|
1140
|
-
Bun.spawn({
|
|
1141
|
-
cwd: process.cwd() + "/node_modules/vaderjs/binaries/",
|
|
1142
|
-
|
|
1143
|
-
env: {
|
|
1144
|
-
PWD: process.cwd(),
|
|
1145
|
-
|
|
1146
|
-
IPC: IPC,
|
|
1147
|
-
|
|
1148
|
-
FOLDERS: "pages,src,public",
|
|
1149
|
-
|
|
1150
|
-
onExit: (code) => {
|
|
1151
|
-
globalThis.isBuilding = false;
|
|
1152
|
-
|
|
1153
|
-
globalThis.oneAndDone = true;
|
|
1154
|
-
},
|
|
1155
|
-
},
|
|
1156
|
-
|
|
1157
|
-
cmd: ["node", "watcher.js"],
|
|
1158
|
-
});
|
|
1159
|
-
|
|
1160
|
-
async function runOnChange() {
|
|
1161
|
-
for (var ints in integrationStates) {
|
|
1162
|
-
if (
|
|
1163
|
-
integrationStates &&
|
|
1164
|
-
integrationStates[ints].on &&
|
|
1165
|
-
integrationStates[ints]?.on.includes("dev:change")
|
|
1166
|
-
) {
|
|
1167
|
-
let int = integrationStates[ints];
|
|
1168
|
-
|
|
1169
|
-
let { name, version, useRuntime, entryPoint, onAction, doOn } = int;
|
|
1170
|
-
|
|
1171
|
-
if (globalThis[`isRunning${name}`]) {
|
|
1172
|
-
setTimeout(() => {
|
|
1173
|
-
globalThis[`isRunning${name}`] = false;
|
|
1174
|
-
}, 1000);
|
|
1175
|
-
return void 0;
|
|
1176
|
-
}
|
|
1177
|
-
|
|
1178
|
-
globalThis[`isRunning${name}`] = true;
|
|
1179
|
-
console.log(`Using integration: ${name} v${version}`);
|
|
1180
|
-
|
|
1181
|
-
Bun.spawn({
|
|
1182
|
-
cwd: process.cwd(),
|
|
1183
|
-
|
|
1184
|
-
isVader: true,
|
|
1185
|
-
|
|
1186
|
-
env: {
|
|
1187
|
-
PWD: process.cwd(),
|
|
1188
|
-
|
|
1189
|
-
isVader: true,
|
|
1190
|
-
|
|
1191
|
-
FOLDERS: "pages,src,public",
|
|
1192
|
-
|
|
1193
|
-
onExit: (code) => {
|
|
1194
|
-
globalThis.isBuilding = false;
|
|
1195
|
-
|
|
1196
|
-
globalThis[`isRunning${name}`] = false;
|
|
1197
|
-
},
|
|
1198
|
-
},
|
|
1199
|
-
|
|
1200
|
-
cmd: [useRuntime || "node", entryPoint],
|
|
1201
|
-
});
|
|
1202
|
-
|
|
1203
|
-
console.log(`Using integration: ${name} v${version}`);
|
|
1204
|
-
}
|
|
1205
|
-
}
|
|
1206
|
-
}
|
|
1207
|
-
|
|
1208
|
-
IPC.client({
|
|
1209
|
-
use: IPCServer.typeEnums.WATCHER,
|
|
1210
|
-
|
|
1211
|
-
port: 3434,
|
|
1212
|
-
}).Console.read(async (message) => {
|
|
1213
|
-
message = message.msg;
|
|
1214
|
-
|
|
1215
|
-
switch (true) {
|
|
1216
|
-
case message.data?.type === "change":
|
|
1217
|
-
console.log("File changed:", message.data.filename);
|
|
1218
|
-
|
|
1219
|
-
transForm();
|
|
1220
|
-
|
|
1221
|
-
clients.forEach((client) => {
|
|
1222
|
-
client.send("reload");
|
|
1223
|
-
});
|
|
1224
|
-
|
|
1225
|
-
// reload config
|
|
1226
|
-
config = await import(process.cwd() + "/vader.config.js").then((m) =>
|
|
1227
|
-
m ? m.default : {}
|
|
1228
|
-
);
|
|
1229
|
-
|
|
1230
|
-
runOnChange();
|
|
1231
|
-
|
|
1232
|
-
break;
|
|
1233
|
-
|
|
1234
|
-
case message.data?.type === "add":
|
|
1235
|
-
console.log("File added:", message.data.filename);
|
|
1236
|
-
|
|
1237
|
-
transForm();
|
|
1238
|
-
|
|
1239
|
-
break;
|
|
1240
|
-
}
|
|
1241
|
-
});
|
|
1242
|
-
|
|
1243
|
-
break;
|
|
1244
|
-
|
|
1245
|
-
case process.argv.includes("build") &&
|
|
1246
|
-
!process.argv.includes("dev") &&
|
|
1247
|
-
!process.argv.includes("start"):
|
|
1248
|
-
globalThis.devMode = false;
|
|
1249
|
-
|
|
1250
|
-
globalThis.mode = "prod";
|
|
1251
|
-
|
|
1252
|
-
globalThis.isProduction = true;
|
|
1253
|
-
|
|
1254
|
-
globalThis.routeStates = [];
|
|
1255
|
-
|
|
1256
|
-
console.log(`
|
|
1257
|
-
Vader.js v1.3.3
|
|
1258
|
-
Building to ./dist
|
|
1259
|
-
`);
|
|
1260
|
-
|
|
1261
|
-
transForm();
|
|
1262
|
-
|
|
1263
|
-
for (var ints in integrationStates) {
|
|
1264
|
-
if (
|
|
1265
|
-
integrationStates &&
|
|
1266
|
-
integrationStates[ints].on &&
|
|
1267
|
-
integrationStates[ints]?.on.includes("build")
|
|
1268
|
-
) {
|
|
1269
|
-
console.log("Starting integration...");
|
|
1270
|
-
|
|
1271
|
-
let int = integrationStates[ints];
|
|
1272
|
-
|
|
1273
|
-
let { name, version, useRuntime, entryPoint, onAction, doOn } = int;
|
|
1274
|
-
|
|
1275
|
-
console.log(`Using integration: ${name} v${version}`);
|
|
1276
|
-
|
|
1277
|
-
Bun.spawn({
|
|
1278
|
-
cwd: process.cwd(),
|
|
1279
|
-
|
|
1280
|
-
isVader: true,
|
|
1281
|
-
|
|
1282
|
-
env: {
|
|
1283
|
-
PWD: process.cwd(),
|
|
1284
|
-
|
|
1285
|
-
isVader: true,
|
|
1286
|
-
|
|
1287
|
-
FOLDERS: "pages,src,public",
|
|
1288
|
-
|
|
1289
|
-
onExit: (code) => {
|
|
1290
|
-
globalThis.isBuilding = false;
|
|
1291
|
-
},
|
|
1292
|
-
},
|
|
1293
|
-
|
|
1294
|
-
cmd: ["node", entryPoint],
|
|
1295
|
-
});
|
|
1296
|
-
}
|
|
1297
|
-
}
|
|
1298
|
-
|
|
1299
|
-
break;
|
|
1300
|
-
|
|
1301
|
-
case process.argv.includes("start") &&
|
|
1302
|
-
!process.argv.includes("dev") &&
|
|
1303
|
-
!process.argv.includes("build"):
|
|
1304
|
-
port = process.argv.includes("-p")
|
|
1305
|
-
? process.argv[process.argv.indexOf("-p") + 1]
|
|
1306
|
-
: config?.host?.prod?.port || 3000;
|
|
1307
|
-
|
|
1308
|
-
console.log(`
|
|
1309
|
-
|
|
1310
|
-
Vader.js v1.3.3
|
|
1311
|
-
|
|
1312
|
-
Serving ./dist on port ${port}
|
|
1313
|
-
|
|
1314
|
-
url: ${config?.host?.prod?.hostname || "http://localhost"}:${port}
|
|
1315
|
-
|
|
1316
|
-
`);
|
|
1317
|
-
|
|
1318
|
-
globalThis.devMode = false;
|
|
1319
|
-
|
|
1320
|
-
globalThis.isProduction = true;
|
|
1321
|
-
|
|
1322
|
-
Server(port);
|
|
1323
|
-
|
|
1324
|
-
break;
|
|
1325
|
-
|
|
1326
|
-
default:
|
|
1327
|
-
break;
|
|
1328
|
-
}
|