]> git.r.bdr.sh - rbdr/blog/blobdiff - lib/generators/static.js
Update version
[rbdr/blog] / lib / generators / static.js
index a0856a37ad558eadf4bc74017822b1b7b8a0c681..416076c966e084d06bd5d1680cedbfbc238b1282 100644 (file)
@@ -1,14 +1,13 @@
 'use strict';
 
 'use strict';
 
-const { access, rm } = require('fs/promises');
-const { ncp } = require('ncp');
+const { access, cp } = require('fs/promises');
 const { join } = require('path');
 const { join } = require('path');
-const { debuglog, promisify } = require('util');
+const { debuglog } = require('util');
+const { rmIfExists } = require('../utils');
+const { kFileNotFoundError } = require('../constants');
 
 const internals = {
 
 const internals = {
-  ncp: promisify(ncp),
   debuglog: debuglog('blog'),
   debuglog: debuglog('blog'),
-
   kAssetsDirectoryName: 'assets'
 };
 
   kAssetsDirectoryName: 'assets'
 };
 
@@ -25,7 +24,7 @@ module.exports = async function StaticGenerator(source, target, posts) {
   const assetsTarget = join(target, internals.kAssetsDirectoryName);
 
   internals.debuglog(`Removing ${assetsTarget}`);
   const assetsTarget = join(target, internals.kAssetsDirectoryName);
 
   internals.debuglog(`Removing ${assetsTarget}`);
-  await rm(assetsTarget, { recursive: true });
+  await rmIfExists(assetsTarget);
 
   for (let i = 0; i < posts.length; ++i) {
     const postSourcePath = join(source, `${i}`);
 
   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}`);
       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) {
     }
     catch (error) {
-      if (error.code === internals.kFileNotFoundError) {
+      if (error.code === kFileNotFoundError) {
         internals.debuglog(`Skipping ${i}`);
         continue;
       }
         internals.debuglog(`Skipping ${i}`);
         continue;
       }