vaderjs 1.6.4 → 1.6.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/README.MD +19 -1
- package/bundler/index.js +13 -20
- package/main.js +34 -2
- package/package.json +1 -1
- package/plugins/tailwind.ts +50 -0
- package/plugins/tailwindcss/index.ts +50 -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,29 @@ 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
|
+
const vader = {
|
|
11
|
+
onFileChange: (file, cb) => {
|
|
12
|
+
fs.watch(file, cb)
|
|
13
|
+
},
|
|
14
|
+
runCommand: (cmd) => {
|
|
15
|
+
return new Promise((resolve, reject) => {
|
|
16
|
+
Bun.spawn(cmd, {
|
|
17
|
+
stdout: 'inherit',
|
|
18
|
+
cwd: process.cwd(),
|
|
19
|
+
onExit({ exitCode: code }) {
|
|
20
|
+
if (code === 0) {
|
|
21
|
+
resolve()
|
|
22
|
+
} else {
|
|
23
|
+
reject()
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
})
|
|
30
|
+
}
|
|
31
|
+
}
|
|
9
32
|
if (!fs.existsSync(process.cwd() + '/app') && !args.includes('init')) {
|
|
10
33
|
console.error(`App directory not found in ${process.cwd()}/app`)
|
|
11
34
|
process.exit(1)
|
|
@@ -24,6 +47,7 @@ export default defineConfig({
|
|
|
24
47
|
host_provider: 'apache'
|
|
25
48
|
})`)
|
|
26
49
|
}
|
|
50
|
+
const config = require(process.cwd() + '/vader.config.ts').default
|
|
27
51
|
const mode = args.includes('dev') ? 'development' : args.includes('prod') || args.includes('build') ? 'production' : args.includes('init') ? 'init' : args.includes('serve') ? 'serve' : null;
|
|
28
52
|
if (!mode) {
|
|
29
53
|
console.log(`
|
|
@@ -133,6 +157,7 @@ const handleReplacements = (code) => {
|
|
|
133
157
|
b4 = line.replace('useRef(', `this.useRef('${key}',`)
|
|
134
158
|
line = b4
|
|
135
159
|
}
|
|
160
|
+
|
|
136
161
|
newLines.push(line)
|
|
137
162
|
}
|
|
138
163
|
let c = newLines.join('\n')
|
|
@@ -246,9 +271,16 @@ async function generateApp() {
|
|
|
246
271
|
let data = ''
|
|
247
272
|
|
|
248
273
|
}
|
|
249
|
-
|
|
274
|
+
// run all plugins that have onBuildFinish
|
|
275
|
+
let plugins = config.plugins || []
|
|
276
|
+
for (let plugin of plugins) {
|
|
277
|
+
if (plugin.onBuildFinish) {
|
|
278
|
+
await plugin.onBuildFinish(vader)
|
|
279
|
+
}
|
|
280
|
+
}
|
|
250
281
|
})
|
|
251
282
|
|
|
283
|
+
|
|
252
284
|
}
|
|
253
285
|
|
|
254
286
|
function handleFiles() {
|
|
@@ -466,4 +498,4 @@ if (mode == 'development' || mode == 'serve') {
|
|
|
466
498
|
})
|
|
467
499
|
|
|
468
500
|
console.log(ansiColors.green('Server started at http://localhost:' + port || 8080))
|
|
469
|
-
}
|
|
501
|
+
}
|
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,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
|
+
}
|