vaderjs 2.0.3 → 2.0.5
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 +25 -84
- package/package.json +1 -1
package/main.js
CHANGED
|
@@ -75,16 +75,15 @@ if (!fs.existsSync(process.cwd() + '/jsconfig.json')) {
|
|
|
75
75
|
await Bun.write(process.cwd() + '/jsconfig.json', JSON.stringify(json, null, 4))
|
|
76
76
|
}
|
|
77
77
|
|
|
78
|
-
|
|
78
|
+
var bindes = []
|
|
79
79
|
var fnmap = []
|
|
80
80
|
const vader = {
|
|
81
|
-
isDev: mode === 'development',
|
|
82
81
|
onFileChange: (file, cb) => {
|
|
83
82
|
fs.watch(file, cb)
|
|
84
83
|
},
|
|
85
84
|
runCommand: (cmd) => {
|
|
86
85
|
return new Promise((resolve, reject) => {
|
|
87
|
-
|
|
86
|
+
Bun.spawn(cmd, {
|
|
88
87
|
stdout: 'inherit',
|
|
89
88
|
cwd: process.cwd(),
|
|
90
89
|
onExit({ exitCode: code }) {
|
|
@@ -96,11 +95,6 @@ const vader = {
|
|
|
96
95
|
}
|
|
97
96
|
})
|
|
98
97
|
|
|
99
|
-
setTimeout(() => {
|
|
100
|
-
c.kill()
|
|
101
|
-
reject()
|
|
102
|
-
}, 5000)
|
|
103
|
-
|
|
104
98
|
|
|
105
99
|
})
|
|
106
100
|
},
|
|
@@ -111,7 +105,6 @@ const vader = {
|
|
|
111
105
|
},
|
|
112
106
|
injectHTML: (html) => {
|
|
113
107
|
bindes.push(html)
|
|
114
|
-
globalThis.bindes = bindes
|
|
115
108
|
},
|
|
116
109
|
}
|
|
117
110
|
const handleReplacements = (code) => {
|
|
@@ -167,9 +160,8 @@ const handleReplacements = (code) => {
|
|
|
167
160
|
line = b4
|
|
168
161
|
}
|
|
169
162
|
if (!hasImport && line.includes('useRef')) {
|
|
170
|
-
line = line.replace(' ', '')
|
|
171
163
|
let b4 = line
|
|
172
|
-
let key = line.split('
|
|
164
|
+
let key = line.split(' ')[1].split('=')[0]
|
|
173
165
|
b4 = line.replace('useRef(', `this.useRef('${key}',`)
|
|
174
166
|
line = b4
|
|
175
167
|
}
|
|
@@ -180,14 +172,12 @@ const handleReplacements = (code) => {
|
|
|
180
172
|
return c
|
|
181
173
|
}
|
|
182
174
|
|
|
183
|
-
|
|
184
|
-
fs.mkdirSync(process.cwd() + '/dev', { recursive: true })
|
|
185
|
-
fs.copyFileSync(require.resolve('vaderjs/bundler/index.js'), process.cwd() + '/dev/bundler.js')
|
|
186
|
-
}
|
|
175
|
+
|
|
187
176
|
let start = Date.now()
|
|
188
177
|
async function generateApp() {
|
|
189
178
|
globalThis.isBuilding = true;
|
|
190
|
-
console.log(ansiColors.green('Building...'))
|
|
179
|
+
console.log(ansiColors.green('Building...'))
|
|
180
|
+
console.log(`Starting build at ${new Date().toLocaleTimeString()}`)
|
|
191
181
|
let plugins = config.plugins || []
|
|
192
182
|
for (let plugin of plugins) {
|
|
193
183
|
if (plugin.onBuildStart) {
|
|
@@ -216,38 +206,19 @@ async function generateApp() {
|
|
|
216
206
|
r = r.replace(process.cwd().replace(/\\/g, '/') + '/app', '')
|
|
217
207
|
r = r.replace('.jsx', '.js').replace('.tsx', '.js')
|
|
218
208
|
fs.mkdirSync(path.join(process.cwd() + '/dist', path.dirname(r)), { recursive: true })
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
// dont return
|
|
229
|
-
|
|
230
|
-
fs.writeFileSync(
|
|
231
|
-
process.cwd() + '/dist/' + path.dirname(r) + '/' + path.basename(r),
|
|
232
|
-
`
|
|
233
|
-
let route = window.location.pathname.split('/').filter(Boolean)
|
|
234
|
-
let params = {
|
|
235
|
-
// get index tehn do route[index]
|
|
236
|
-
${Object.keys(params).map((param, i) => {
|
|
237
|
-
if (paramIndexes[i] !== -1) {
|
|
238
|
-
var r_copy = r;
|
|
239
|
-
r_copy = r_copy.split('/').filter(Boolean)
|
|
240
|
-
var index = paramIndexes[i] - 1
|
|
241
|
-
return `${param}: route[${index}]`
|
|
242
|
-
}
|
|
243
|
-
}).join(',\n')}
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
\n${code}
|
|
247
|
-
`
|
|
248
|
-
);
|
|
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
|
+
`)
|
|
249
218
|
fs.mkdirSync(process.cwd() + '/dev', { recursive: true })
|
|
250
|
-
|
|
219
|
+
if (!fs.existsSync(process.cwd() + '/dev/bundler.js')) {
|
|
220
|
+
fs.copyFileSync(require.resolve('vaderjs/bundler/index.js'), process.cwd() + '/dev/bundler.js')
|
|
221
|
+
}
|
|
251
222
|
|
|
252
223
|
if (!fs.existsSync(process.cwd() + '/dev/readme.md')) {
|
|
253
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`)
|
|
@@ -275,7 +246,8 @@ async function generateApp() {
|
|
|
275
246
|
},
|
|
276
247
|
onExit({ exitCode: code }) {
|
|
277
248
|
if (code === 0) {
|
|
278
|
-
bindes = []
|
|
249
|
+
bindes = []
|
|
250
|
+
console.log(`Built ${r} in ${Date.now() - start}ms`)
|
|
279
251
|
resolve()
|
|
280
252
|
} else {
|
|
281
253
|
reject()
|
|
@@ -322,7 +294,6 @@ async function generateApp() {
|
|
|
322
294
|
await plugin.onBuildFinish(vader)
|
|
323
295
|
}
|
|
324
296
|
}
|
|
325
|
-
|
|
326
297
|
})
|
|
327
298
|
|
|
328
299
|
|
|
@@ -330,7 +301,8 @@ async function generateApp() {
|
|
|
330
301
|
|
|
331
302
|
function handleFiles() {
|
|
332
303
|
return new Promise(async (resolve, reject) => {
|
|
333
|
-
try {
|
|
304
|
+
try {
|
|
305
|
+
console.log(Glob)
|
|
334
306
|
let glob = new Glob('public/**/*')
|
|
335
307
|
for await (var i of glob.scan()) {
|
|
336
308
|
let file = i
|
|
@@ -472,14 +444,13 @@ if (mode === 'development') {
|
|
|
472
444
|
else if (mode == 'production') {
|
|
473
445
|
await handleFiles()
|
|
474
446
|
await generateApp()
|
|
475
|
-
|
|
476
|
-
console.log(`Build complete in ${Date.now() - start}ms at ${new Date().toLocaleTimeString()}`);
|
|
477
447
|
}
|
|
478
448
|
else {
|
|
479
449
|
if (isBuilding) console.log(`Build complete in ${Date.now() - start}ms at ${new Date().toLocaleTimeString()}`);
|
|
480
|
-
|
|
450
|
+
|
|
481
451
|
}
|
|
482
452
|
|
|
453
|
+
|
|
483
454
|
if (mode == 'development' || mode == 'serve') {
|
|
484
455
|
let server = Bun.serve({
|
|
485
456
|
port: port || 8080,
|
|
@@ -530,44 +501,17 @@ if (mode == 'development' || mode == 'serve') {
|
|
|
530
501
|
base = base.replace(path.join(process.cwd() + '/app').replace(/\\/g, '/'), '')
|
|
531
502
|
base = base.replace(/\\/g, '/').replace('/app', '/dist')
|
|
532
503
|
base = process.cwd() + "/dist/" + base
|
|
533
|
-
if(!fs.existsSync(path.join(base, 'index.html'))){
|
|
534
|
-
return new Response(`
|
|
535
|
-
<html>
|
|
536
|
-
<head>
|
|
537
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
538
|
-
<meta http-equiv="refresh" content="5">
|
|
539
|
-
</head>
|
|
540
|
-
<body>
|
|
541
|
-
<p>Rerouting to display changes from server</p>
|
|
542
|
-
</body>
|
|
543
|
-
`, {
|
|
544
|
-
headers: {
|
|
545
|
-
'Content-Type': 'text/html',
|
|
546
|
-
'Cache-Control': 'no-cache'
|
|
547
|
-
}
|
|
548
|
-
})
|
|
549
|
-
}
|
|
550
504
|
let data = await Bun.file(path.join(base, 'index.html')).text()
|
|
551
505
|
if (mode == "development") {
|
|
552
506
|
return new Response(data + `
|
|
553
507
|
<script>
|
|
554
|
-
let ws = new WebSocket(
|
|
508
|
+
let ws = new WebSocket('ws://localhost:${server.port}')
|
|
555
509
|
ws.onmessage = (e) => {
|
|
556
510
|
if(e.data === 'reload'){
|
|
557
511
|
console.log('Reloading to display changes from server')
|
|
558
512
|
window.location.reload()
|
|
559
513
|
}
|
|
560
514
|
}
|
|
561
|
-
ws.onopen = () => {
|
|
562
|
-
console.log('Connected to hmr server')
|
|
563
|
-
}
|
|
564
|
-
|
|
565
|
-
ws.onclose = () => {
|
|
566
|
-
// try to reconnect
|
|
567
|
-
console.log('Reconnecting to hmr server')
|
|
568
|
-
ws = new WebSocket(\`\${location.protocol === 'https:' ? 'wss' : 'ws'}://\${location.host}\`)
|
|
569
|
-
}
|
|
570
|
-
|
|
571
515
|
</script>
|
|
572
516
|
`, {
|
|
573
517
|
headers: {
|
|
@@ -587,6 +531,3 @@ if (mode == 'development' || mode == 'serve') {
|
|
|
587
531
|
|
|
588
532
|
console.log(ansiColors.green('Server started at http://localhost:' + port || 8080))
|
|
589
533
|
}
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|