X-Git-Url: https://git.r.bdr.sh/rbdr/blog/blobdiff_plain/db7b464d701c7d48777ddd38a10f69093cd5442c..9eac24780006862171b85858b40db0f29f494e76:/lib/generators/static.js?ds=inline diff --git a/lib/generators/static.js b/lib/generators/static.js index eb3c631..416076c 100644 --- a/lib/generators/static.js +++ b/lib/generators/static.js @@ -1,14 +1,13 @@ 'use strict'; -const { access, rmdir } = require('fs/promises'); -const { ncp } = require('ncp'); +const { access, cp } = require('fs/promises'); const { join } = require('path'); -const { debuglog, promisify } = require('util'); +const { debuglog } = require('util'); +const { rmIfExists } = require('../utils'); +const { kFileNotFoundError } = require('../constants'); const internals = { - ncp: promisify(ncp), debuglog: debuglog('blog'), - kAssetsDirectoryName: 'assets' }; @@ -25,7 +24,7 @@ module.exports = async function StaticGenerator(source, target, posts) { const assetsTarget = join(target, internals.kAssetsDirectoryName); internals.debuglog(`Removing ${assetsTarget}`); - await rmdir(assetsTarget, { recursive: true }); + await rmIfExists(assetsTarget); for (let i = 0; i < posts.length; ++i) { const postSourcePath = join(source, `${i}`); @@ -36,10 +35,10 @@ module.exports = async function StaticGenerator(source, target, posts) { const assetsSource = join(postSourcePath, internals.kAssetsDirectoryName); internals.debuglog(`Copying ${assetsSource} to ${assetsTarget}`); - await internals.ncp(assetsSource, assetsTarget); + await cp(assetsSource, assetsTarget, { recursive: true }); } catch (error) { - if (error.code === internals.kFileNotFoundError) { + if (error.code === kFileNotFoundError) { internals.debuglog(`Skipping ${i}`); continue; }