-const { mkdir, readdir, rm, writeFile } = require('fs/promises');
-const { debuglog, promisify } = require('util');
-const { ncp } = require('ncp');
+const { cp, mkdir, readdir, writeFile } = require('fs/promises');
+const { debuglog } = require('util');
const { resolve, join } = require('path');
+const { rmIfExists } = require('../utils');
const internals = {
kArchiveName: resolve(join(__dirname, '../..', '.gemlog')),
kIndexName: 'index.gmi',
kGeminiRe: /\.gmi$/i,
- ncp: promisify(ncp),
debuglog: debuglog('blog'),
buildUrl(id, slug) {
try {
internals.debuglog('Removing index');
- await rm(internals.kArchiveName, { recursive: true });
+ await rmIfExists(internals.kArchiveName);
}
finally {
internals.debuglog('Creating index');
await writeFile(indexFile, index);
internals.debuglog('Copying posts to archive');
- await internals.ncp(archiveDirectory, internals.kArchiveName);
+ await cp(archiveDirectory, internals.kArchiveName, { recursive: true });
}
};