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