Skip to main content
Go to Latest
File
import slash from 'https://esm.sh/slash@5.0.0'import { ensureDir } from 'https://deno.land/std@v0.172.0/fs/mod.ts'import { resolve } from 'https://deno.land/std@v0.172.0/path/mod.ts'
export const encode = (str: string) => new TextEncoder().encode(str)
export const decode = (buf: BufferSource) => new TextDecoder().decode(buf)
export const hash = async (str: string, alg: AlgorithmIdentifier = 'SHA-256') => await crypto.subtle.digest(alg, encode(str))
export async function* files(dir: string): AsyncIterableIterator<string> { const dirents = Deno.readDir(dir) for await (const dirent of dirents) { const res = resolve(dir, dirent.name)
if (dirent.isDirectory) yield* files(res) else yield res }}
export const copyDir = async (from: string, to: string) => { for await (const file of files(from)) { if (file.includes('.git')) continue
const filePath = file.replace(from, to) , dirPathArray = slash(file.replace(from, to)).split('/')
dirPathArray.pop()
const dirPath = dirPathArray.join('/')
await ensureDir(dirPath)
await Deno.copyFile(file, filePath) }}