#!/usr/bin/env bun import { fileURLToPath } from "url"; import fs from "node:fs/promises"; import { basename, normalize } from "node:path"; function ignore_exist_error(fn: (...args: any[]) => Promise) { return async (...args: any[]) => { try { await fn(...args); } catch (error: any) { if (error.code !== "EEXIST") { throw error; // Re-throw the error if it's not "file exists" } } }; } const mkdir = ignore_exist_error(fs.mkdir); const symlink = ignore_exist_error(fs.symlink); const def = await Bun.file("package.json").json(); const dependencies = Object.keys(def.dependencies); for (const pkg of dependencies) { const path = normalize(fileURLToPath(import.meta.resolve(pkg))); const file = Bun.file(import.meta.resolve(pkg)); const type = file.type.split(";").at(0); const filename = basename(path); switch (type) { case "text/x-scss": await mkdir(`sass/${pkg}`, { recursive: true }); await symlink(path, `sass/${pkg}/${filename}`); console.log(`${path} -> sass/${pkg}/${filename}`); break; case "text/javascript": // console.log("es JS") break; } } console.log(); console.log("Dependencies linked!");