X-Git-Url: https://git.r.bdr.sh/rbdr/blog/blobdiff_plain/36a4680d18de012e2e5c732f9db161dafa884344..172f4c8807d44ebe38c7f227b7fdc2d6a9dbe323:/lib/generators/static.js diff --git a/lib/generators/static.js b/lib/generators/static.js deleted file mode 100644 index 45f5a04..0000000 --- a/lib/generators/static.js +++ /dev/null @@ -1,48 +0,0 @@ -import { access, cp, readdir } from 'fs/promises'; -import { constants } from 'fs'; -import { join } from 'path'; -import { debuglog } from 'util'; -import { kFileNotFoundError } from '../constants.js'; - -const internals = { - debuglog: debuglog('blog'), - kAssetsDirectoryName: 'assets' -}; - -/** - * Generates the static assets required for the blog - * - * @name StaticGenerator - * @param {string} source the source directory - * @param {string} target the target directory - * @param {Array.} posts the list of posts - */ -export default async function StaticGenerator(source, target, _) { - - try { - await access(source, constants.R_OK); - - const entries = await readdir(source, { withFileTypes: true }); - for (const entry of entries) { - const sourceAsset = join(source, entry.name); - const targetAsset = join(target, entry.name); - - internals.debuglog(`Copying ${sourceAsset} to ${targetAsset}`); - - if (entry.isDirectory()) { - await cp(sourceAsset, targetAsset, { recursive: true }); - } - else { - await cp(sourceAsset, targetAsset); - } - } - } - catch (error) { - if (error.code === kFileNotFoundError) { - internals.debuglog(`No static directory found in ${source}`); - return; - } - - throw error; - } -}