vaderjs 2.0.4 → 2.0.6
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/main.js +78 -138
- package/package.json +1 -1
- package/bun.lockb +0 -0
package/main.js
CHANGED
|
@@ -5,16 +5,8 @@ import { Glob } from 'bun'
|
|
|
5
5
|
const args = Bun.argv.slice(2)
|
|
6
6
|
globalThis.isBuilding = false;
|
|
7
7
|
import fs from 'fs'
|
|
8
|
-
import { platform } from 'os'
|
|
9
8
|
import path from 'path'
|
|
10
9
|
|
|
11
|
-
let bunPath = 'bun'; // Default for Linux/Mac
|
|
12
|
-
if (platform() === 'win32') {
|
|
13
|
-
bunPath = 'bun'; // Bun path for Windows
|
|
14
|
-
} else {
|
|
15
|
-
bunPath = path.resolve(process.env.HOME || process.env.USERPROFILE, '.bun', 'bin', 'bun');
|
|
16
|
-
}
|
|
17
|
-
|
|
18
10
|
|
|
19
11
|
if (!fs.existsSync(process.cwd() + '/app') && !args.includes('init')) {
|
|
20
12
|
console.error(`App directory not found in ${process.cwd()}/app`)
|
|
@@ -29,21 +21,21 @@ if (!fs.existsSync(process.cwd() + '/src')) {
|
|
|
29
21
|
if (!fs.existsSync(process.cwd() + '/vader.config.ts')) {
|
|
30
22
|
fs.writeFileSync(process.cwd() + '/vader.config.ts',
|
|
31
23
|
`import defineConfig from 'vaderjs/config'
|
|
32
|
-
export default
|
|
33
|
-
|
|
34
|
-
|
|
24
|
+
export default defineConfig({
|
|
25
|
+
port: 8080,
|
|
26
|
+
host_provider: 'apache'
|
|
35
27
|
})`)
|
|
36
28
|
}
|
|
37
29
|
var config = require(process.cwd() + '/vader.config.ts').default
|
|
38
30
|
const mode = args.includes('dev') ? 'development' : args.includes('prod') || args.includes('build') ? 'production' : args.includes('init') ? 'init' : args.includes('serve') ? 'serve' : null;
|
|
39
31
|
if (!mode) {
|
|
40
32
|
console.log(`
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
33
|
+
Usage:
|
|
34
|
+
bun vaderjs serve - Start the server
|
|
35
|
+
bun vaderjs dev - Start development server output in dist/
|
|
36
|
+
bun vaderjs prod - Build for production output in dist/
|
|
37
|
+
bun vaderjs init - Initialize a new vaderjs project
|
|
38
|
+
`)
|
|
47
39
|
process.exit(1)
|
|
48
40
|
}
|
|
49
41
|
|
|
@@ -60,11 +52,11 @@ if (mode === 'init') {
|
|
|
60
52
|
|
|
61
53
|
console.log(
|
|
62
54
|
`VaderJS - v${require(process.cwd() + '/node_modules/vaderjs/package.json').version} 🚀
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
55
|
+
Mode: ${mode}
|
|
56
|
+
SSR: ${require(process.cwd() + '/vader.config.ts').default.ssr ? 'Enabled' : 'Disabled'}
|
|
57
|
+
PORT: ${require(process.cwd() + '/vader.config.ts').default.port || 8080}
|
|
58
|
+
${mode == 'serve' ? `SSL: ${require(process.cwd() + '/vader.config.ts').default?.ssl?.enabled ? 'Enabled' : 'Disabled'} ` : ``}
|
|
59
|
+
`
|
|
68
60
|
)
|
|
69
61
|
|
|
70
62
|
|
|
@@ -83,16 +75,15 @@ if (!fs.existsSync(process.cwd() + '/jsconfig.json')) {
|
|
|
83
75
|
await Bun.write(process.cwd() + '/jsconfig.json', JSON.stringify(json, null, 4))
|
|
84
76
|
}
|
|
85
77
|
|
|
86
|
-
|
|
78
|
+
var bindes = []
|
|
87
79
|
var fnmap = []
|
|
88
80
|
const vader = {
|
|
89
|
-
isDev: mode === 'development',
|
|
90
81
|
onFileChange: (file, cb) => {
|
|
91
82
|
fs.watch(file, cb)
|
|
92
83
|
},
|
|
93
84
|
runCommand: (cmd) => {
|
|
94
85
|
return new Promise((resolve, reject) => {
|
|
95
|
-
|
|
86
|
+
Bun.spawn(cmd, {
|
|
96
87
|
stdout: 'inherit',
|
|
97
88
|
cwd: process.cwd(),
|
|
98
89
|
onExit({ exitCode: code }) {
|
|
@@ -104,11 +95,6 @@ const vader = {
|
|
|
104
95
|
}
|
|
105
96
|
})
|
|
106
97
|
|
|
107
|
-
setTimeout(() => {
|
|
108
|
-
c.kill()
|
|
109
|
-
reject()
|
|
110
|
-
}, 5000)
|
|
111
|
-
|
|
112
98
|
|
|
113
99
|
})
|
|
114
100
|
},
|
|
@@ -119,7 +105,6 @@ const vader = {
|
|
|
119
105
|
},
|
|
120
106
|
injectHTML: (html) => {
|
|
121
107
|
bindes.push(html)
|
|
122
|
-
globalThis.bindes = bindes
|
|
123
108
|
},
|
|
124
109
|
}
|
|
125
110
|
const handleReplacements = (code) => {
|
|
@@ -142,10 +127,10 @@ const handleReplacements = (code) => {
|
|
|
142
127
|
url = url.replace(/\\/g, '/')
|
|
143
128
|
if (!bindes.includes(`<link rel="stylesheet" href="${url}">`)) {
|
|
144
129
|
bindes.push(`
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
130
|
+
<style>
|
|
131
|
+
${fs.readFileSync(p, 'utf-8')}
|
|
132
|
+
</style>
|
|
133
|
+
`)
|
|
149
134
|
}
|
|
150
135
|
} catch (error) {
|
|
151
136
|
console.error(error)
|
|
@@ -175,9 +160,8 @@ const handleReplacements = (code) => {
|
|
|
175
160
|
line = b4
|
|
176
161
|
}
|
|
177
162
|
if (!hasImport && line.includes('useRef')) {
|
|
178
|
-
line = line.replace(' ', '')
|
|
179
163
|
let b4 = line
|
|
180
|
-
let key = line.split('
|
|
164
|
+
let key = line.split(' ')[1].split('=')[0]
|
|
181
165
|
b4 = line.replace('useRef(', `this.useRef('${key}',`)
|
|
182
166
|
line = b4
|
|
183
167
|
}
|
|
@@ -188,14 +172,12 @@ const handleReplacements = (code) => {
|
|
|
188
172
|
return c
|
|
189
173
|
}
|
|
190
174
|
|
|
191
|
-
|
|
192
|
-
fs.mkdirSync(process.cwd() + '/dev', { recursive: true })
|
|
193
|
-
fs.copyFileSync(require.resolve('vaderjs/bundler/index.js'), process.cwd() + '/dev/bundler.js')
|
|
194
|
-
}
|
|
175
|
+
|
|
195
176
|
let start = Date.now()
|
|
196
177
|
async function generateApp() {
|
|
197
178
|
globalThis.isBuilding = true;
|
|
198
179
|
console.log(ansiColors.green('Building...'))
|
|
180
|
+
console.log(`Starting build at ${new Date().toLocaleTimeString()}`)
|
|
199
181
|
let plugins = config.plugins || []
|
|
200
182
|
for (let plugin of plugins) {
|
|
201
183
|
if (plugin.onBuildStart) {
|
|
@@ -219,43 +201,24 @@ async function generateApp() {
|
|
|
219
201
|
|
|
220
202
|
let r = routes.routes[route]
|
|
221
203
|
let code = await Bun.file(r).text()
|
|
222
|
-
code = handleReplacements(code)
|
|
223
204
|
let size = code.length / 1024
|
|
224
205
|
r = r.replace(process.cwd().replace(/\\/g, '/') + '/app', '')
|
|
225
|
-
|
|
206
|
+
var beforeR = r
|
|
207
|
+
r = r.replace('.jsx', '.js').replace('.tsx', '.js')
|
|
226
208
|
fs.mkdirSync(path.join(process.cwd() + '/dist', path.dirname(r)), { recursive: true })
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
// dont return
|
|
237
|
-
|
|
238
|
-
fs.writeFileSync(
|
|
239
|
-
process.cwd() + '/dist/' + path.dirname(r) + '/' + path.basename(r),
|
|
240
|
-
`
|
|
241
|
-
let route = window.location.pathname.split('/').filter(Boolean)
|
|
242
|
-
let params = {
|
|
243
|
-
// get index tehn do route[index]
|
|
244
|
-
${Object.keys(params).map((param, i) => {
|
|
245
|
-
if (paramIndexes[i] !== -1) {
|
|
246
|
-
var r_copy = r;
|
|
247
|
-
r_copy = r_copy.split('/').filter(Boolean)
|
|
248
|
-
var index = paramIndexes[i] - 1
|
|
249
|
-
return `${param}: route[${index}]`
|
|
250
|
-
}
|
|
251
|
-
}).join(',\n')}
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
\n${code}
|
|
255
|
-
`
|
|
256
|
-
);
|
|
209
|
+
fs.writeFileSync(process.cwd() + '/dist/' + path.dirname(r) + '/' + path.basename(r), `
|
|
210
|
+
let route = window.location.pathname.split('/').filter(v => v !== '')
|
|
211
|
+
let params = {
|
|
212
|
+
${Object.keys(routes.match(route).params || {}).length > 0 ? Object.keys(routes.match(route).params || {}).map(p => {
|
|
213
|
+
return `${p}: route[${Object.keys(routes.match(route).params).indexOf(p) + Object.keys(routes.match(route).params).length}]`
|
|
214
|
+
}).join(',') : ""}
|
|
215
|
+
}
|
|
216
|
+
\n${code}
|
|
217
|
+
`)
|
|
257
218
|
fs.mkdirSync(process.cwd() + '/dev', { recursive: true })
|
|
258
|
-
|
|
219
|
+
if (!fs.existsSync(process.cwd() + '/dev/bundler.js')) {
|
|
220
|
+
fs.copyFileSync(require.resolve('vaderjs/bundler/index.js'), process.cwd() + '/dev/bundler.js')
|
|
221
|
+
}
|
|
259
222
|
|
|
260
223
|
if (!fs.existsSync(process.cwd() + '/dev/readme.md')) {
|
|
261
224
|
fs.writeFileSync(process.cwd() + '/dev/readme.md', `# Please do not edit the bundler.js file in the dev directory. This file is automatically generated by the bundler. \n\n`)
|
|
@@ -264,32 +227,37 @@ async function generateApp() {
|
|
|
264
227
|
fs.writeFileSync(process.cwd() + '/dist/src/vader/index.js', await new Bun.Transpiler({
|
|
265
228
|
loader: 'ts',
|
|
266
229
|
}).transformSync(await Bun.file(require.resolve('vaderjs')).text()))
|
|
230
|
+
|
|
267
231
|
Bun.spawn({
|
|
268
|
-
cmd: [
|
|
232
|
+
cmd: ['bun', 'run', './dev/bundler.js'],
|
|
269
233
|
cwd: process.cwd(),
|
|
270
234
|
stdout: 'inherit',
|
|
271
235
|
env: {
|
|
272
|
-
ENTRYPOINT: path.join(process.cwd()
|
|
273
|
-
ROOT:
|
|
236
|
+
ENTRYPOINT: path.join(process.cwd() + '/dist/' + path.dirname(r) + '/' + path.basename(r)),
|
|
237
|
+
ROOT: process.cwd() + '/app/',
|
|
274
238
|
OUT: path.dirname(r),
|
|
275
|
-
file:
|
|
239
|
+
file: process.cwd() + '/dist/' + path.dirname(r) + '/' + path.basename(r),
|
|
276
240
|
DEV: mode === 'development',
|
|
277
241
|
size,
|
|
278
242
|
bindes: bindes.join('\n'),
|
|
243
|
+
isTs: beforeR.endsWith(".tsx"),
|
|
279
244
|
filePath: r,
|
|
245
|
+
|
|
246
|
+
isJsx: beforeR.endsWith('.tsx') || beforeR.endsWith(".jsx"),
|
|
280
247
|
isAppFile: true,
|
|
281
|
-
|
|
282
|
-
INPUT: `../app/${r.replace('.js', '.jsx').replace('.tsx', '.js')}`,
|
|
248
|
+
INPUT: `../app/${beforeR}`,
|
|
283
249
|
},
|
|
284
250
|
onExit({ exitCode: code }) {
|
|
285
251
|
if (code === 0) {
|
|
286
|
-
bindes = []
|
|
287
|
-
|
|
252
|
+
bindes = []
|
|
253
|
+
console.log(`Built ${r} in ${Date.now() - start}ms`)
|
|
254
|
+
resolve()
|
|
288
255
|
} else {
|
|
289
|
-
reject()
|
|
256
|
+
reject()
|
|
290
257
|
}
|
|
291
|
-
}
|
|
292
|
-
})
|
|
258
|
+
}
|
|
259
|
+
})
|
|
260
|
+
|
|
293
261
|
})
|
|
294
262
|
|
|
295
263
|
switch (host_provider) {
|
|
@@ -329,7 +297,6 @@ async function generateApp() {
|
|
|
329
297
|
await plugin.onBuildFinish(vader)
|
|
330
298
|
}
|
|
331
299
|
}
|
|
332
|
-
|
|
333
300
|
})
|
|
334
301
|
|
|
335
302
|
|
|
@@ -352,15 +319,15 @@ function handleFiles() {
|
|
|
352
319
|
var file = i
|
|
353
320
|
fs.mkdirSync(path.join(process.cwd() + '/dist', path.dirname(file)), { recursive: true })
|
|
354
321
|
// turn jsx to js
|
|
355
|
-
if (file.
|
|
322
|
+
if (file.endsWith('.jsx') || file.endsWith('.tsx')) {
|
|
356
323
|
let code = await Bun.file(file).text()
|
|
357
324
|
|
|
358
325
|
code = handleReplacements(code)
|
|
359
|
-
|
|
326
|
+
var url = file
|
|
360
327
|
file = file.replace('.jsx', '.js').replace('.tsx', '.js')
|
|
361
328
|
fs.writeFileSync(path.join(process.cwd() + '/dist', file.replace('.jsx', '.js').replace('.tsx', '.js')), code)
|
|
362
329
|
await Bun.spawn({
|
|
363
|
-
cmd: [
|
|
330
|
+
cmd: ['bun', 'run', './dev/bundler.js'],
|
|
364
331
|
cwd: process.cwd(),
|
|
365
332
|
stdout: 'inherit',
|
|
366
333
|
env: {
|
|
@@ -372,8 +339,9 @@ function handleFiles() {
|
|
|
372
339
|
DEV: mode === 'development',
|
|
373
340
|
size: code.length / 1024,
|
|
374
341
|
filePath: file.replace('.jsx', '.js'),
|
|
375
|
-
|
|
376
|
-
|
|
342
|
+
isJsx: url.endsWith('.tsx') || url.endsWith(".jsx"),
|
|
343
|
+
isAppFile: false,
|
|
344
|
+
INPUT: path.join(process.cwd(), url),
|
|
377
345
|
},
|
|
378
346
|
onExit({ exitCode: code }) {
|
|
379
347
|
if (code === 0) {
|
|
@@ -383,13 +351,13 @@ function handleFiles() {
|
|
|
383
351
|
}
|
|
384
352
|
}
|
|
385
353
|
})
|
|
386
|
-
} else if (file.
|
|
354
|
+
} else if (file.endsWith('.ts')) {
|
|
387
355
|
let code = await Bun.file(file).text()
|
|
388
356
|
code = handleReplacements(code)
|
|
389
357
|
file = file.replace('.ts', '.js')
|
|
390
358
|
fs.writeFileSync(path.join(process.cwd() + '/dist', file.replace('.ts', '.js')), code)
|
|
391
359
|
await Bun.spawn({
|
|
392
|
-
cmd: [
|
|
360
|
+
cmd: ['bun', 'run', './dev/bundler.js'],
|
|
393
361
|
cwd: process.cwd(),
|
|
394
362
|
stdout: 'inherit',
|
|
395
363
|
env: {
|
|
@@ -424,8 +392,8 @@ function handleFiles() {
|
|
|
424
392
|
globalThis.clients = []
|
|
425
393
|
|
|
426
394
|
if (mode === 'development') {
|
|
427
|
-
await generateApp()
|
|
428
395
|
await handleFiles()
|
|
396
|
+
await generateApp()
|
|
429
397
|
const watcher = fs.watch(path.join(process.cwd() + '/'), { recursive: true })
|
|
430
398
|
let isBuilding = false; // Flag to track build status
|
|
431
399
|
|
|
@@ -479,14 +447,13 @@ if (mode === 'development') {
|
|
|
479
447
|
else if (mode == 'production') {
|
|
480
448
|
await handleFiles()
|
|
481
449
|
await generateApp()
|
|
482
|
-
|
|
483
|
-
console.log(`Build complete in ${Date.now() - start}ms at ${new Date().toLocaleTimeString()}`);
|
|
484
450
|
}
|
|
485
451
|
else {
|
|
486
452
|
if (isBuilding) console.log(`Build complete in ${Date.now() - start}ms at ${new Date().toLocaleTimeString()}`);
|
|
487
453
|
|
|
488
454
|
}
|
|
489
455
|
|
|
456
|
+
|
|
490
457
|
if (mode == 'development' || mode == 'serve') {
|
|
491
458
|
let server = Bun.serve({
|
|
492
459
|
port: port || 8080,
|
|
@@ -527,56 +494,29 @@ if (mode == 'development' || mode == 'serve') {
|
|
|
527
494
|
style: 'nextjs'
|
|
528
495
|
})
|
|
529
496
|
router.reload()
|
|
530
|
-
let route = router.match(url.pathname)
|
|
497
|
+
let route = router.match(url.pathname)
|
|
531
498
|
if (!route) {
|
|
532
499
|
return new Response('Not found', { status: 404 })
|
|
533
500
|
}
|
|
534
501
|
let p = route.pathname;
|
|
535
502
|
let base = path.dirname(route.filePath)
|
|
536
503
|
base = base.replace(/\\/g, '/')
|
|
537
|
-
base = base.replace(path.join(process.cwd() + '/app').replace(/\\/g, '/'), '')
|
|
538
|
-
base = base.replace(/\\/g, '/').replace(
|
|
539
|
-
base = process.cwd() +
|
|
540
|
-
if (!fs.existsSync(path.join(base, 'index.html'))) {
|
|
541
|
-
return new Response(`
|
|
542
|
-
<html>
|
|
543
|
-
<head>
|
|
544
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
545
|
-
<meta http-equiv="refresh" content="5">
|
|
546
|
-
</head>
|
|
547
|
-
<body>
|
|
548
|
-
<p>Rerouting to display changes from server</p>
|
|
549
|
-
</body>
|
|
550
|
-
`, {
|
|
551
|
-
headers: {
|
|
552
|
-
'Content-Type': 'text/html',
|
|
553
|
-
'Cache-Control': 'no-cache'
|
|
554
|
-
}
|
|
555
|
-
})
|
|
556
|
-
}
|
|
504
|
+
base = base.replace(path.join(process.cwd() + '/app').replace(/\\/g, '/'), '');
|
|
505
|
+
base = base.replace(/\\/g, '/').replace(/\/app(\/|$)/, '/dist$1');
|
|
506
|
+
base = process.cwd() + '/dist/' + base;
|
|
557
507
|
let data = await Bun.file(path.join(base, 'index.html')).text()
|
|
558
508
|
if (mode == "development") {
|
|
559
509
|
return new Response(data + `
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
}
|
|
571
|
-
|
|
572
|
-
ws.onclose = () => {
|
|
573
|
-
// try to reconnect
|
|
574
|
-
console.log('Reconnecting to hmr server')
|
|
575
|
-
ws = new WebSocket(\`\${location.protocol === 'https:' ? 'wss' : 'ws'}://\${location.host}\`)
|
|
576
|
-
}
|
|
577
|
-
|
|
578
|
-
</script>
|
|
579
|
-
`, {
|
|
510
|
+
<script>
|
|
511
|
+
let ws = new WebSocket('ws://localhost:${server.port}')
|
|
512
|
+
ws.onmessage = (e) => {
|
|
513
|
+
if(e.data === 'reload'){
|
|
514
|
+
console.log('Reloading to display changes from server')
|
|
515
|
+
window.location.reload()
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
</script>
|
|
519
|
+
`, {
|
|
580
520
|
headers: {
|
|
581
521
|
'Content-Type': 'text/html'
|
|
582
522
|
}
|
|
@@ -593,4 +533,4 @@ if (mode == 'development' || mode == 'serve') {
|
|
|
593
533
|
})
|
|
594
534
|
|
|
595
535
|
console.log(ansiColors.green('Server started at http://localhost:' + port || 8080))
|
|
596
|
-
}
|
|
536
|
+
}
|
package/package.json
CHANGED
package/bun.lockb
DELETED
|
Binary file
|