@vyckr/tachyon 1.1.0 → 1.1.1

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/src/client/yon.ts +30 -20
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vyckr/tachyon",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
4
4
  "author": "Chidelma",
5
5
  "repository": {
6
6
  "type": "git",
package/src/client/yon.ts CHANGED
@@ -2,6 +2,7 @@ import { JSDOM } from 'jsdom'
2
2
  import Router from "../router.js";
3
3
  import { EventEmitter } from 'node:stream';
4
4
  import { BunRequest } from 'bun';
5
+ import { exists } from 'node:fs/promises';
5
6
 
6
7
  export default class Yon {
7
8
 
@@ -246,29 +247,35 @@ export default class Yon {
246
247
 
247
248
  private static async bundleAssets() {
248
249
 
249
- const routes = Array.from(new Bun.Glob(`**/*`).scanSync({ cwd: Router.assetsPath }))
250
+ if(await exists(Router.assetsPath)) {
250
251
 
251
- for(const route of routes) {
252
+ const routes = Array.from(new Bun.Glob(`**/*`).scanSync({ cwd: Router.assetsPath }))
252
253
 
253
- Router.reqRoutes[`/assets/${route}`] = {
254
- GET: async () => new Response(await Bun.file(`${Router.assetsPath}/${route}`).text())
254
+ for(const route of routes) {
255
+
256
+ Router.reqRoutes[`/assets/${route}`] = {
257
+ GET: async () => new Response(await Bun.file(`${Router.assetsPath}/${route}`).text())
258
+ }
255
259
  }
256
260
  }
257
261
  }
258
262
 
259
263
  private static async bundlePages() {
260
264
 
261
- const routes = Array.from(new Bun.Glob(`**/${Yon.htmlMethod}`).scanSync({ cwd: Router.routesPath }))
265
+ if(await exists(Router.routesPath)) {
266
+
267
+ const routes = Array.from(new Bun.Glob(`**/${Yon.htmlMethod}`).scanSync({ cwd: Router.routesPath }))
262
268
 
263
- for(const route of routes) {
269
+ for(const route of routes) {
264
270
 
265
- await Router.validateRoute(route)
271
+ await Router.validateRoute(route)
266
272
 
267
- const data = await Bun.file(`${Router.routesPath}/${route}`).text()
273
+ const data = await Bun.file(`${Router.routesPath}/${route}`).text()
268
274
 
269
- const { html, script, style } = Yon.extractComponents(data)
270
-
271
- await Yon.addToStatix(html, script, style, `${route}.${script.lang || 'js'}`, 'pages')
275
+ const { html, script, style } = Yon.extractComponents(data)
276
+
277
+ await Yon.addToStatix(html, script, style, `${route}.${script.lang || 'js'}`, 'pages')
278
+ }
272
279
  }
273
280
 
274
281
  const nfFile = Bun.file(`${process.cwd()}/404.html`)
@@ -282,21 +289,24 @@ export default class Yon {
282
289
 
283
290
  private static async bundleComponents() {
284
291
 
285
- const components = Array.from(new Bun.Glob(`**/*.html`).scanSync({ cwd: Router.componentsPath }))
292
+ if(await exists(Router.componentsPath)) {
286
293
 
287
- for(let comp of components) {
294
+ const components = Array.from(new Bun.Glob(`**/*.html`).scanSync({ cwd: Router.componentsPath }))
288
295
 
289
- const folders = comp.split('/')
296
+ for(let comp of components) {
290
297
 
291
- const filename = folders[folders.length - 1].replace('.html', '')
298
+ const folders = comp.split('/')
292
299
 
293
- Yon.compMapping.set(filename, comp.replace('.html', '.js'))
300
+ const filename = folders[folders.length - 1].replace('.html', '')
294
301
 
295
- const data = await Bun.file(`${Router.componentsPath}/${comp}`).text()
302
+ Yon.compMapping.set(filename, comp.replace('.html', '.js'))
296
303
 
297
- const { html, script, style } = Yon.extractComponents(data)
298
-
299
- await Yon.addToStatix(html, script, style, comp, 'components')
304
+ const data = await Bun.file(`${Router.componentsPath}/${comp}`).text()
305
+
306
+ const { html, script, style } = Yon.extractComponents(data)
307
+
308
+ await Yon.addToStatix(html, script, style, comp, 'components')
309
+ }
300
310
  }
301
311
  }
302
312