vaderjs 1.6.5 → 1.6.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 CHANGED
@@ -7,28 +7,7 @@ globalThis.isBuilding = false;
7
7
  import fs from 'fs'
8
8
  import path from 'path'
9
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
10
 
29
- })
30
- }
31
- }
32
11
  if (!fs.existsSync(process.cwd() + '/app') && !args.includes('init')) {
33
12
  console.error(`App directory not found in ${process.cwd()}/app`)
34
13
  process.exit(1)
@@ -47,7 +26,7 @@ export default defineConfig({
47
26
  host_provider: 'apache'
48
27
  })`)
49
28
  }
50
- const config = require(process.cwd() + '/vader.config.ts').default
29
+ const config = require(process.cwd() + '/vader.config.ts').default
51
30
  const mode = args.includes('dev') ? 'development' : args.includes('prod') || args.includes('build') ? 'production' : args.includes('init') ? 'init' : args.includes('serve') ? 'serve' : null;
52
31
  if (!mode) {
53
32
  console.log(`
@@ -98,7 +77,37 @@ if (!fs.existsSync(process.cwd() + '/jsconfig.json')) {
98
77
  }
99
78
 
100
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
+
101
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
+ }
102
111
  const handleReplacements = (code) => {
103
112
  let lines = code.split('\n')
104
113
  let newLines = []
@@ -157,7 +166,7 @@ const handleReplacements = (code) => {
157
166
  b4 = line.replace('useRef(', `this.useRef('${key}',`)
158
167
  line = b4
159
168
  }
160
-
169
+
161
170
  newLines.push(line)
162
171
  }
163
172
  let c = newLines.join('\n')
@@ -170,7 +179,13 @@ async function generateApp() {
170
179
  globalThis.isBuilding = true;
171
180
  console.log(ansiColors.green('Building...'))
172
181
  console.log(`Starting build at ${new Date().toLocaleTimeString()}`)
173
- // remove files from dist
182
+ let plugins = config.plugins || []
183
+ for (let plugin of plugins) {
184
+ if (plugin.onBuildStart) {
185
+ await plugin.onBuildStart(vader)
186
+ }
187
+ }
188
+
174
189
  if (mode === 'development') {
175
190
  fs.rmdirSync(process.cwd() + '/dist', { recursive: true })
176
191
  } else {
@@ -271,16 +286,16 @@ async function generateApp() {
271
286
  let data = ''
272
287
 
273
288
  }
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
- }
289
+ // run all plugins that have onBuildFinish
290
+ let plugins = config.plugins || []
291
+ for (let plugin of plugins) {
292
+ if (plugin.onBuildFinish) {
293
+ await plugin.onBuildFinish(vader)
294
+ }
295
+ }
281
296
  })
282
297
 
283
-
298
+
284
299
  }
285
300
 
286
301
  function handleFiles() {
@@ -408,10 +423,10 @@ if (mode === 'development') {
408
423
  // Event listeners with debounced handling
409
424
  watcher.on('change', handleFileChangeDebounced);
410
425
 
411
- }
412
- else if(mode == 'production'){
426
+ }
427
+ else if (mode == 'production') {
413
428
  await handleFiles()
414
- await generateApp()
429
+ await generateApp()
415
430
  }
416
431
  else {
417
432
  if (isBuilding) console.log(`Build complete in ${Date.now() - start}ms at ${new Date().toLocaleTimeString()}`);
@@ -496,6 +511,6 @@ if (mode == 'development' || mode == 'serve') {
496
511
 
497
512
  }
498
513
  })
499
-
514
+
500
515
  console.log(ansiColors.green('Server started at http://localhost:' + port || 8080))
501
- }
516
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vaderjs",
3
- "version": "1.6.5",
3
+ "version": "1.6.7",
4
4
  "description": "A simple and powerful JavaScript library for building modern web applications.",
5
5
  "bin": {
6
6
  "vaderjs": "./main.js"
@@ -13,7 +13,15 @@ function checkIfTailwindInstalled() {
13
13
 
14
14
  function initTailwind() {
15
15
  const tailwindConfig = path.resolve(process.cwd(), 'tailwind.config.js')
16
+ const postcssConfig = path.resolve(process.cwd(), 'postcss.config.js')
16
17
  if (!fs.existsSync(tailwindConfig)) {
18
+ fs.writeFileSync(postcssConfig, `module.exports = {
19
+ plugins: {
20
+ tailwindcss: {},
21
+ autoprefixer: {},
22
+ }
23
+ }`)
24
+
17
25
  fs.writeFileSync(tailwindConfig, `/** @type {import('tailwindcss').Config} */
18
26
  module.exports = {
19
27
  content: ['./src/**/*.{html,js,jsx,ts,tsx}', './app/**/*.{html,js,jsx,ts,tsx}'],
@@ -32,19 +40,23 @@ export default {
32
40
  name: 'tailwindcss',
33
41
  description: 'TailwindCSS plugin for Vader.js',
34
42
  version: '0.0.1',
43
+ onBuildStart: async (vader) => {
44
+ vader.injectHTML(`<link rel="stylesheet" href="/public/tailwind.css">`)
45
+ },
35
46
  onBuildFinish: async (vader) => {
36
47
  if (!checkIfTailwindInstalled()) {
37
- console.error('TailwindCSS is not installed. Please install it using `bun install tailwindcss`')
48
+ console.error('TailwindCSS is not installed. Please install it using `bun install tailwindcss postcss-cli autoprefixer`')
38
49
  process.exit(1)
39
50
  }else{
40
51
  initTailwind()
52
+
41
53
  vader.onFileChange('tailwind.config.js', async () => {
42
54
  console.log('Rebuilding TailwindCSS...')
43
55
  await vader.runCommand(['bun', 'run', 'tailwindcss', 'build', '-o', 'public/styles.css'])
44
56
  console.log('TailwindCSS rebuilt successfully!')
45
57
  })
46
- vader.runCommand(['bun', 'run', 'tailwindcss', 'build', '-o', 'public/styles.css'])
47
- }
58
+ vader.runCommand(['bun', 'run', 'postcss', 'public/styles.css', '-o', 'dist/public/tailwind.css'])
59
+ }
48
60
  },
49
61
 
50
62
  }