vaderjs 1.6.4 → 1.6.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/README.MD +19 -1
- package/bundler/index.js +13 -20
- package/main.js +50 -5
- package/package.json +1 -1
- package/plugins/tailwind.ts +50 -0
- package/plugins/tailwindcss/index.ts +61 -0
package/README.MD
CHANGED
|
@@ -12,7 +12,25 @@
|
|
|
12
12
|
|
|
13
13
|
[](https://github.com/Postr-Inc/Vader.js/blob/main/LICENSE) [](https://www.npmjs.com/package/vaderjs)
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
```tsx
|
|
16
|
+
import { useState, Switch, Match } from "vaderjs"
|
|
17
|
+
|
|
18
|
+
export default function(){
|
|
19
|
+
let [count, setCount] = useState(0)
|
|
20
|
+
return(
|
|
21
|
+
<div>
|
|
22
|
+
<Switch>
|
|
23
|
+
<Match when={count() > 10}>
|
|
24
|
+
<h1>Count is greater than 10 </h1>
|
|
25
|
+
</Match>
|
|
26
|
+
<Match when={count() < 10}>
|
|
27
|
+
<h1>Count is less than 10 </h1>
|
|
28
|
+
</Match>
|
|
29
|
+
</Switch>
|
|
30
|
+
</div>
|
|
31
|
+
)
|
|
32
|
+
}
|
|
33
|
+
```
|
|
16
34
|
# Installation
|
|
17
35
|
|
|
18
36
|
```js
|
package/bundler/index.js
CHANGED
|
@@ -37,42 +37,39 @@ await Bun.build({
|
|
|
37
37
|
entrypoints: [process.env.ENTRYPOINT],
|
|
38
38
|
minify: false,
|
|
39
39
|
root: process.cwd() + "/dist/",
|
|
40
|
-
outdir: process.cwd() + "/dist/",
|
|
40
|
+
outdir: process.cwd() + "/dist/",
|
|
41
|
+
|
|
41
42
|
format: "esm",
|
|
42
43
|
...(process.env.DEV ? { sourcemap: "inline" } : {}),
|
|
43
|
-
external:['*.jsx', '*.js', '*.ts'
|
|
44
|
+
external:['*.jsx', '*.js', '*.ts']
|
|
44
45
|
});
|
|
45
46
|
|
|
46
47
|
let builtCode = fs.readFileSync(path.join(process.cwd(), 'dist', process.env.filePath), 'utf-8')
|
|
48
|
+
|
|
47
49
|
function handleReplacements(code) {
|
|
48
50
|
let lines = code.split("\n");
|
|
49
51
|
let newLines = [];
|
|
50
52
|
for (let line of lines) {
|
|
51
53
|
let hasImport = line.includes('import')
|
|
52
|
-
if(hasImport && line.includes('from')){
|
|
53
|
-
try {
|
|
54
|
+
if(hasImport && line.includes('from') && !newLines.includes(line)){
|
|
55
|
+
try {
|
|
54
56
|
let url = line.includes("'") ? line.split("'")[1] : line.split('"')[1]
|
|
55
|
-
|
|
56
57
|
line = line.replace(url, url.replace('.jsx', '.js').replace('.tsx', '.js'))
|
|
57
58
|
line = line.replace(url, url.replace('.ts', '.js').replace('.tsx', '.js'))
|
|
58
59
|
newLines.push(line)
|
|
59
|
-
} catch (error) {
|
|
60
|
+
} catch (error) {
|
|
60
61
|
continue;
|
|
61
62
|
}
|
|
62
63
|
}else{
|
|
63
|
-
|
|
64
|
+
newLines.push(line)
|
|
64
65
|
}
|
|
65
|
-
|
|
66
66
|
}
|
|
67
|
-
return
|
|
67
|
+
return newLines.join("\n");
|
|
68
68
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
builtCode = handleReplacements(builtCode)
|
|
69
|
+
builtCode = handleReplacements(builtCode)
|
|
72
70
|
fs.writeFileSync(path.join(process.cwd(), 'dist', process.env.filePath), builtCode)
|
|
73
|
-
|
|
71
|
+
|
|
74
72
|
let isClass = function (element) {
|
|
75
|
-
if (!element) return false;
|
|
76
73
|
return element.toString().startsWith("class");
|
|
77
74
|
};
|
|
78
75
|
const generatePage = async (
|
|
@@ -84,10 +81,6 @@ const generatePage = async (
|
|
|
84
81
|
let { head } = await import(path).then((m) => m);
|
|
85
82
|
let isFunction = false;
|
|
86
83
|
globalThis.isServer = true;
|
|
87
|
-
if(!html) {
|
|
88
|
-
console.log(ansiColors.red(`No default export found in ${path}`))
|
|
89
|
-
process.exit(0)
|
|
90
|
-
}
|
|
91
84
|
if (isClass(html)) {
|
|
92
85
|
html = new html();
|
|
93
86
|
html.Mounted = true;
|
|
@@ -107,8 +100,8 @@ const generatePage = async (
|
|
|
107
100
|
});
|
|
108
101
|
}
|
|
109
102
|
let headHtml = "";
|
|
110
|
-
if (head) {
|
|
111
|
-
headHtml = document(head());
|
|
103
|
+
if (head) {
|
|
104
|
+
headHtml = document(head());
|
|
112
105
|
}
|
|
113
106
|
|
|
114
107
|
await Bun.write(
|
package/main.js
CHANGED
|
@@ -6,6 +6,8 @@ const args = Bun.argv.slice(2)
|
|
|
6
6
|
globalThis.isBuilding = false;
|
|
7
7
|
import fs from 'fs'
|
|
8
8
|
import path from 'path'
|
|
9
|
+
|
|
10
|
+
|
|
9
11
|
if (!fs.existsSync(process.cwd() + '/app') && !args.includes('init')) {
|
|
10
12
|
console.error(`App directory not found in ${process.cwd()}/app`)
|
|
11
13
|
process.exit(1)
|
|
@@ -24,6 +26,7 @@ export default defineConfig({
|
|
|
24
26
|
host_provider: 'apache'
|
|
25
27
|
})`)
|
|
26
28
|
}
|
|
29
|
+
const config = require(process.cwd() + '/vader.config.ts').default
|
|
27
30
|
const mode = args.includes('dev') ? 'development' : args.includes('prod') || args.includes('build') ? 'production' : args.includes('init') ? 'init' : args.includes('serve') ? 'serve' : null;
|
|
28
31
|
if (!mode) {
|
|
29
32
|
console.log(`
|
|
@@ -74,7 +77,37 @@ if (!fs.existsSync(process.cwd() + '/jsconfig.json')) {
|
|
|
74
77
|
}
|
|
75
78
|
|
|
76
79
|
var bindes = []
|
|
80
|
+
var fnmap = []
|
|
81
|
+
const vader = {
|
|
82
|
+
onFileChange: (file, cb) => {
|
|
83
|
+
fs.watch(file, cb)
|
|
84
|
+
},
|
|
85
|
+
runCommand: (cmd) => {
|
|
86
|
+
return new Promise((resolve, reject) => {
|
|
87
|
+
Bun.spawn(cmd, {
|
|
88
|
+
stdout: 'inherit',
|
|
89
|
+
cwd: process.cwd(),
|
|
90
|
+
onExit({ exitCode: code }) {
|
|
91
|
+
if (code === 0) {
|
|
92
|
+
resolve()
|
|
93
|
+
} else {
|
|
94
|
+
reject()
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
})
|
|
98
|
+
|
|
77
99
|
|
|
100
|
+
})
|
|
101
|
+
},
|
|
102
|
+
onBuildStart: (cb) => {
|
|
103
|
+
if (!fnmap.find(v => v.code == cb.toString())) {
|
|
104
|
+
fnmap.push({ code: cb.toString(), fn: cb })
|
|
105
|
+
}
|
|
106
|
+
},
|
|
107
|
+
injectHTML: (html) => {
|
|
108
|
+
bindes.push(html)
|
|
109
|
+
},
|
|
110
|
+
}
|
|
78
111
|
const handleReplacements = (code) => {
|
|
79
112
|
let lines = code.split('\n')
|
|
80
113
|
let newLines = []
|
|
@@ -133,6 +166,7 @@ const handleReplacements = (code) => {
|
|
|
133
166
|
b4 = line.replace('useRef(', `this.useRef('${key}',`)
|
|
134
167
|
line = b4
|
|
135
168
|
}
|
|
169
|
+
|
|
136
170
|
newLines.push(line)
|
|
137
171
|
}
|
|
138
172
|
let c = newLines.join('\n')
|
|
@@ -145,6 +179,10 @@ async function generateApp() {
|
|
|
145
179
|
globalThis.isBuilding = true;
|
|
146
180
|
console.log(ansiColors.green('Building...'))
|
|
147
181
|
console.log(`Starting build at ${new Date().toLocaleTimeString()}`)
|
|
182
|
+
for (let fn of fnmap) {
|
|
183
|
+
await fn.fn(vader)
|
|
184
|
+
fnmap = fnmap.filter(v => v.code !== fn.code)
|
|
185
|
+
}
|
|
148
186
|
// remove files from dist
|
|
149
187
|
if (mode === 'development') {
|
|
150
188
|
fs.rmdirSync(process.cwd() + '/dist', { recursive: true })
|
|
@@ -246,9 +284,16 @@ async function generateApp() {
|
|
|
246
284
|
let data = ''
|
|
247
285
|
|
|
248
286
|
}
|
|
249
|
-
|
|
287
|
+
// run all plugins that have onBuildFinish
|
|
288
|
+
let plugins = config.plugins || []
|
|
289
|
+
for (let plugin of plugins) {
|
|
290
|
+
if (plugin.onBuildFinish) {
|
|
291
|
+
await plugin.onBuildFinish(vader)
|
|
292
|
+
}
|
|
293
|
+
}
|
|
250
294
|
})
|
|
251
295
|
|
|
296
|
+
|
|
252
297
|
}
|
|
253
298
|
|
|
254
299
|
function handleFiles() {
|
|
@@ -376,10 +421,10 @@ if (mode === 'development') {
|
|
|
376
421
|
// Event listeners with debounced handling
|
|
377
422
|
watcher.on('change', handleFileChangeDebounced);
|
|
378
423
|
|
|
379
|
-
}
|
|
380
|
-
else if(mode == 'production'){
|
|
424
|
+
}
|
|
425
|
+
else if (mode == 'production') {
|
|
381
426
|
await handleFiles()
|
|
382
|
-
await generateApp()
|
|
427
|
+
await generateApp()
|
|
383
428
|
}
|
|
384
429
|
else {
|
|
385
430
|
if (isBuilding) console.log(`Build complete in ${Date.now() - start}ms at ${new Date().toLocaleTimeString()}`);
|
|
@@ -464,6 +509,6 @@ if (mode == 'development' || mode == 'serve') {
|
|
|
464
509
|
|
|
465
510
|
}
|
|
466
511
|
})
|
|
467
|
-
|
|
512
|
+
|
|
468
513
|
console.log(ansiColors.green('Server started at http://localhost:' + port || 8080))
|
|
469
514
|
}
|
package/package.json
CHANGED
|
@@ -0,0 +1,50 @@
|
|
|
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
|
+
if (!fs.existsSync(tailwindConfig)) {
|
|
17
|
+
fs.writeFileSync(tailwindConfig, `/** @type {import('tailwindcss').Config} */
|
|
18
|
+
module.exports = {
|
|
19
|
+
content: ['./src/**/*.{html,js,jsx,ts,tsx}', './app/**/*.{html,js,jsx,ts,tsx}'],
|
|
20
|
+
theme: {
|
|
21
|
+
extend: {},
|
|
22
|
+
},
|
|
23
|
+
plugins: [],
|
|
24
|
+
}`)
|
|
25
|
+
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
export default {
|
|
32
|
+
name: 'tailwindcss',
|
|
33
|
+
description: 'TailwindCSS plugin for Vader.js',
|
|
34
|
+
version: '0.0.1',
|
|
35
|
+
onBuildFinish: async (vader) => {
|
|
36
|
+
if (!checkIfTailwindInstalled()) {
|
|
37
|
+
console.error('TailwindCSS is not installed. Please install it using `bun install tailwindcss`')
|
|
38
|
+
process.exit(1)
|
|
39
|
+
}else{
|
|
40
|
+
initTailwind()
|
|
41
|
+
vader.onFileChange('tailwind.config.js', async () => {
|
|
42
|
+
console.log('Rebuilding TailwindCSS...')
|
|
43
|
+
await vader.runCommand(['bun', 'run', 'tailwindcss', 'build', '-o', 'public/styles.css'])
|
|
44
|
+
console.log('TailwindCSS rebuilt successfully!')
|
|
45
|
+
})
|
|
46
|
+
vader.runCommand(['bun', 'run', 'tailwindcss', 'build', '-o', 'public/styles.css'])
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
|
|
50
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
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(tailwindConfig)) {
|
|
18
|
+
fs.writeFileSync(postcssConfig, `module.exports = {
|
|
19
|
+
plugins: {
|
|
20
|
+
tailwindcss: {},
|
|
21
|
+
autoprefixer: {},
|
|
22
|
+
}
|
|
23
|
+
}`)
|
|
24
|
+
|
|
25
|
+
fs.writeFileSync(tailwindConfig, `/** @type {import('tailwindcss').Config} */
|
|
26
|
+
module.exports = {
|
|
27
|
+
content: ['./src/**/*.{html,js,jsx,ts,tsx}', './app/**/*.{html,js,jsx,ts,tsx}'],
|
|
28
|
+
theme: {
|
|
29
|
+
extend: {},
|
|
30
|
+
},
|
|
31
|
+
plugins: [],
|
|
32
|
+
}`)
|
|
33
|
+
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
export default {
|
|
40
|
+
name: 'tailwindcss',
|
|
41
|
+
description: 'TailwindCSS plugin for Vader.js',
|
|
42
|
+
version: '0.0.1',
|
|
43
|
+
onBuildFinish: async (vader) => {
|
|
44
|
+
if (!checkIfTailwindInstalled()) {
|
|
45
|
+
console.error('TailwindCSS is not installed. Please install it using `bun install tailwindcss postcss-cli autoprefixer`')
|
|
46
|
+
process.exit(1)
|
|
47
|
+
}else{
|
|
48
|
+
initTailwind()
|
|
49
|
+
vader.onBuildStart(() => {
|
|
50
|
+
vader.injectHTML(`<link rel="stylesheet" href="/public/tailwind.css">`)
|
|
51
|
+
})
|
|
52
|
+
vader.onFileChange('tailwind.config.js', async () => {
|
|
53
|
+
console.log('Rebuilding TailwindCSS...')
|
|
54
|
+
await vader.runCommand(['bun', 'run', 'postcss', 'public/styles.css', '-o', 'dist/public/tailwind.css'])
|
|
55
|
+
console.log('TailwindCSS rebuilt successfully!')
|
|
56
|
+
})
|
|
57
|
+
vader.runCommand(['bun', 'run', 'postcss', 'public/styles.css', '-o', 'dist/public/tailwind.css'])
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
|
|
61
|
+
}
|