vaderjs 2.1.6 → 2.1.8

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 CHANGED
@@ -63,6 +63,11 @@ globalThis.window = {
63
63
  pathname: "",
64
64
  },
65
65
  }
66
+
67
+ globalThis.localStorage = {
68
+ setItem: (key, value) => { },
69
+ getItem: (key) => { },
70
+ }
66
71
  try {
67
72
  await Bun.build({
68
73
  entrypoints: [process.env.ENTRYPOINT],
@@ -73,7 +78,7 @@ try {
73
78
  ...(JSON.parse(process.env.DEV) ? { sourcemap: "inline" } : {}),
74
79
  packages: "bundle",
75
80
  env: "inline",
76
- external: ["vaderjs"]
81
+ external: ["vaderjs", "*.png", "*.jpg", "*.jpeg", "*.gif", "*.svg", "*.css"],
77
82
  });
78
83
  } catch (error) {
79
84
  console.error(error)
@@ -81,7 +86,7 @@ try {
81
86
 
82
87
 
83
88
  let builtCode = fs.readFileSync(path.join(process.cwd(), 'dist', process.env.filePath), 'utf-8')
84
-
89
+
85
90
  const handleReplacements = (code) => {
86
91
  let lines = code.split('\n')
87
92
  let newLines = []
@@ -89,6 +94,20 @@ const handleReplacements = (code) => {
89
94
  let hasImport = line.includes('import')
90
95
  if (hasImport && line.includes('vaderjs')) {
91
96
  line = line.replace('vaderjs', '/src/vader/index.js')
97
+ }
98
+ if (hasImport && line.includes('react')) {
99
+ line = line.replace('react', '/src/vader/index.js')
100
+ }
101
+ if(hasImport && line.includes('public') && line.includes('.png') ||
102
+ line.includes('.jpg') || line.includes('.jpeg') || line.includes('.gif') || line.includes('.svg')) {
103
+ let url = line.split('"')[1]
104
+ // replace ../../
105
+ var b4 = url
106
+ let filevariable = line.split("import")[1].split("from")[0].replace(" ", "").replace("{", "").replace("}","")
107
+
108
+ url = url.replace('../../', '').replace('../', '').replace('./', '')
109
+ line = `var ${filevariable} = "${url}"`
110
+ console.log(line)
92
111
  }
93
112
  if (hasImport && line.includes('.css')) {
94
113
  try {
@@ -210,7 +229,27 @@ const generatePage = async (
210
229
  html = instance.render();
211
230
  }
212
231
 
232
+
213
233
  let h = document(html);
234
+ if(process.env.bindes.includes('<link rel="stylesheet" ')){
235
+ // turn stylesheet into inline style
236
+ let links = process.env.bindes.split('<link rel="stylesheet" ')
237
+ let styles = []
238
+ for(let link of links){
239
+ if(link.includes('href')){
240
+ let href = link.split('href=')[1].split('>')[0].replace('"', '').replace('"', '')
241
+ let file = fs.readFileSync(path2.join(process.cwd() + "/dist/", href), 'utf-8')
242
+ styles.push(file)
243
+ }
244
+ }
245
+ let style = styles.join('\n')
246
+ process.env.bindes = `
247
+ <style>
248
+ ${style}
249
+ </style>
250
+ `
251
+ }
252
+
214
253
  if (!fs.existsSync(process.cwd() + "/dist" + path2.dirname(route))) {
215
254
  fs.mkdirSync(process.cwd() + "/dist" + path2.dirname(route), {
216
255
  recursive: true,
package/index.ts CHANGED
@@ -58,7 +58,36 @@ if(isServer){
58
58
  export const useFetch = (url: string, options: any) => {
59
59
  return [null, true, null];
60
60
  };
61
-
61
+ /**
62
+ * @description - Bypasses this error when using state in a non parent function
63
+ * @param funct
64
+ * @param context
65
+ * @returns
66
+ * @example
67
+ * // - src/index.ts
68
+ *
69
+ * export default function useAuth(){
70
+ * let [isAuthenticated, setAuthenticated] = useState(false)
71
+ * }
72
+ *
73
+ * // app/index.jsx
74
+ *
75
+ * export default function(){
76
+ * // this will error because this is not present in the cild function
77
+ * const { isAuthenticated } = useAuth()
78
+ * // to declare this we need to use bound from vaderjs module
79
+ * const { isAuthenticated } = bound(useAuth)()
80
+ * return (
81
+ * <div></div>
82
+ *
83
+ * )
84
+ * }
85
+ */
86
+ export function bound(funct: Function, context: any) {
87
+ return function() {
88
+ return funct.apply(context, arguments);
89
+ };
90
+ }
62
91
  /**
63
92
  * @description - useRef allows you to store a reference to a DOM element
64
93
  * @param value
package/main.js CHANGED
@@ -129,7 +129,15 @@ const handleReplacements = (code) => {
129
129
  let newLines = []
130
130
  for (let line of lines) {
131
131
  let hasImport = line.includes('import')
132
+
133
+ if(hasImport && line.includes('public')){
134
+ // remove ../ from path
135
+
136
+ line = line.replaceAll('../', '').replaceAll('./', '')
132
137
 
138
+ line = line.replace('public', '/public')
139
+ console.log(line)
140
+ }
133
141
  if (hasImport && line.includes('.css')) {
134
142
  try {
135
143
  let isSmallColon = line.includes("'")
@@ -198,6 +206,11 @@ let start = Date.now()
198
206
  async function generateApp() {
199
207
  globalThis.isBuilding = true;
200
208
  console.log(ansiColors.green('Building...'))
209
+ if (mode === 'development') {
210
+ fs.rmdirSync(process.cwd() + '/dist', { recursive: true })
211
+ } else {
212
+ fs.mkdirSync(process.cwd() + '/dist', { recursive: true })
213
+ }
201
214
  let plugins = config.plugins || []
202
215
  for (let plugin of plugins) {
203
216
  if (plugin.onBuildStart) {
@@ -205,11 +218,7 @@ async function generateApp() {
205
218
  }
206
219
  }
207
220
 
208
- if (mode === 'development') {
209
- fs.rmdirSync(process.cwd() + '/dist', { recursive: true })
210
- } else {
211
- fs.mkdirSync(process.cwd() + '/dist', { recursive: true })
212
- }
221
+
213
222
  return new Promise(async (resolve, reject) => {
214
223
  let routes = new Bun.FileSystemRouter({
215
224
  dir: path.join(process.cwd(), '/app'),
@@ -426,56 +435,60 @@ function handleFiles() {
426
435
  globalThis.clients = []
427
436
 
428
437
  if (mode === 'development') {
429
- await generateApp()
430
- await handleFiles()
431
- const watcher = fs.watch(path.join(process.cwd() + '/'), { recursive: true })
432
- let isBuilding = false; // Flag to track build status
433
-
434
- // Initialize a variable to hold the timeout ID
435
- let debounceTimeout;
436
-
437
- // Function to handle file changes with debounce
438
- const handleFileChangeDebounced = async (change, file) => {
439
- if (file.endsWith('.tsx') || file.endsWith('.jsx') || file.endsWith('.css') || file.endsWith('.ts')
440
- && !file.includes('node_module')
441
- ) {
442
- // delete files cache
443
- if (file.endsWith('vader.config.ts')){
444
- delete require.cache[require.resolve(process.cwd() + '/vader.config.ts')]
445
-
446
- config = require(process.cwd() + '/vader.config.ts').default
447
- port = config.port;
448
- host_provider = config.host_provider
449
- host = config.host
450
-
451
- globalThis.config = config
452
- }
453
- if (file.includes('dist')) return
454
- clearTimeout(debounceTimeout);
455
- debounceTimeout = setTimeout(async () => {
456
- if (!isBuilding) { // Check if not already building
457
- isBuilding = true; // Set build flag to true
458
- try {
459
- await generateApp();
460
- await handleFiles();
461
- let t = setTimeout(() => {
462
- clients.forEach(c => {
463
- c.send('reload');
464
- });
465
- clearTimeout(t)
466
- }, 1000)
467
- } catch (error) {
468
- console.error(error);
469
- } finally {
470
- isBuilding = false; // Reset build flag
471
- }
438
+ try {
439
+ await generateApp()
440
+ await handleFiles()
441
+ const watcher = fs.watch(path.join(process.cwd() + '/'), { recursive: true })
442
+ let isBuilding = false; // Flag to track build status
443
+
444
+ // Initialize a variable to hold the timeout ID
445
+ let debounceTimeout;
446
+
447
+ // Function to handle file changes with debounce
448
+ const handleFileChangeDebounced = async (change, file) => {
449
+ if (file.endsWith('.tsx') || file.endsWith('.jsx') || file.endsWith('.css') || file.endsWith('.ts')
450
+ && !file.includes('node_module')
451
+ ) {
452
+ // delete files cache
453
+ if (file.endsWith('vader.config.ts')){
454
+ delete require.cache[require.resolve(process.cwd() + '/vader.config.ts')]
455
+
456
+ config = require(process.cwd() + '/vader.config.ts').default
457
+ port = config.port;
458
+ host_provider = config.host_provider
459
+ host = config.host
460
+
461
+ globalThis.config = config
472
462
  }
473
- }, 500);
474
- }
475
- };
476
-
477
- // Event listeners with debounced handling
478
- watcher.on('change', handleFileChangeDebounced);
463
+ if (file.includes('dist')) return
464
+ clearTimeout(debounceTimeout);
465
+ debounceTimeout = setTimeout(async () => {
466
+ if (!isBuilding) { // Check if not already building
467
+ isBuilding = true; // Set build flag to true
468
+ try {
469
+ await generateApp();
470
+ await handleFiles();
471
+ let t = setTimeout(() => {
472
+ clients.forEach(c => {
473
+ c.send('reload');
474
+ });
475
+ clearTimeout(t)
476
+ }, 1000)
477
+ } catch (error) {
478
+ console.error(error);
479
+ } finally {
480
+ isBuilding = false; // Reset build flag
481
+ }
482
+ }
483
+ }, 500);
484
+ }
485
+ };
486
+
487
+ // Event listeners with debounced handling
488
+ watcher.on('change', handleFileChangeDebounced);
489
+ } catch (error) {
490
+ console.error(error)
491
+ }
479
492
 
480
493
  }
481
494
  else if (mode == 'production') {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vaderjs",
3
- "version": "2.1.6",
3
+ "version": "2.1.8",
4
4
  "description": "A simple and powerful JavaScript library for building modern web applications.",
5
5
  "bin": {
6
6
  "vaderjs": "./main.js"
@@ -14,6 +14,10 @@ function checkIfTailwindInstalled() {
14
14
  function initTailwind() {
15
15
  const tailwindConfig = path.resolve(process.cwd(), 'tailwind.config.js')
16
16
  const postcssConfig = path.resolve(process.cwd(), 'postcss.config.js')
17
+ const tailwindCssFile = path.join(process.cwd(), '/public/styles.css')
18
+ if(!fs.existsSync(tailwindCssFile)){
19
+ fs.writeFileSync(tailwindCssFile, `@import "tailwindcss"`)
20
+ }
17
21
  if (!fs.existsSync(tailwindConfig)) {
18
22
  fs.writeFileSync(postcssConfig, `module.exports = {
19
23
  plugins: {
@@ -39,23 +43,25 @@ module.exports = {
39
43
  export default {
40
44
  name: 'tailwindcss',
41
45
  description: 'TailwindCSS plugin for Vader.js',
42
- version: '0.0.1',
46
+ version: '0.0.2',
43
47
  onBuildStart: async (vader) => {
44
48
  if (!checkIfTailwindInstalled()) {
45
- console.error('TailwindCSS is not installed. Please install it using `bun install tailwindcss postcss-cli autoprefixer`')
49
+ console.error('TailwindCSS is not installed. Please install it using `bun install tailwindcss @tailwindcss/postcss postcss \n more info: https://tailwindcss.com/docs/installation/using-postcss`')
46
50
  process.exit(1)
47
51
  }else{
48
52
  initTailwind()
53
+ console.log('Building TailwindCSS...')
49
54
 
50
55
  if(vader.isDev){
51
56
  vader.onFileChange('tailwind.config.js', async () => {
52
57
  console.log('Rebuilding TailwindCSS...')
53
58
  await vader.runCommand(['bun', 'run', 'postcss', './public/styles.css', '-o', 'dist/public/tailwind.css'])
54
- console.log('TailwindCSS rebuilt successfully!')
59
+ vader.injectHTML(`<link rel="stylesheet" href="/public/tailwind.css">`)
55
60
  })
56
61
  }
57
62
  await vader.runCommand(['bun', 'run', 'postcss', './public/styles.css', '-o', 'dist/public/tailwind.css'])
58
- vader.injectHTML(`<style>${fs.readFileSync(path.resolve(process.cwd(), 'dist/public/tailwind.css'))}</style>`)
63
+ vader.injectHTML(`<link rel="stylesheet" href="/public/tailwind.css">`)
64
+
59
65
  }
60
66
 
61
67
  return