vaderjs 1.6.5 → 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/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
+ })
101
98
 
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,6 +179,10 @@ 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()}`)
182
+ for (let fn of fnmap) {
183
+ await fn.fn(vader)
184
+ fnmap = fnmap.filter(v => v.code !== fn.code)
185
+ }
173
186
  // remove files from dist
174
187
  if (mode === 'development') {
175
188
  fs.rmdirSync(process.cwd() + '/dist', { recursive: true })
@@ -271,16 +284,16 @@ async function generateApp() {
271
284
  let data = ''
272
285
 
273
286
  }
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
- }
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
+ }
281
294
  })
282
295
 
283
-
296
+
284
297
  }
285
298
 
286
299
  function handleFiles() {
@@ -408,10 +421,10 @@ if (mode === 'development') {
408
421
  // Event listeners with debounced handling
409
422
  watcher.on('change', handleFileChangeDebounced);
410
423
 
411
- }
412
- else if(mode == 'production'){
424
+ }
425
+ else if (mode == 'production') {
413
426
  await handleFiles()
414
- await generateApp()
427
+ await generateApp()
415
428
  }
416
429
  else {
417
430
  if (isBuilding) console.log(`Build complete in ${Date.now() - start}ms at ${new Date().toLocaleTimeString()}`);
@@ -496,6 +509,6 @@ if (mode == 'development' || mode == 'serve') {
496
509
 
497
510
  }
498
511
  })
499
-
512
+
500
513
  console.log(ansiColors.green('Server started at http://localhost:' + port || 8080))
501
- }
514
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vaderjs",
3
- "version": "1.6.5",
3
+ "version": "1.6.6",
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}'],
@@ -34,17 +42,20 @@ export default {
34
42
  version: '0.0.1',
35
43
  onBuildFinish: async (vader) => {
36
44
  if (!checkIfTailwindInstalled()) {
37
- console.error('TailwindCSS is not installed. Please install it using `bun install tailwindcss`')
45
+ console.error('TailwindCSS is not installed. Please install it using `bun install tailwindcss postcss-cli autoprefixer`')
38
46
  process.exit(1)
39
47
  }else{
40
48
  initTailwind()
49
+ vader.onBuildStart(() => {
50
+ vader.injectHTML(`<link rel="stylesheet" href="/public/tailwind.css">`)
51
+ })
41
52
  vader.onFileChange('tailwind.config.js', async () => {
42
53
  console.log('Rebuilding TailwindCSS...')
43
- await vader.runCommand(['bun', 'run', 'tailwindcss', 'build', '-o', 'public/styles.css'])
54
+ await vader.runCommand(['bun', 'run', 'postcss', 'public/styles.css', '-o', 'dist/public/tailwind.css'])
44
55
  console.log('TailwindCSS rebuilt successfully!')
45
56
  })
46
- vader.runCommand(['bun', 'run', 'tailwindcss', 'build', '-o', 'public/styles.css'])
47
- }
57
+ vader.runCommand(['bun', 'run', 'postcss', 'public/styles.css', '-o', 'dist/public/tailwind.css'])
58
+ }
48
59
  },
49
60
 
50
61
  }