vaderjs 2.0.5 → 2.0.7
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 +104 -37
- package/package.json +1 -1
- package/bun.lockb +0 -0
package/main.js
CHANGED
|
@@ -4,9 +4,18 @@ import ansiColors from 'ansi-colors'
|
|
|
4
4
|
import { Glob } from 'bun'
|
|
5
5
|
const args = Bun.argv.slice(2)
|
|
6
6
|
globalThis.isBuilding = false;
|
|
7
|
-
import fs from 'fs'
|
|
7
|
+
import fs from 'fs'
|
|
8
|
+
import { platform } from 'os'
|
|
8
9
|
import path from 'path'
|
|
9
10
|
|
|
11
|
+
let bunPath = 'bun'; // Default for Linux/Mac
|
|
12
|
+
|
|
13
|
+
if (platform() === 'win32') {
|
|
14
|
+
bunPath ='bun'; // Bun path for Windows
|
|
15
|
+
} else {
|
|
16
|
+
bunPath = path.resolve(process.env.HOME || process.env.USERPROFILE, '.bun', 'bin', 'bun');
|
|
17
|
+
}
|
|
18
|
+
|
|
10
19
|
|
|
11
20
|
if (!fs.existsSync(process.cwd() + '/app') && !args.includes('init')) {
|
|
12
21
|
console.error(`App directory not found in ${process.cwd()}/app`)
|
|
@@ -75,15 +84,16 @@ if (!fs.existsSync(process.cwd() + '/jsconfig.json')) {
|
|
|
75
84
|
await Bun.write(process.cwd() + '/jsconfig.json', JSON.stringify(json, null, 4))
|
|
76
85
|
}
|
|
77
86
|
|
|
78
|
-
|
|
87
|
+
globalThis.bindes = []
|
|
79
88
|
var fnmap = []
|
|
80
89
|
const vader = {
|
|
90
|
+
isDev: mode === 'development',
|
|
81
91
|
onFileChange: (file, cb) => {
|
|
82
92
|
fs.watch(file, cb)
|
|
83
93
|
},
|
|
84
94
|
runCommand: (cmd) => {
|
|
85
95
|
return new Promise((resolve, reject) => {
|
|
86
|
-
|
|
96
|
+
let c = Bun.spawn(cmd, {
|
|
87
97
|
stdout: 'inherit',
|
|
88
98
|
cwd: process.cwd(),
|
|
89
99
|
onExit({ exitCode: code }) {
|
|
@@ -95,6 +105,11 @@ const vader = {
|
|
|
95
105
|
}
|
|
96
106
|
})
|
|
97
107
|
|
|
108
|
+
setTimeout(() => {
|
|
109
|
+
c.kill()
|
|
110
|
+
reject()
|
|
111
|
+
}, 5000)
|
|
112
|
+
|
|
98
113
|
|
|
99
114
|
})
|
|
100
115
|
},
|
|
@@ -105,6 +120,7 @@ const vader = {
|
|
|
105
120
|
},
|
|
106
121
|
injectHTML: (html) => {
|
|
107
122
|
bindes.push(html)
|
|
123
|
+
globalThis.bindes = bindes
|
|
108
124
|
},
|
|
109
125
|
}
|
|
110
126
|
const handleReplacements = (code) => {
|
|
@@ -160,8 +176,9 @@ const handleReplacements = (code) => {
|
|
|
160
176
|
line = b4
|
|
161
177
|
}
|
|
162
178
|
if (!hasImport && line.includes('useRef')) {
|
|
179
|
+
line = line.replace(' ', '')
|
|
163
180
|
let b4 = line
|
|
164
|
-
let key = line.split('
|
|
181
|
+
let key = line.split('=')[0].split(' ').filter(Boolean)[1]
|
|
165
182
|
b4 = line.replace('useRef(', `this.useRef('${key}',`)
|
|
166
183
|
line = b4
|
|
167
184
|
}
|
|
@@ -172,12 +189,14 @@ const handleReplacements = (code) => {
|
|
|
172
189
|
return c
|
|
173
190
|
}
|
|
174
191
|
|
|
175
|
-
|
|
192
|
+
if (!fs.existsSync(process.cwd() + '/dev/bundler.js')) {
|
|
193
|
+
fs.mkdirSync(process.cwd() + '/dev', { recursive: true })
|
|
194
|
+
fs.copyFileSync(require.resolve('vaderjs/bundler/index.js'), process.cwd() + '/dev/bundler.js')
|
|
195
|
+
}
|
|
176
196
|
let start = Date.now()
|
|
177
197
|
async function generateApp() {
|
|
178
198
|
globalThis.isBuilding = true;
|
|
179
|
-
console.log(ansiColors.green('Building...'))
|
|
180
|
-
console.log(`Starting build at ${new Date().toLocaleTimeString()}`)
|
|
199
|
+
console.log(ansiColors.green('Building...'))
|
|
181
200
|
let plugins = config.plugins || []
|
|
182
201
|
for (let plugin of plugins) {
|
|
183
202
|
if (plugin.onBuildStart) {
|
|
@@ -206,19 +225,38 @@ async function generateApp() {
|
|
|
206
225
|
r = r.replace(process.cwd().replace(/\\/g, '/') + '/app', '')
|
|
207
226
|
r = r.replace('.jsx', '.js').replace('.tsx', '.js')
|
|
208
227
|
fs.mkdirSync(path.join(process.cwd() + '/dist', path.dirname(r)), { recursive: true })
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
228
|
+
let params = routes.match(route).params || {}
|
|
229
|
+
let base = routes.match(route)
|
|
230
|
+
let paramIndexes = []
|
|
231
|
+
for (let param in params) {
|
|
232
|
+
let routes = base.pathname.split('/')
|
|
233
|
+
let index = routes.indexOf('[' + param + ']')
|
|
234
|
+
paramIndexes.push(index)
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
// dont return
|
|
238
|
+
|
|
239
|
+
fs.writeFileSync(
|
|
240
|
+
process.cwd() + '/dist/' + path.dirname(r) + '/' + path.basename(r),
|
|
241
|
+
`
|
|
242
|
+
let route = window.location.pathname.split('/').filter(Boolean)
|
|
243
|
+
let params = {
|
|
244
|
+
// get index tehn do route[index]
|
|
245
|
+
${Object.keys(params).map((param, i) => {
|
|
246
|
+
if (paramIndexes[i] !== -1) {
|
|
247
|
+
var r_copy = r;
|
|
248
|
+
r_copy = r_copy.split('/').filter(Boolean)
|
|
249
|
+
var index = paramIndexes[i] - 1
|
|
250
|
+
return `${param}: route[${index}]`
|
|
251
|
+
}
|
|
252
|
+
}).join(',\n')}
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
\n${code}
|
|
256
|
+
`
|
|
257
|
+
);
|
|
218
258
|
fs.mkdirSync(process.cwd() + '/dev', { recursive: true })
|
|
219
|
-
|
|
220
|
-
fs.copyFileSync(require.resolve('vaderjs/bundler/index.js'), process.cwd() + '/dev/bundler.js')
|
|
221
|
-
}
|
|
259
|
+
|
|
222
260
|
|
|
223
261
|
if (!fs.existsSync(process.cwd() + '/dev/readme.md')) {
|
|
224
262
|
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`)
|
|
@@ -228,14 +266,14 @@ async function generateApp() {
|
|
|
228
266
|
loader: 'ts',
|
|
229
267
|
}).transformSync(await Bun.file(require.resolve('vaderjs')).text()))
|
|
230
268
|
Bun.spawn({
|
|
231
|
-
cmd: [
|
|
269
|
+
cmd: [bunPath, 'run', './dev/bundler.js'] ,
|
|
232
270
|
cwd: process.cwd(),
|
|
233
271
|
stdout: 'inherit',
|
|
234
272
|
env: {
|
|
235
|
-
ENTRYPOINT: path.join(process.cwd()
|
|
236
|
-
ROOT: process.cwd()
|
|
273
|
+
ENTRYPOINT: path.join(process.cwd(), 'dist', path.dirname(r), path.basename(r)),
|
|
274
|
+
ROOT: path.join(process.cwd(), 'app/'),
|
|
237
275
|
OUT: path.dirname(r),
|
|
238
|
-
file: process.cwd()
|
|
276
|
+
file: path.join(process.cwd(), 'dist', path.dirname(r), path.basename(r)),
|
|
239
277
|
DEV: mode === 'development',
|
|
240
278
|
size,
|
|
241
279
|
bindes: bindes.join('\n'),
|
|
@@ -246,15 +284,13 @@ async function generateApp() {
|
|
|
246
284
|
},
|
|
247
285
|
onExit({ exitCode: code }) {
|
|
248
286
|
if (code === 0) {
|
|
249
|
-
bindes = []
|
|
250
|
-
|
|
251
|
-
resolve()
|
|
287
|
+
bindes = [];
|
|
288
|
+
resolve();
|
|
252
289
|
} else {
|
|
253
|
-
reject()
|
|
290
|
+
reject();
|
|
254
291
|
}
|
|
255
|
-
}
|
|
256
|
-
})
|
|
257
|
-
|
|
292
|
+
},
|
|
293
|
+
});
|
|
258
294
|
})
|
|
259
295
|
|
|
260
296
|
switch (host_provider) {
|
|
@@ -294,6 +330,7 @@ async function generateApp() {
|
|
|
294
330
|
await plugin.onBuildFinish(vader)
|
|
295
331
|
}
|
|
296
332
|
}
|
|
333
|
+
|
|
297
334
|
})
|
|
298
335
|
|
|
299
336
|
|
|
@@ -301,8 +338,7 @@ async function generateApp() {
|
|
|
301
338
|
|
|
302
339
|
function handleFiles() {
|
|
303
340
|
return new Promise(async (resolve, reject) => {
|
|
304
|
-
try {
|
|
305
|
-
console.log(Glob)
|
|
341
|
+
try {
|
|
306
342
|
let glob = new Glob('public/**/*')
|
|
307
343
|
for await (var i of glob.scan()) {
|
|
308
344
|
let file = i
|
|
@@ -325,7 +361,7 @@ function handleFiles() {
|
|
|
325
361
|
file = file.replace('.jsx', '.js').replace('.tsx', '.js')
|
|
326
362
|
fs.writeFileSync(path.join(process.cwd() + '/dist', file.replace('.jsx', '.js').replace('.tsx', '.js')), code)
|
|
327
363
|
await Bun.spawn({
|
|
328
|
-
cmd: [
|
|
364
|
+
cmd: [bunPath, 'run', './dev/bundler.js'],
|
|
329
365
|
cwd: process.cwd(),
|
|
330
366
|
stdout: 'inherit',
|
|
331
367
|
env: {
|
|
@@ -354,7 +390,7 @@ function handleFiles() {
|
|
|
354
390
|
file = file.replace('.ts', '.js')
|
|
355
391
|
fs.writeFileSync(path.join(process.cwd() + '/dist', file.replace('.ts', '.js')), code)
|
|
356
392
|
await Bun.spawn({
|
|
357
|
-
cmd: [
|
|
393
|
+
cmd: [bunPath, 'run', './dev/bundler.js'],
|
|
358
394
|
cwd: process.cwd(),
|
|
359
395
|
stdout: 'inherit',
|
|
360
396
|
env: {
|
|
@@ -444,13 +480,14 @@ if (mode === 'development') {
|
|
|
444
480
|
else if (mode == 'production') {
|
|
445
481
|
await handleFiles()
|
|
446
482
|
await generateApp()
|
|
483
|
+
|
|
484
|
+
console.log(`Build complete in ${Date.now() - start}ms at ${new Date().toLocaleTimeString()}`);
|
|
447
485
|
}
|
|
448
486
|
else {
|
|
449
487
|
if (isBuilding) console.log(`Build complete in ${Date.now() - start}ms at ${new Date().toLocaleTimeString()}`);
|
|
450
|
-
|
|
488
|
+
|
|
451
489
|
}
|
|
452
490
|
|
|
453
|
-
|
|
454
491
|
if (mode == 'development' || mode == 'serve') {
|
|
455
492
|
let server = Bun.serve({
|
|
456
493
|
port: port || 8080,
|
|
@@ -501,17 +538,44 @@ if (mode == 'development' || mode == 'serve') {
|
|
|
501
538
|
base = base.replace(path.join(process.cwd() + '/app').replace(/\\/g, '/'), '')
|
|
502
539
|
base = base.replace(/\\/g, '/').replace('/app', '/dist')
|
|
503
540
|
base = process.cwd() + "/dist/" + base
|
|
541
|
+
if(!fs.existsSync(path.join(base, 'index.html'))){
|
|
542
|
+
return new Response(`
|
|
543
|
+
<html>
|
|
544
|
+
<head>
|
|
545
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
546
|
+
<meta http-equiv="refresh" content="5">
|
|
547
|
+
</head>
|
|
548
|
+
<body>
|
|
549
|
+
<p>Rerouting to display changes from server</p>
|
|
550
|
+
</body>
|
|
551
|
+
`, {
|
|
552
|
+
headers: {
|
|
553
|
+
'Content-Type': 'text/html',
|
|
554
|
+
'Cache-Control': 'no-cache'
|
|
555
|
+
}
|
|
556
|
+
})
|
|
557
|
+
}
|
|
504
558
|
let data = await Bun.file(path.join(base, 'index.html')).text()
|
|
505
559
|
if (mode == "development") {
|
|
506
560
|
return new Response(data + `
|
|
507
561
|
<script>
|
|
508
|
-
let ws = new WebSocket('ws
|
|
562
|
+
let ws = new WebSocket(\`\${location.protocol === 'https:' ? 'wss' : 'ws'}://\${location.host}\`)
|
|
509
563
|
ws.onmessage = (e) => {
|
|
510
564
|
if(e.data === 'reload'){
|
|
511
565
|
console.log('Reloading to display changes from server')
|
|
512
566
|
window.location.reload()
|
|
513
567
|
}
|
|
514
568
|
}
|
|
569
|
+
ws.onopen = () => {
|
|
570
|
+
console.log('Connected to hmr server')
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
ws.onclose = () => {
|
|
574
|
+
// try to reconnect
|
|
575
|
+
console.log('Reconnecting to hmr server')
|
|
576
|
+
ws = new WebSocket(\`\${location.protocol === 'https:' ? 'wss' : 'ws'}://\${location.host}\`)
|
|
577
|
+
}
|
|
578
|
+
|
|
515
579
|
</script>
|
|
516
580
|
`, {
|
|
517
581
|
headers: {
|
|
@@ -531,3 +595,6 @@ if (mode == 'development' || mode == 'serve') {
|
|
|
531
595
|
|
|
532
596
|
console.log(ansiColors.green('Server started at http://localhost:' + port || 8080))
|
|
533
597
|
}
|
|
598
|
+
|
|
599
|
+
|
|
600
|
+
|
package/package.json
CHANGED
package/bun.lockb
DELETED
|
Binary file
|