@vyckr/tachyon 1.0.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vyckr/tachyon",
3
- "version": "1.0.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
 
@@ -48,7 +49,7 @@ export default class Yon {
48
49
  styles += `${msg}\n`
49
50
  })
50
51
 
51
- await Promise.all([Yon.bundleDependencies(), Yon.bundleComponents(), Yon.bundlePages()])
52
+ await Promise.all([Yon.bundleDependencies(), Yon.bundleComponents(), Yon.bundlePages(), Yon.bundleAssets()])
52
53
 
53
54
  await Bun.write(Bun.file(`${import.meta.dir}/routes.json`), JSON.stringify(Router.routeSlugs))
54
55
 
@@ -244,19 +245,37 @@ export default class Yon {
244
245
  }
245
246
  }
246
247
 
248
+ private static async bundleAssets() {
249
+
250
+ if(await exists(Router.assetsPath)) {
251
+
252
+ const routes = Array.from(new Bun.Glob(`**/*`).scanSync({ cwd: Router.assetsPath }))
253
+
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
+ }
259
+ }
260
+ }
261
+ }
262
+
247
263
  private static async bundlePages() {
248
264
 
249
- 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 }))
250
268
 
251
- for(const route of routes) {
269
+ for(const route of routes) {
252
270
 
253
- await Router.validateRoute(route)
271
+ await Router.validateRoute(route)
254
272
 
255
- const data = await Bun.file(`${Router.routesPath}/${route}`).text()
273
+ const data = await Bun.file(`${Router.routesPath}/${route}`).text()
256
274
 
257
- const { html, script, style } = Yon.extractComponents(data)
258
-
259
- 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
+ }
260
279
  }
261
280
 
262
281
  const nfFile = Bun.file(`${process.cwd()}/404.html`)
@@ -270,21 +289,24 @@ export default class Yon {
270
289
 
271
290
  private static async bundleComponents() {
272
291
 
273
- const components = Array.from(new Bun.Glob(`**/*.html`).scanSync({ cwd: Router.componentsPath }))
292
+ if(await exists(Router.componentsPath)) {
274
293
 
275
- for(let comp of components) {
294
+ const components = Array.from(new Bun.Glob(`**/*.html`).scanSync({ cwd: Router.componentsPath }))
276
295
 
277
- const folders = comp.split('/')
296
+ for(let comp of components) {
278
297
 
279
- const filename = folders[folders.length - 1].replace('.html', '')
298
+ const folders = comp.split('/')
280
299
 
281
- Yon.compMapping.set(filename, comp.replace('.html', '.js'))
300
+ const filename = folders[folders.length - 1].replace('.html', '')
282
301
 
283
- const data = await Bun.file(`${Router.componentsPath}/${comp}`).text()
302
+ Yon.compMapping.set(filename, comp.replace('.html', '.js'))
284
303
 
285
- const { html, script, style } = Yon.extractComponents(data)
286
-
287
- 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
+ }
288
310
  }
289
311
  }
290
312
 
package/src/router.ts CHANGED
@@ -19,6 +19,7 @@ export default class Router {
19
19
 
20
20
  static readonly routesPath = `${process.cwd()}/routes`
21
21
  static readonly componentsPath = `${process.cwd()}/components`
22
+ static readonly assetsPath = `${process.cwd()}/assets`
22
23
 
23
24
  private static readonly allMethods = process.env.ALLOW_METHODS ? process.env.ALLOW_METHODS.split(',') : ['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'HEAD', 'OPTIONS']
24
25