vaderjs 1.4.0 → 1.4.1-h7iuy47
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 +189 -0
- package/LICENSE +21 -0
- package/README.md +29 -52
- package/binaries/IPC/index.js +277 -0
- package/binaries/main.js +1455 -0
- package/binaries/watcher.js +70 -66
- package/binaries/win32/check.ps1 +7 -0
- package/config/index.js +36 -0
- package/package.json +5 -6
- package/runtime/router.js +1 -1
- package/runtime/vader.js +1 -1
- package/vader.js +212 -672
- package/binaries/generator.js +0 -201
package/vader.js
CHANGED
|
@@ -1,690 +1,230 @@
|
|
|
1
|
-
#!/usr/bin/env
|
|
2
|
-
import {
|
|
3
|
-
import fs from "fs";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
let
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
/**@description - Used to store hmr websocket clients */
|
|
11
|
-
globalThis.clients = []
|
|
12
|
-
/**@description - Used to keep track of routes */
|
|
13
|
-
globalThis.routes = []
|
|
14
|
-
/**
|
|
15
|
-
* @description - Used to keep track of the mode
|
|
16
|
-
*/
|
|
17
|
-
globalThis.mode = 'dev'
|
|
18
|
-
/**@usedby @transForm */
|
|
19
|
-
globalThis.isBuilding = false
|
|
20
|
-
globalThis.hasGenerated = []
|
|
21
|
-
/**
|
|
22
|
-
* @description - Used to keep track of the bundle size
|
|
23
|
-
*/
|
|
24
|
-
let bundleSize = 0
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
if(globalThis.mode === 'dev'){
|
|
28
|
-
Bun.spawn({
|
|
29
|
-
cwd: process.cwd() + '/node_modules/vaderjs/binaries/',
|
|
30
|
-
env: {
|
|
31
|
-
PWD: process.cwd(),
|
|
32
|
-
onExit: (code) => {
|
|
33
|
-
globalThis.isBuilding = false
|
|
34
|
-
globalThis.oneAndDone = true
|
|
35
|
-
}
|
|
36
|
-
},
|
|
37
|
-
cmd: ['node', 'generator.js'],
|
|
38
|
-
})
|
|
39
|
-
globalThis.generatorWs = new WebSocket(`ws://localhost:${3436}`)
|
|
40
|
-
globalThis.generatorWs.on('message', (message) => {
|
|
41
|
-
let data = JSON.parse(message.toString())
|
|
42
|
-
switch(true){
|
|
43
|
-
case data.type === 'done':
|
|
44
|
-
let file = data.file
|
|
45
|
-
globalThis.hasGenerated.push(file)
|
|
46
|
-
console.log('Generated', file)
|
|
47
|
-
break;
|
|
48
|
-
case data.type === 'error':
|
|
49
|
-
console.error(data.message)
|
|
50
|
-
break;
|
|
51
|
-
}
|
|
52
|
-
})
|
|
53
|
-
globalThis.generatorWs.on('connection', (ws) => {
|
|
54
|
-
console.log('Connected to generator...')
|
|
55
|
-
})
|
|
56
|
-
|
|
57
|
-
if(!globalThis.generatorWs.readyState === 1){
|
|
58
|
-
console.log('Generator is not ready...')
|
|
59
|
-
}
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { exec } from "child_process";
|
|
3
|
+
import fs from "fs";
|
|
4
|
+
globalThis.currentCommand = null;
|
|
5
|
+
globalThis.isRunning = false;
|
|
6
|
+
let vaderisInstalled = process.cwd() + "/node_modules/vaderjs/binaries/main.js";
|
|
7
|
+
if (!fs.existsSync(process.cwd() + "/_dev")) {
|
|
8
|
+
fs.mkdirSync(process.cwd() + "/_dev");
|
|
9
|
+
!fs.existsSync(process.cwd() + "/_dev/readme.md") && fs.writeFileSync(process.cwd() + "/_dev/readme.md", `This folder is used by vader.js to store important files, deletables include: Bun, Chrome - These should only be uninstalled if you need to reinstall them.`);
|
|
60
10
|
}
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* @description - variables used to generate arrays of paths recursively
|
|
64
|
-
*/
|
|
65
|
-
const glob = new Glob("/pages/**/**/*.{,tsx,js,jsx}", {absolute: true});
|
|
66
|
-
const vaderGlob = new Glob("/node_modules/vaderjs/runtime/**/**/*.{,tsx,js}", {absolute: true});
|
|
67
|
-
const srcGlob = new Glob("/src/**/**/*.{jsx,ts,tsx,js}", {absolute: true});
|
|
68
|
-
const publicGlob = new Glob("/public/**/**/*.{css,js,html,jpg,png,gif,svg,ico,video,webm,mp4,jpeg}", {absolute: true});
|
|
69
|
-
const distPages = new Glob("/dist/pages/**/**/*.{tsx,js,jsx}", {absolute: true})
|
|
70
|
-
const distSrc = new Glob("/dist/src/**/**/*.{tsx,js,jsx}", {absolute: true})
|
|
71
|
-
const distPublic = new Glob("/dist/public/**/**/*.{css,js,html,jpg,png,gif,svg,ico,video,webm,mp4,jpeg}", {absolute: true});
|
|
72
|
-
|
|
73
|
-
const router = new Bun.FileSystemRouter({
|
|
74
|
-
style: "nextjs",
|
|
75
|
-
dir: process.cwd() + '/pages',
|
|
76
|
-
origin: process.env.ORIGIN || "http://localhost:3000",
|
|
77
|
-
assetPrefix: "_next/static/"
|
|
78
|
-
});
|
|
79
|
-
/**
|
|
80
|
-
* @function handleReplaceMents
|
|
81
|
-
* @description - replaces data to be compatible with Vader.js
|
|
82
|
-
* @param {*} data
|
|
83
|
-
* @returns
|
|
84
|
-
*/
|
|
85
|
-
function handleReplaceMents(data){
|
|
86
|
-
data.split('\n').forEach((line, index)=>{
|
|
87
|
-
switch(true){
|
|
88
|
-
|
|
89
|
-
case line.includes('useReducer') && !line.includes('import'):
|
|
90
|
-
line = line.replaceAll(/\s+/g, " ");
|
|
91
|
-
|
|
92
|
-
let varTypereducer = line.split("=")[0].trim().split("[")[0].trim();
|
|
93
|
-
let keyreducer = line.split("=")[0].trim().split("[")[1].trim().split(",")[0].trim();
|
|
94
|
-
let setKeyreducer = line.split("=")[0].trim().split(",")[1].trim().replace("]", "");
|
|
95
|
-
let reducer = line.split("=")[1].split("useReducer(")[1];
|
|
96
|
-
|
|
97
|
-
let newStatereducer = `${varTypereducer} [${keyreducer}, ${setKeyreducer}] = this.useReducer('${keyreducer}', ${line.includes('=>') ? reducer + '=>{' : reducer}`;
|
|
98
|
-
|
|
99
|
-
data = data.replace(line, newStatereducer);
|
|
100
|
-
break
|
|
101
|
-
|
|
102
|
-
case line.includes('useState') && !line.includes('import'):
|
|
103
|
-
let varType = line.split("[")[0]
|
|
104
|
-
if (!line.split("=")[0].split(",")[1]) {
|
|
105
|
-
throw new Error('You forgot to value selector (useState) ' + ' at ' + `${file}:${string.split(line)[0].split('\n').length}`)
|
|
106
|
-
}
|
|
107
|
-
let key = line.split("=")[0].split(",")[0].trim().split('[')[1];
|
|
108
|
-
|
|
109
|
-
if (!line.split("=")[0].split(",")[1]) {
|
|
110
|
-
throw new Error('You forgot to add a setter (useState) ' + ' at ' + `${file}:${string.split(line)[0].split('\n').length}`)
|
|
111
|
-
}
|
|
112
|
-
let setKey = line.split("=")[0].split(",")[1].trim().replace("]", "");
|
|
113
|
-
key = key.replace("[", "").replace(",", "");
|
|
114
|
-
let valuestate = line.split("=")[1].split("useState(")[1];
|
|
115
|
-
|
|
116
|
-
let regex = /useState\((.*)\)/gs;
|
|
117
|
-
valuestate = valuestate.match(regex) ? valuestate.match(regex)[0].split("useState(")[1].split(")")[0].trim() : valuestate
|
|
118
|
-
let newState = `${varType} [${key}, ${setKey}] = this.useState('${key}', ${valuestate}`;
|
|
119
|
-
data = data.replace(line, newState);
|
|
120
|
-
break;
|
|
121
|
-
|
|
122
|
-
case line.includes("useRef") && !line.includes("import"):
|
|
123
|
-
line = line.trim();
|
|
124
|
-
let typeref = line.split(" ")[0]
|
|
125
11
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
let valueref = line.split("=")[1].split("useRef(")[1];
|
|
130
|
-
|
|
131
|
-
let newStateref = `${typeref} ${keyref} = this.useRef('${keyref}', ${valueref}`;
|
|
132
|
-
data = data.replace(line, newStateref);
|
|
133
|
-
case line.includes('.jsx') && line.includes('import') || line.includes('.tsx') && line.includes('import'):
|
|
134
|
-
let old = line
|
|
135
|
-
line = line.replace('.jsx', '.js')
|
|
136
|
-
line = line.replace('.tsx', '.js')
|
|
137
|
-
data = data.replace(old, line)
|
|
138
|
-
|
|
139
|
-
break;
|
|
140
|
-
}
|
|
141
|
-
})
|
|
142
|
-
|
|
143
|
-
data = data.replaceAll('jsxDEV', 'Vader.createElement')
|
|
144
|
-
data = data.replaceAll('jsx', 'Vader.createElement')
|
|
145
|
-
data = data.replaceAll('vaderjs/client', '/vader.js')
|
|
146
|
-
data = data.replaceAll('.tsx', '.js')
|
|
147
|
-
let reactImportMatch = data.match(/import React/g);
|
|
148
|
-
if(reactImportMatch){
|
|
149
|
-
let fullmatch = data.match(/import React from "react"/g);
|
|
150
|
-
if(fullmatch){
|
|
151
|
-
data = data.replaceAll('import React from "react"', '');
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
data = data.replaceAll('.ts', '.js')
|
|
155
|
-
|
|
156
|
-
// check if Vader is imported
|
|
157
|
-
let vaderImport = data.match(/import Vader/g);
|
|
158
|
-
if(!vaderImport){
|
|
159
|
-
data = `import Vader from "/vader.js";\n` + data;
|
|
160
|
-
}
|
|
161
|
-
return data;
|
|
12
|
+
if (!fs.existsSync(process.cwd() + "/_dev/vader.js")) {
|
|
13
|
+
console.log("Copying vader to dev folder....");
|
|
14
|
+
fs.copyFileSync(vaderisInstalled, process.cwd() + "/_dev/vader.js");
|
|
162
15
|
}
|
|
163
|
-
|
|
164
16
|
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
return 'image/png';
|
|
185
|
-
case 'gif':
|
|
186
|
-
return 'image/gif';
|
|
187
|
-
case 'svg':
|
|
188
|
-
return 'image/svg+xml';
|
|
189
|
-
case 'ico':
|
|
190
|
-
return 'image/x-icon';
|
|
191
|
-
default:
|
|
192
|
-
return 'text/html';
|
|
193
|
-
|
|
194
|
-
}
|
|
17
|
+
function checkIFBundleIsInstalled() {
|
|
18
|
+
if (fs.existsSync(process.cwd() + "/_dev/bun")) {
|
|
19
|
+
return new Promise((resolve, reject) => {
|
|
20
|
+
resolve(true);
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
return new Promise((resolve, reject) => {
|
|
24
|
+
exec("bun -v", (err, stdout, stderr) => {
|
|
25
|
+
if (err) {
|
|
26
|
+
reject(err);
|
|
27
|
+
}
|
|
28
|
+
if (stdout) {
|
|
29
|
+
resolve(`Bun.js is installed: ${stdout}`);
|
|
30
|
+
}
|
|
31
|
+
if (stderr) {
|
|
32
|
+
reject(`Bun.js is not installed: ${stderr}`);
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
});
|
|
195
36
|
}
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
/**
|
|
199
|
-
* @function Server
|
|
200
|
-
* @description - Creates a hmr development server
|
|
201
|
-
* @param {Number} port
|
|
202
|
-
*/
|
|
203
|
-
function Server(port){
|
|
204
|
-
Bun.serve({
|
|
205
|
-
port: port,
|
|
206
|
-
fetch(req, res){
|
|
207
|
-
const url = new URL(req.url);
|
|
208
|
-
const success = res.upgrade(req);
|
|
209
|
-
if(success){
|
|
210
|
-
return new Response('Connected', {
|
|
211
|
-
headers: {
|
|
212
|
-
"Content-Type": "text/html"
|
|
213
|
-
}
|
|
214
|
-
})
|
|
215
|
-
}
|
|
216
|
-
if(req.url.includes('.')){
|
|
217
|
-
return new Response(fs.readFileSync(process.cwd() + '/dist/' + url.pathname, 'utf8'), {
|
|
218
|
-
headers: {
|
|
219
|
-
"Content-Type": ContentType(req.url)
|
|
220
|
-
}
|
|
221
|
-
})
|
|
222
|
-
}
|
|
223
|
-
let matchedRoute = router.match(url.pathname);
|
|
224
|
-
if(matchedRoute){
|
|
225
|
-
let {filePath, kind, name, params, pathname, query,} = matchedRoute
|
|
226
|
-
let folder = url.pathname.split('/')[1]
|
|
227
|
-
let jsFile = filePath.split('pages/').pop().split('.').shift() + '.js'
|
|
228
|
-
let pageContent = fs.readFileSync(process.cwd() + '/dist/pages/' + folder + '/index.html', 'utf8')
|
|
229
|
-
globalThis.mode === 'dev' ? pageContent += `
|
|
230
|
-
<script type="module">
|
|
231
|
-
let ws = new WebSocket('ws://localhost:${port}');
|
|
232
|
-
ws.onmessage = async (e) => {
|
|
233
|
-
if(e.data === 'reload'){
|
|
234
|
-
window.location.reload()
|
|
235
|
-
console.log('Reloading...')
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
</script>
|
|
239
|
-
` : void 0
|
|
240
|
-
return new Response( pageContent, {
|
|
241
|
-
headers: {
|
|
242
|
-
"Content-Type": "text/html",
|
|
243
|
-
"X-Powered-By": "Vader.js v1.3.3"
|
|
244
|
-
}
|
|
245
|
-
})
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
return new Response('Not Found', {
|
|
249
|
-
status: 404,
|
|
250
|
-
headers: {
|
|
251
|
-
"Content-Type": "text/html"
|
|
252
|
-
}
|
|
253
|
-
})
|
|
254
|
-
},
|
|
255
|
-
websocket: {
|
|
256
|
-
open(ws){
|
|
257
|
-
clients.push(ws)
|
|
258
|
-
},
|
|
259
|
-
}
|
|
260
|
-
})
|
|
261
|
-
}
|
|
262
|
-
/**
|
|
263
|
-
* @function write
|
|
264
|
-
* @description - Writes data to a file
|
|
265
|
-
* @returns {void} 0
|
|
266
|
-
* @param {string} file
|
|
267
|
-
* @param {any} data
|
|
268
|
-
* @returns
|
|
269
|
-
*/
|
|
270
|
-
const write = (file, data) => {
|
|
271
|
-
try {
|
|
272
|
-
if(!fs.existsSync('./dist')){
|
|
273
|
-
fs.mkdirSync('./dist')
|
|
274
|
-
}
|
|
275
|
-
Bun.write(file, data);
|
|
276
|
-
} catch (error) {
|
|
277
|
-
console.error(error)
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
}
|
|
281
|
-
/**
|
|
282
|
-
* @function read
|
|
283
|
-
* @param {path} file
|
|
284
|
-
* @returns {Promise<string>}
|
|
285
|
-
*/
|
|
286
|
-
const read = async (file) => {
|
|
287
|
-
return await Bun.file(file).text();
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
/**
|
|
291
|
-
* @function generateProviderRoutes
|
|
292
|
-
* @description - Generates routes for hosting provders ie: vercel, cloudflare
|
|
293
|
-
* @returns {void} 0
|
|
294
|
-
*/
|
|
295
|
-
async function generateProviderRoutes(){
|
|
296
|
-
if(!config?.host?.provider){
|
|
297
|
-
console.warn('No provider found in vader.config.js ignoring route generation...')
|
|
298
|
-
return void 0;
|
|
299
|
-
}
|
|
300
|
-
let providerType = [{
|
|
301
|
-
provider: 'vercel',
|
|
302
|
-
file: 'vercel.json',
|
|
303
|
-
out: process.cwd() + '/vercel.json',
|
|
304
|
-
obj: {
|
|
305
|
-
rewrites:[]
|
|
306
|
-
}
|
|
307
|
-
},{
|
|
308
|
-
provider: 'cloudflare',
|
|
309
|
-
file:'_redirects',
|
|
310
|
-
out: 'dist/_redirects'
|
|
311
|
-
}]
|
|
312
37
|
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
fs.writeFileSync(provider.out, JSON.stringify({rewrites: prev}, null, 2))
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
})
|
|
353
|
-
provider.obj.rewrites = prev
|
|
354
|
-
write(provider.out, JSON.stringify(provider.obj, null, 2))
|
|
355
|
-
break;
|
|
356
|
-
case 'cloudflare':
|
|
357
|
-
console.warn('Cloudflare is not supported yet refer to their documentation for more information:https://developers.cloudflare.com/pages/configuration/redirects/')
|
|
358
|
-
break;
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
}
|
|
365
|
-
return void 0;
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
/**
|
|
369
|
-
* @function transform
|
|
370
|
-
* @description - Transforms the jsx files to js files based on file paths
|
|
371
|
-
*/
|
|
372
|
-
|
|
373
|
-
async function transForm(){
|
|
374
|
-
globalThis.isBuilding = true
|
|
375
|
-
router.reload()
|
|
376
|
-
for await (var file of glob.scan('.')) {
|
|
377
|
-
file = file.replace(/\\/g, '/');
|
|
378
|
-
let isBasePath = file.split('pages/')?.[1]?.split('/').length === 1;
|
|
379
|
-
let folder = file.split('pages/')?.[1]?.split('/').slice(0, -1).join('/') || null;
|
|
380
|
-
let route = isBasePath ? router.match('/') : router.match('/' + folder)
|
|
381
|
-
if(route){
|
|
382
|
-
let {filePath, kind, name, params, pathname, query,} = route
|
|
383
|
-
let data = await read(filePath);
|
|
384
|
-
try{
|
|
385
|
-
data = new Bun.Transpiler({loader: "tsx", target:"browser", }).transformSync(data);
|
|
386
|
-
}catch(e){
|
|
387
|
-
console.error(e)
|
|
388
|
-
}
|
|
389
|
-
let out = `./dist/pages/${isBasePath ? 'index.js' : folder + '/index.js'}`;
|
|
390
|
-
isBasePath ? folder = '/': null;
|
|
391
|
-
data = handleReplaceMents(data);
|
|
392
|
-
globalThis.routes.push({path: folder, file: out, isParam: kind === 'dynamic' ? true : false, params, query, pathname})
|
|
393
|
-
write(out, data);
|
|
394
|
-
bundleSize += data.length
|
|
38
|
+
function run() {
|
|
39
|
+
if (!fs.existsSync(process.cwd() + "/package.json")) {
|
|
40
|
+
fs.writeFileSync(process.cwd() + "/package.json", JSON.stringify({ name: "my_app", version: "1.0.0" }, null, 2));
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
let packageJson = JSON.parse(fs.readFileSync(process.cwd() + "/package.json").toString());
|
|
44
|
+
if (!packageJson.scripts) {
|
|
45
|
+
packageJson.scripts = {};
|
|
46
|
+
}
|
|
47
|
+
packageJson.scripts["dev"] = "bun run ./_dev/vader.js dev";
|
|
48
|
+
packageJson.scripts["build"] = "bun run ./_dev/vader.js build";
|
|
49
|
+
packageJson.scripts["start"] = "bun run ./_dev/vader.js start";
|
|
50
|
+
if (!packageJson.dependencies) {
|
|
51
|
+
packageJson.dependencies = {};
|
|
52
|
+
}
|
|
53
|
+
fs.writeFileSync(process.cwd() + "/package.json", JSON.stringify(packageJson, null, 2));
|
|
54
|
+
|
|
55
|
+
if (currentCommand) {
|
|
56
|
+
let child = exec(currentCommand);
|
|
57
|
+
child.stdout.pipe(process.stdout);
|
|
58
|
+
child.stderr.pipe(process.stderr);
|
|
59
|
+
child.on("exit", (code) => {
|
|
60
|
+
process.exit(code);
|
|
61
|
+
});
|
|
62
|
+
child.on("message", (message) => {
|
|
63
|
+
console.log(message.toString());
|
|
64
|
+
});
|
|
65
|
+
child.on("error", (err) => {
|
|
66
|
+
console.error(err);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
console.log(`
|
|
73
|
+
Vader.js is a reactive framework for building interactive applications for the web built ontop of bun.js!
|
|
395
74
|
|
|
75
|
+
Usage: npx vaderjs <command>
|
|
396
76
|
|
|
397
|
-
|
|
77
|
+
Commands:
|
|
398
78
|
|
|
399
|
-
|
|
79
|
+
vaderjs run dev -p <number> Start the development server
|
|
80
|
+
|
|
81
|
+
vaderjs run build Build the project to ./dist
|
|
82
|
+
|
|
83
|
+
vaderjs run start -p <number> Production Mode (default 3000 or process.env.PORT)
|
|
84
|
+
|
|
85
|
+
Learn more about vader: https://vader-js.pages.dev/
|
|
86
|
+
|
|
87
|
+
`);
|
|
88
|
+
}
|
|
400
89
|
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
90
|
+
function checkIFChromeIumIsInstalled() {
|
|
91
|
+
let platform = process.platform;
|
|
92
|
+
let findChrome = {
|
|
93
|
+
windows: `powershell -c "${process.cwd() + "\\node_modules\\vaderjs\\binaries\\win32\\check.ps1"}"`,
|
|
94
|
+
others: "/usr/bin/chromium-browser --version",
|
|
95
|
+
};
|
|
96
|
+
let installCommands = {
|
|
97
|
+
windows: `winget install Google.Chrome`,
|
|
98
|
+
others: "sudo apt-get install chromium-browser -y",
|
|
99
|
+
};
|
|
100
|
+
findChrome.windows = findChrome.windows.replace(/\n/g, " ");
|
|
101
|
+
let commandToRun = platform === "win32" ? findChrome.windows : findChrome.others;
|
|
102
|
+
|
|
103
|
+
return new Promise((resolve, reject) => {
|
|
104
|
+
if (fs.existsSync(process.cwd() + "/_dev/chrome")) {
|
|
105
|
+
resolve(true);
|
|
106
|
+
} else {
|
|
107
|
+
exec(commandToRun, (err, stdout, stderr) => {
|
|
108
|
+
let hasError = false;
|
|
109
|
+
if (err) {
|
|
110
|
+
console.log(err);
|
|
111
|
+
hasError = true;
|
|
112
|
+
console.log(`Attempting to install DEPENDENCY: ${platform === "win32" ? "Google Chrome" : "Chromium"}`);
|
|
404
113
|
}
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
let transpiler = new Bun.Transpiler({loader: "ts", target:"browser", });
|
|
409
|
-
let data = await read(file);
|
|
410
|
-
try {
|
|
411
|
-
data = transpiler.transformSync(data);
|
|
412
|
-
} catch (error) {
|
|
413
|
-
console.error(error)
|
|
414
|
-
}
|
|
415
|
-
file = file.replace('.ts', '.js')
|
|
416
|
-
let path = process.cwd() +'/dist/src/' + file.split('src/').pop()
|
|
417
|
-
write(path, data);
|
|
418
|
-
bundleSize += data.length
|
|
419
|
-
|
|
420
|
-
break;
|
|
421
|
-
|
|
422
|
-
case 'tsx':
|
|
423
|
-
let transpilerx = new Bun.Transpiler({loader: "tsx", target:"browser", });
|
|
424
|
-
let datax = await read(file);
|
|
425
|
-
try {
|
|
426
|
-
datax = transpilerx.transformSync(datax);
|
|
427
|
-
} catch (error) {
|
|
428
|
-
console.error(error)
|
|
429
|
-
}
|
|
430
|
-
datax = handleReplaceMents(datax);
|
|
431
|
-
file = file.replace('.tsx', '.js')
|
|
432
|
-
let pathx = process.cwd() +'/dist/src/' + file.split('src/').pop()
|
|
433
|
-
write(pathx, datax);
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
break;
|
|
437
|
-
case 'jsx':
|
|
438
|
-
let transpilerjx = new Bun.Transpiler({loader: "jsx", target:"browser", });
|
|
439
|
-
let datajx = await read(file);
|
|
440
|
-
try {
|
|
441
|
-
datajx = transpilerjx.transformSync(datajx);
|
|
442
|
-
} catch (error) {
|
|
443
|
-
console.error(error)
|
|
444
|
-
}
|
|
445
|
-
datajx = handleReplaceMents(datajx);
|
|
446
|
-
file = file.replace('.jsx', '.js')
|
|
447
|
-
let pathjx = process.cwd() +'/dist/src/' + file.split('src/').pop()
|
|
448
|
-
write(pathjx, datajx);
|
|
449
|
-
bundleSize += datajx.length
|
|
450
|
-
break;
|
|
114
|
+
if (stdout && !hasError) {
|
|
115
|
+
resolve(`${platform === "win32" ? "Google Chrome" : "Chromium"} is installed: ${stdout}`);
|
|
116
|
+
fs.writeFileSync(process.cwd() + "/_dev/chrome", `Installed: ${stdout}`);
|
|
451
117
|
}
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
let path = process.cwd() +'/pages/' + file.split('dist/pages/').pop()
|
|
472
|
-
path = path.replace('.js', config?.files?.mimeType || '.jsx')
|
|
473
|
-
|
|
474
|
-
if(!fs.existsSync(path)){
|
|
475
|
-
fs.unlinkSync(file)
|
|
476
|
-
}
|
|
477
|
-
|
|
478
|
-
}
|
|
479
|
-
|
|
480
|
-
for await( var file of distSrc.scan('.')){
|
|
481
|
-
file = file.replace(/\\/g, '/');
|
|
482
|
-
let path = process.cwd() +'/src/' + file.split('dist/src/').pop()
|
|
483
|
-
// if the file is a js file see if theirs a matching ts file
|
|
484
|
-
if(file.split('.').pop() === 'js'){
|
|
485
|
-
let tsFile = path.replace('.js', '.ts')
|
|
486
|
-
// if the ts file exists then the js file is valid else if not the js file exists then remove
|
|
487
|
-
switch(true){
|
|
488
|
-
case !fs.existsSync(tsFile):
|
|
489
|
-
// check if a tsx or jsx file exists
|
|
490
|
-
let tsxFile = path.replace('.js', '.tsx')
|
|
491
|
-
let jsxFile = path.replace('.js', '.jsx')
|
|
492
|
-
let tsfile = path.replace('.js', '.ts')
|
|
493
|
-
switch(true){
|
|
494
|
-
case fs.existsSync(tsxFile):
|
|
495
|
-
break;
|
|
496
|
-
case fs.existsSync(jsxFile):
|
|
497
|
-
break;
|
|
498
|
-
case fs.existsSync(tsfile):
|
|
499
|
-
break
|
|
500
|
-
default:
|
|
501
|
-
fs.unlinkSync(file)
|
|
502
|
-
break;
|
|
503
|
-
}
|
|
504
|
-
break;
|
|
505
|
-
case fs.existsSync(tsFile):
|
|
506
|
-
|
|
507
|
-
break;
|
|
508
|
-
}
|
|
509
|
-
}
|
|
510
|
-
}
|
|
511
|
-
|
|
512
|
-
for await( var file of distPublic.scan('.')){
|
|
513
|
-
file = file.replace(/\\/g, '/');
|
|
514
|
-
let path = process.cwd() +'/public/' + file.split('dist/public/').pop()
|
|
515
|
-
if(!fs.existsSync(path)){
|
|
516
|
-
fs.unlinkSync(file)
|
|
517
|
-
}
|
|
118
|
+
if (stderr) {
|
|
119
|
+
console.log(stderr);
|
|
120
|
+
console.log(`Installing DEPENDENCY: ${platform === "win32" ? "Google Chrome" : "Chromium"}`);
|
|
121
|
+
let installCommand = platform === "win32" ? installCommands.windows : installCommands.others;
|
|
122
|
+
return new Promise((resolve, reject) => {
|
|
123
|
+
exec(installCommand, (err, stdout, stderr) => {
|
|
124
|
+
if (err) {
|
|
125
|
+
reject(err);
|
|
126
|
+
}
|
|
127
|
+
if (stdout) {
|
|
128
|
+
resolve(`${platform === "win32" ? "Google Chrome" : "Chromium"} installed successfully: ${stdout}`);
|
|
129
|
+
fs.writeFileSync(process.cwd() + "/_dev/chrome", `Installed: ${stdout}`);
|
|
130
|
+
run();
|
|
131
|
+
}
|
|
132
|
+
if (stderr) {
|
|
133
|
+
reject(`${platform === "win32" ? "Google Chrome" : "Chromium"} failed to install: ${stderr}`);
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
});
|
|
518
137
|
}
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
/**
|
|
523
|
-
* @function organizeRoutes
|
|
524
|
-
* @description - Organizes routes that have param paths
|
|
525
|
-
*/
|
|
526
|
-
|
|
527
|
-
const organizeRoutes = () => {
|
|
528
|
-
// if path starts with the same path and is dynamic then they are the same route and push params to the same route
|
|
529
|
-
let newRoutes = []
|
|
530
|
-
routes.forEach((route) => {
|
|
531
|
-
let exists = routes.find((r) => r.path.startsWith(route.path) && r.isParam === true)
|
|
532
|
-
if(exists){
|
|
533
|
-
let b4Params = route.params
|
|
534
|
-
route.params = []
|
|
535
|
-
route.params.push(b4Params)
|
|
536
|
-
route.params.push( {
|
|
537
|
-
jsFile: '/pages/' + exists.path + '/index.js',
|
|
538
|
-
folder: '/pages/' + exists.path,
|
|
539
|
-
paramData:exists.params
|
|
540
|
-
}
|
|
541
|
-
)
|
|
542
|
-
route.query = exists.query
|
|
543
|
-
newRoutes.push(route)
|
|
544
|
-
}
|
|
545
|
-
else if(!exists && !route.isParam){
|
|
546
|
-
newRoutes.push(route)
|
|
547
|
-
|
|
548
|
-
}
|
|
549
|
-
//remove param route that matched
|
|
550
|
-
routes = routes.filter((r) => exists ? r.path !== exists.path : true)
|
|
551
|
-
|
|
552
|
-
})
|
|
553
|
-
globalThis.routes = newRoutes
|
|
138
|
+
});
|
|
554
139
|
}
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
if(globalThis.mode === 'dev' && !globalThis.oneAndDone || globalThis.mode === 'build'){
|
|
559
|
-
|
|
560
|
-
/**
|
|
561
|
-
* @description - create an html file for each route
|
|
562
|
-
*/
|
|
563
|
-
routes.forEach((r)=>{
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
globalThis.generatorWs.send(JSON.stringify({
|
|
567
|
-
type:'generate',
|
|
568
|
-
PWD: process.cwd(),
|
|
569
|
-
output: process.cwd() + '/dist/pages/' + r.path + '/index.html',
|
|
570
|
-
file: '/pages/' + r.path + '/index.js',
|
|
571
|
-
folder:'/pages/' + r.path,
|
|
572
|
-
params: JSON.stringify(r.params),
|
|
573
|
-
}))
|
|
574
|
-
|
|
575
|
-
})
|
|
576
|
-
let i = setInterval(() => {
|
|
577
|
-
if(hasGenerated.length === routes.length){
|
|
578
|
-
globalThis.generatorWs.send(JSON.stringify({
|
|
579
|
-
type:'done'
|
|
580
|
-
}))
|
|
581
|
-
globalThis.oneAndDone = true
|
|
582
|
-
clearInterval(i)
|
|
583
|
-
}
|
|
584
|
-
}, 1000)
|
|
585
|
-
}
|
|
586
|
-
generateProviderRoutes( )
|
|
587
|
-
globalThis.isBuilding = false
|
|
588
|
-
console.log(`Finished building ${Math.round(bundleSize / 1000)}kb`)
|
|
589
|
-
bundleSize = 0
|
|
590
|
-
return void 0;
|
|
591
|
-
|
|
140
|
+
});
|
|
592
141
|
}
|
|
593
|
-
let
|
|
142
|
+
let Commands = {
|
|
143
|
+
dev: `bun run dev`,
|
|
144
|
+
build: `bun run build`,
|
|
145
|
+
start: `bun run start`,
|
|
146
|
+
};
|
|
147
|
+
let port = process.argv.includes("-p") || process.argv.includes("--port") ? process.argv[process.argv.indexOf("-p") + 1] || process.argv[process.argv.indexOf("--port") + 1] || process.env.PORT || 3000 : process.env.PORT || 3000;
|
|
594
148
|
switch (true) {
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
onExit: (code) => {
|
|
617
|
-
console.log('Exited', code)
|
|
618
|
-
}
|
|
619
|
-
})
|
|
620
|
-
const ws = new WebSocket(`ws://localhost:${3434}`)
|
|
621
|
-
ws.on('open', () => {
|
|
622
|
-
console.log('Watching for changes...')
|
|
623
|
-
})
|
|
624
|
-
ws.on('message', (message) => {
|
|
625
|
-
message = JSON.parse(message.toString())
|
|
626
|
-
switch(true){
|
|
627
|
-
case message.type === 'change' && !globalThis.isBuilding:
|
|
628
|
-
console.log('Rebuilding...')
|
|
629
|
-
globalThis.clients.forEach((client) => {
|
|
630
|
-
client.send('reload')
|
|
631
|
-
})
|
|
632
|
-
transForm()
|
|
633
|
-
break;
|
|
634
|
-
case message.type === 'add' && !globalThis.isBuilding:
|
|
635
|
-
console.log('Rebuilding...')
|
|
636
|
-
globalThis.clients.forEach((client) => {
|
|
637
|
-
client.send('reload')
|
|
638
|
-
})
|
|
639
|
-
transForm()
|
|
640
|
-
break;
|
|
149
|
+
case process.argv.includes("dev") && !process.argv.includes("build") && !process.argv.includes("start"):
|
|
150
|
+
currentCommand = Commands.dev + (port ? ` -p ${port}` : "");
|
|
151
|
+
break;
|
|
152
|
+
case process.argv.includes("build") && !process.argv.includes("dev") && !process.argv.includes("start"):
|
|
153
|
+
currentCommand = Commands.build + (port ? ` -p ${port}` : "");
|
|
154
|
+
break;
|
|
155
|
+
case process.argv.includes("start") && !process.argv.includes("dev") && !process.argv.includes("build"):
|
|
156
|
+
currentCommand = Commands.start + (port ? ` -p ${port}` : "");
|
|
157
|
+
break;
|
|
158
|
+
default:
|
|
159
|
+
currentCommand = null;
|
|
160
|
+
break;
|
|
161
|
+
}
|
|
162
|
+
checkIFChromeIumIsInstalled()
|
|
163
|
+
.then((stdout) => {
|
|
164
|
+
if (stdout) {
|
|
165
|
+
checkIFBundleIsInstalled()
|
|
166
|
+
.then((stdout) => {
|
|
167
|
+
if (stdout && !isRunning) {
|
|
168
|
+
if (!fs.existsSync(process.cwd() + "/_dev/bun")) {
|
|
169
|
+
fs.writeFileSync(process.cwd() + "/_dev/bun", `Installed: ${stdout}`);
|
|
641
170
|
}
|
|
642
|
-
|
|
171
|
+
run();
|
|
172
|
+
globalThis.isRunning = true;
|
|
173
|
+
}
|
|
643
174
|
})
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
175
|
+
.catch(async (err) => {
|
|
176
|
+
console.log("Bun.js is not installed. Installing....");
|
|
177
|
+
let installScipt = {
|
|
178
|
+
windows: 'powershell -c "irm bun.sh/install.ps1|iex',
|
|
179
|
+
others: "curl -fsSL https://bun.sh/install.sh | bash",
|
|
180
|
+
};
|
|
181
|
+
let scriptotRun = process.platform === "win32" ? installScipt.windows : installScipt.others;
|
|
182
|
+
exec(scriptotRun, async (err, stdout, stderr) => {
|
|
183
|
+
if (err) {
|
|
184
|
+
console.log("Error installing bun.js");
|
|
185
|
+
process.exit(1);
|
|
186
|
+
}
|
|
187
|
+
if (stdout) {
|
|
188
|
+
if (!process.platform === "win32") {
|
|
189
|
+
await new Promise((resolve, reject) => {
|
|
190
|
+
console.log(`Adding bun.js to path...`);
|
|
191
|
+
let shell = null;
|
|
192
|
+
exec("source ~/.bashrc", (err, stdout, stderr) => {
|
|
193
|
+
if (err) {
|
|
194
|
+
console.log("Error installing bun.js");
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
if (stdout) {
|
|
198
|
+
run();
|
|
199
|
+
}
|
|
200
|
+
if (stderr) {
|
|
201
|
+
console.log("Error installing bun.js");
|
|
202
|
+
process.exit(1);
|
|
203
|
+
}
|
|
204
|
+
});
|
|
205
|
+
});
|
|
206
|
+
exec("chmod +x bun.sh/install.sh", (err, stdout, stderr) => {
|
|
207
|
+
if (err) {
|
|
208
|
+
console.log("Error installing bun.js");
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
if (stdout) {
|
|
212
|
+
console.log("Bun.js installed successfully");
|
|
213
|
+
run();
|
|
214
|
+
}
|
|
215
|
+
if (stderr) {
|
|
216
|
+
console.log("Error installing bun.js");
|
|
217
|
+
process.exit(1);
|
|
218
|
+
}
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
run();
|
|
222
|
+
}
|
|
223
|
+
});
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
})
|
|
227
|
+
.catch(async (err) => {
|
|
228
|
+
console.error(err);
|
|
229
|
+
process.exit(1);
|
|
230
|
+
});
|