vaderjs 1.3.3-7bn27417d42e1 → 1.3.3-7bn28b17d42e1

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/vader.js +65 -8
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "vaderjs",
3
3
  "description": "A Reactive library aimed to helping you build reactive applications inspired by react.js",
4
4
  "module": "vader.js",
5
- "version": "1.3.3-7bn27417d42e1",
5
+ "version": "1.3.3-7bn28b17d42e1",
6
6
  "bin": {
7
7
  "vader": "./vader.js"
8
8
  },
package/vader.js CHANGED
@@ -467,7 +467,7 @@ function Compiler(func, file) {
467
467
  spreadContent = spreadContent.replaceAll(/\s+/g, " ").trim()
468
468
  spreadContent = spreadContent.replace(')}', ')').replace('}}', '}')
469
469
 
470
- propstring += spreadContent + ','
470
+ propstring += spreadContent + ','
471
471
  hasSpread = true
472
472
 
473
473
  }
@@ -807,15 +807,17 @@ function Compiler(func, file) {
807
807
 
808
808
  globalThis.isBuilding = false
809
809
  globalThis.isWriting = null
810
- const glb = await glob("**/**/**/**.{jsx,js}", {
811
- ignore: ["node_modules/**/*", "dist/**/*"],
812
- cwd: process.cwd() + '/pages/',
813
- absolute: true,
814
- recursive: true
815
- });
810
+
816
811
  let hasRendered = []
817
812
 
818
813
  async function Build() {
814
+ const glb = await glob("**/**/**/**.{jsx,js}", {
815
+ ignore: ["node_modules/**/*", "dist/**/*"],
816
+ cwd: process.cwd() + '/pages/',
817
+ absolute: true,
818
+ recursive: true
819
+ });
820
+
819
821
  globalThis.isBuilding = true
820
822
  console.log(globalThis.isProduction ? 'Creating Optimized Production Build\n' : '')
821
823
  let str = `Page \t\t\t\t Size\n`
@@ -1060,6 +1062,39 @@ async function Build() {
1060
1062
  globalThis.routes.push({ fileName: fileName, url: obj.url, html: '/' + (isBasePath ? 'index.html' : `${obj.url}/` + 'index.html') })
1061
1063
  }
1062
1064
 
1065
+ // check if route has a index.html file
1066
+
1067
+ if (!fs.existsSync(process.cwd() + '/dist/' + (isBasePath ? 'index.html' : `${obj.url}/` + 'index.html'))
1068
+ && !obj.url.includes(':') && !globalThis.isProduction
1069
+ ) {
1070
+ let document = `<!DOCTYPE html>
1071
+ <html lang="en">
1072
+ <head>
1073
+ <meta charset="UTF-8">
1074
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
1075
+ <title>${obj.url}</title>
1076
+ <script>
1077
+ window.routes = JSON.parse('${JSON.stringify(globalThis.routes)}')
1078
+ </script>
1079
+ <script type="module">
1080
+ import VaderRouter from '/router.js'
1081
+ const router = new VaderRouter('${obj.url}')
1082
+ router.get('${obj.url}', async (req, res) => {
1083
+ let module = await import('/${obj.url === '/' ? 'index.js' : obj.url + '.js'}')
1084
+ if(Object.keys(module).includes('$prerender') && !module.$prerender){
1085
+ document.head.setAttribute('prerender', 'false')
1086
+ }
1087
+ res.render(module, req, res, module.$metadata)
1088
+ })
1089
+ router.listen(3000)
1090
+ </script>
1091
+ </head>
1092
+ <body>
1093
+ <div id="root"></div>
1094
+ </body>
1095
+ </html>`
1096
+ writer(process.cwd() + '/dist/' + (isBasePath ? 'index.html' : `${obj.url}/` + 'index.html'), document)
1097
+ }
1063
1098
 
1064
1099
  let stats = {
1065
1100
  route: obj.url.padEnd(30),
@@ -1252,7 +1287,29 @@ async function Build() {
1252
1287
 
1253
1288
  globalThis.isProduction ? console.log(`Total Bundle Size: ${Math.round(bundleSize / 1000)}kb`) : null
1254
1289
  bundleSize = 0;
1290
+ if (!globalThis.isBuilding) {
1291
+ let folders = fs.readdirSync(process.cwd() + '/dist/', { withFileTypes: true })
1292
+
1293
+ folders.forEach((folder) => {
1294
+ // exclude files
1295
+ if (folder.name.includes('src') || folder.name.includes('public') || folder.name.includes('pages')
1296
+ || !folder.isDirectory()
1297
+ ) {
1298
+ return
1299
+ }
1255
1300
 
1301
+ let existsInPages = fs.existsSync(process.cwd() + '/pages/' + folder.name)
1302
+
1303
+ if (existsInPages) {
1304
+ return
1305
+ }
1306
+ fs.rm(process.cwd() + '/dist/' + folder.name, { recursive: true }, (err) => {
1307
+ if (err) {
1308
+ throw err
1309
+ }
1310
+ })
1311
+ })
1312
+ }
1256
1313
  return true
1257
1314
  }
1258
1315
  const s = (port) => {
@@ -1262,7 +1319,7 @@ const s = (port) => {
1262
1319
  const validExtensions = ['.js', '.css', '.mjs', '.cjs', '.html', '.json', '.png', '.jpg', '.jpeg', '.gif', '.svg', '.mp4', '.webm', '.ogg', '.map']
1263
1320
 
1264
1321
  if (!validExtensions.some(ext => req.url.endsWith(ext))) {
1265
- req.url = req.url !== '/' ? req.url.split('/')[1] : req.url;
1322
+ req.url = req.url + '/'
1266
1323
  req.url = path.join(process.cwd(), 'dist', req.url, 'index.html');
1267
1324
  } else {
1268
1325
  req.url = path.join(process.cwd(), 'dist', req.url);