refactor: move cache and src css

This commit is contained in:
Julien Oculi 2024-01-14 21:10:16 +01:00
parent d912ea247d
commit 9286ec758d
2 changed files with 12 additions and 10 deletions

View file

@ -3,7 +3,7 @@ import { ensureDir } from '$std/fs/mod.ts'
import { parse, resolve } from '$std/path/mod.ts'
console.log('building styles starts')
await ensureDir('_fresh')
await ensureDir('_fresh/static')
try {
//prevent Deno from exiting before bundle
@ -12,7 +12,7 @@ try {
const cssImports = new Map()
const { code, map } = await bundleAsync({
filename: './static/stylesheets/main.css',
filename: './src/stylesheets/main.css',
minify: true,
sourceMap: true,
resolver: {
@ -29,22 +29,24 @@ try {
//update cache for new remote
const response = await fetch(specifier)
const file = await response.text()
const file = await response.arrayBuffer()
const hash = new Uint8Array(await crypto.subtle.digest('SHA-256', file))
const filename = [...hash].map(value => value.toString(16).padStart(2, '0')).join('')
const filename = `_fresh/${crypto.randomUUID()}`
await Deno.writeTextFile(filename, file)
cssImports.set(specifier, filename)
return filename
const filepath = `_fresh/${filename}`
await Deno.writeFile(filepath, new Uint8Array(file))
cssImports.set(specifier, filepath)
return filepath
},
},
})
await Deno.writeTextFile(
'./_fresh/styles.css',
'./static/styles.css',
new TextDecoder().decode(code),
)
await Deno.writeTextFile(
'./_fresh/styles.map.css',
'./static/styles.map.css',
new TextDecoder().decode(map!),
)
} catch (error) {

View file

@ -8,7 +8,7 @@
"build": "deno run -A dev.ts build",
"preview": "deno run -A main.ts",
"update": "deno run -A -r https://fresh.deno.dev/update .",
"assets:watch": "deno run -A --watch=static/stylesheets/ build.ts",
"assets:watch": "deno run -A --watch=src/ build.ts",
"assets": "deno run -A build.ts"
},
"fmt": {