vaderjs 1.7.9 → 1.8.0
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/bundler/index.js +3 -3
- package/main.js +17 -20
- package/package.json +1 -1
- package/plugins/tailwindcss/index.ts +0 -72
package/bundler/index.js
CHANGED
|
@@ -93,7 +93,7 @@ const handleReplacements = (code) => {
|
|
|
93
93
|
|
|
94
94
|
let key = line.split(',')[0].split('[')[1].replace(' ', '');
|
|
95
95
|
|
|
96
|
-
let updatedLine = line.replace(/\buseState\d*\(/, `this.useState('${key
|
|
96
|
+
let updatedLine = line.replace(/\buseState\d*\(/, `this.useState('${key}',`);
|
|
97
97
|
|
|
98
98
|
line = updatedLine;
|
|
99
99
|
}
|
|
@@ -103,7 +103,7 @@ const handleReplacements = (code) => {
|
|
|
103
103
|
|
|
104
104
|
let key = line.split(',')[0].split('[')[1].replace(' ', '');
|
|
105
105
|
|
|
106
|
-
let updatedLine = line.replace(/\buseAsyncState\d*\(/, `this.useAsyncState('${key
|
|
106
|
+
let updatedLine = line.replace(/\buseAsyncState\d*\(/, `this.useAsyncState('${key}',`);
|
|
107
107
|
|
|
108
108
|
line = updatedLine;
|
|
109
109
|
}
|
|
@@ -191,7 +191,7 @@ const generatePage = async (
|
|
|
191
191
|
import c from '${process.env.filePath}'
|
|
192
192
|
import {render, e} from '/src/vader/index.js'
|
|
193
193
|
window.e = e
|
|
194
|
-
render(c, document.body)
|
|
194
|
+
render(c, document.body.firstChild)
|
|
195
195
|
</script>
|
|
196
196
|
`
|
|
197
197
|
);
|
package/main.js
CHANGED
|
@@ -201,9 +201,9 @@ async function generateApp() {
|
|
|
201
201
|
|
|
202
202
|
let r = routes.routes[route]
|
|
203
203
|
let code = await Bun.file(r).text()
|
|
204
|
+
code = handleReplacements(code)
|
|
204
205
|
let size = code.length / 1024
|
|
205
206
|
r = r.replace(process.cwd().replace(/\\/g, '/') + '/app', '')
|
|
206
|
-
var beforeR = r
|
|
207
207
|
r = r.replace('.jsx', '.js').replace('.tsx', '.js')
|
|
208
208
|
fs.mkdirSync(path.join(process.cwd() + '/dist', path.dirname(r)), { recursive: true })
|
|
209
209
|
fs.writeFileSync(process.cwd() + '/dist/' + path.dirname(r) + '/' + path.basename(r), `
|
|
@@ -227,7 +227,6 @@ async function generateApp() {
|
|
|
227
227
|
fs.writeFileSync(process.cwd() + '/dist/src/vader/index.js', await new Bun.Transpiler({
|
|
228
228
|
loader: 'ts',
|
|
229
229
|
}).transformSync(await Bun.file(require.resolve('vaderjs')).text()))
|
|
230
|
-
|
|
231
230
|
Bun.spawn({
|
|
232
231
|
cmd: ['bun', 'run', './dev/bundler.js'],
|
|
233
232
|
cwd: process.cwd(),
|
|
@@ -240,12 +239,10 @@ async function generateApp() {
|
|
|
240
239
|
DEV: mode === 'development',
|
|
241
240
|
size,
|
|
242
241
|
bindes: bindes.join('\n'),
|
|
243
|
-
isTs: beforeR.endsWith(".tsx"),
|
|
244
242
|
filePath: r,
|
|
245
|
-
|
|
246
|
-
isJsx: beforeR.endsWith('.tsx') || beforeR.endsWith(".jsx"),
|
|
247
243
|
isAppFile: true,
|
|
248
|
-
|
|
244
|
+
isJsx: true,
|
|
245
|
+
INPUT: `../app/${r.replace('.js', '.jsx').replace('.tsx', '.js')}`,
|
|
249
246
|
},
|
|
250
247
|
onExit({ exitCode: code }) {
|
|
251
248
|
if (code === 0) {
|
|
@@ -305,6 +302,7 @@ async function generateApp() {
|
|
|
305
302
|
function handleFiles() {
|
|
306
303
|
return new Promise(async (resolve, reject) => {
|
|
307
304
|
try {
|
|
305
|
+
console.log(Glob)
|
|
308
306
|
let glob = new Glob('public/**/*')
|
|
309
307
|
for await (var i of glob.scan()) {
|
|
310
308
|
let file = i
|
|
@@ -319,11 +317,11 @@ function handleFiles() {
|
|
|
319
317
|
var file = i
|
|
320
318
|
fs.mkdirSync(path.join(process.cwd() + '/dist', path.dirname(file)), { recursive: true })
|
|
321
319
|
// turn jsx to js
|
|
322
|
-
if (file.
|
|
320
|
+
if (file.includes('.jsx') || file.includes('.tsx')) {
|
|
323
321
|
let code = await Bun.file(file).text()
|
|
324
322
|
|
|
325
323
|
code = handleReplacements(code)
|
|
326
|
-
|
|
324
|
+
|
|
327
325
|
file = file.replace('.jsx', '.js').replace('.tsx', '.js')
|
|
328
326
|
fs.writeFileSync(path.join(process.cwd() + '/dist', file.replace('.jsx', '.js').replace('.tsx', '.js')), code)
|
|
329
327
|
await Bun.spawn({
|
|
@@ -339,9 +337,8 @@ function handleFiles() {
|
|
|
339
337
|
DEV: mode === 'development',
|
|
340
338
|
size: code.length / 1024,
|
|
341
339
|
filePath: file.replace('.jsx', '.js'),
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
INPUT: path.join(process.cwd(), url),
|
|
340
|
+
isTs: file.includes('.tsx'),
|
|
341
|
+
INPUT: path.join(process.cwd(), file.replace('.js', '.jsx').replace('.tsx', '.js')),
|
|
345
342
|
},
|
|
346
343
|
onExit({ exitCode: code }) {
|
|
347
344
|
if (code === 0) {
|
|
@@ -351,7 +348,7 @@ function handleFiles() {
|
|
|
351
348
|
}
|
|
352
349
|
}
|
|
353
350
|
})
|
|
354
|
-
} else if (file.
|
|
351
|
+
} else if (file.includes('.ts')) {
|
|
355
352
|
let code = await Bun.file(file).text()
|
|
356
353
|
code = handleReplacements(code)
|
|
357
354
|
file = file.replace('.ts', '.js')
|
|
@@ -392,8 +389,8 @@ function handleFiles() {
|
|
|
392
389
|
globalThis.clients = []
|
|
393
390
|
|
|
394
391
|
if (mode === 'development') {
|
|
395
|
-
await handleFiles()
|
|
396
392
|
await generateApp()
|
|
393
|
+
await handleFiles()
|
|
397
394
|
const watcher = fs.watch(path.join(process.cwd() + '/'), { recursive: true })
|
|
398
395
|
let isBuilding = false; // Flag to track build status
|
|
399
396
|
|
|
@@ -403,10 +400,10 @@ if (mode === 'development') {
|
|
|
403
400
|
// Function to handle file changes with debounce
|
|
404
401
|
const handleFileChangeDebounced = async (change, file) => {
|
|
405
402
|
if (file.endsWith('.tsx') || file.endsWith('.jsx') || file.endsWith('.css') || file.endsWith('.ts')
|
|
406
|
-
|
|
403
|
+
&& !file.includes('node_module')
|
|
407
404
|
) {
|
|
408
405
|
// delete files cache
|
|
409
|
-
if (file.endsWith('vader.config.ts'))
|
|
406
|
+
if (file.endsWith('vader.config.ts')){
|
|
410
407
|
delete require.cache[require.resolve(process.cwd() + '/vader.config.ts')]
|
|
411
408
|
|
|
412
409
|
config = require(process.cwd() + '/vader.config.ts').default
|
|
@@ -494,16 +491,16 @@ if (mode == 'development' || mode == 'serve') {
|
|
|
494
491
|
style: 'nextjs'
|
|
495
492
|
})
|
|
496
493
|
router.reload()
|
|
497
|
-
let route = router.match(url.pathname)
|
|
494
|
+
let route = router.match(url.pathname)
|
|
498
495
|
if (!route) {
|
|
499
496
|
return new Response('Not found', { status: 404 })
|
|
500
497
|
}
|
|
501
498
|
let p = route.pathname;
|
|
502
499
|
let base = path.dirname(route.filePath)
|
|
503
500
|
base = base.replace(/\\/g, '/')
|
|
504
|
-
base = base.replace(path.join(process.cwd() + '/app').replace(/\\/g, '/'), '')
|
|
505
|
-
base = base.replace(/\\/g, '/').replace(
|
|
506
|
-
base = process.cwd() +
|
|
501
|
+
base = base.replace(path.join(process.cwd() + '/app').replace(/\\/g, '/'), '')
|
|
502
|
+
base = base.replace(/\\/g, '/').replace('/app', '/dist')
|
|
503
|
+
base = process.cwd() + "/dist/" + base
|
|
507
504
|
let data = await Bun.file(path.join(base, 'index.html')).text()
|
|
508
505
|
if (mode == "development") {
|
|
509
506
|
return new Response(data + `
|
|
@@ -533,4 +530,4 @@ if (mode == 'development' || mode == 'serve') {
|
|
|
533
530
|
})
|
|
534
531
|
|
|
535
532
|
console.log(ansiColors.green('Server started at http://localhost:' + port || 8080))
|
|
536
|
-
}
|
|
533
|
+
}
|
package/package.json
CHANGED
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
//@ts-nocheck
|
|
2
|
-
import fs from 'fs'
|
|
3
|
-
import path from 'path'
|
|
4
|
-
function checkIfTailwindInstalled() {
|
|
5
|
-
try {
|
|
6
|
-
//@ts-ignore
|
|
7
|
-
require.resolve('tailwindcss')
|
|
8
|
-
return true
|
|
9
|
-
} catch (e) {
|
|
10
|
-
return false
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
function initTailwind() {
|
|
15
|
-
const tailwindConfig = path.resolve(process.cwd(), 'tailwind.config.js')
|
|
16
|
-
const postcssConfig = path.resolve(process.cwd(), 'postcss.config.js')
|
|
17
|
-
if(!fs.existsSync(path.join(process.cwd(), '/public/styles.css'))){
|
|
18
|
-
|
|
19
|
-
fs.writeFileSync(path.join(process.cwd(), '/public/styles.css'), `
|
|
20
|
-
@tailwind base;
|
|
21
|
-
@tailwind components;
|
|
22
|
-
@tailwind utilities;
|
|
23
|
-
`)
|
|
24
|
-
}
|
|
25
|
-
if (!fs.existsSync(tailwindConfig)) {
|
|
26
|
-
fs.writeFileSync(postcssConfig, `module.exports = {
|
|
27
|
-
plugins: {
|
|
28
|
-
tailwindcss: {},
|
|
29
|
-
autoprefixer: {},
|
|
30
|
-
}
|
|
31
|
-
}`)
|
|
32
|
-
|
|
33
|
-
fs.writeFileSync(tailwindConfig, `/** @type {import('tailwindcss').Config} */
|
|
34
|
-
module.exports = {
|
|
35
|
-
content: ['./src/**/*.{html,js,jsx,ts,tsx}', './app/**/*.{html,js,jsx,ts,tsx}'],
|
|
36
|
-
theme: {
|
|
37
|
-
extend: {},
|
|
38
|
-
},
|
|
39
|
-
plugins: [],
|
|
40
|
-
}`)
|
|
41
|
-
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
export default {
|
|
48
|
-
name: 'tailwindcss',
|
|
49
|
-
description: 'TailwindCSS plugin for Vader.js',
|
|
50
|
-
version: '0.0.1',
|
|
51
|
-
onBuildStart: async (vader) => {
|
|
52
|
-
if (!checkIfTailwindInstalled()) {
|
|
53
|
-
console.error('TailwindCSS is not installed. Please install it using `bun install tailwindcss postcss-cli autoprefixer`')
|
|
54
|
-
process.exit(1)
|
|
55
|
-
}else{
|
|
56
|
-
initTailwind()
|
|
57
|
-
|
|
58
|
-
vader.onFileChange('tailwind.config.js', async () => {
|
|
59
|
-
console.log('Rebuilding TailwindCSS...')
|
|
60
|
-
await vader.runCommand(['bun', 'run', 'postcss', './public/styles.css', '-o', 'dist/public/tailwind.css'])
|
|
61
|
-
console.log('TailwindCSS rebuilt successfully!')
|
|
62
|
-
})
|
|
63
|
-
await vader.runCommand(['bun', 'run', 'postcss', './public/styles.css', '-o', 'dist/public/tailwind.css'])
|
|
64
|
-
vader.injectHTML(`<style>${fs.readFileSync(path.resolve(process.cwd(), 'dist/public/tailwind.css'))}</style>`)
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
},
|
|
68
|
-
onBuildFinish: async (vader) => {
|
|
69
|
-
console.log('TailwindCSS plugin finished building')
|
|
70
|
-
},
|
|
71
|
-
|
|
72
|
-
}
|