]>
git.r.bdr.sh - rbdr/blog/blob - lib/generators/static.js
60719e2ef5ee7e1fbe7159a92c321da7b1f6b7d9
3 import { access
, cp
, readdir
} from 'fs/promises';
4 import { constants
} from 'fs';
5 import { join
} from 'path';
6 import { debuglog
} from 'util';
7 import { kFileNotFoundError
} from '../constants.js';
10 debuglog: debuglog('blog'),
11 kAssetsDirectoryName: 'assets'
15 * Generates the static assets required for the blog
17 * @name StaticGenerator
18 * @param {string} source the source directory
19 * @param {string} target the target directory
20 * @param {Array.<Blog.tPost>} posts the list of posts
22 export default async
function StaticGenerator(source
, target
, _
) {
25 await
access(source
, constants
.R_OK
);
27 const entries
= await
readdir(source
, { withFileTypes: true });
28 for (const entry
of entries
) {
29 const sourceAsset
= join(source
, entry
.name
);
30 const targetAsset
= join(target
, entry
.name
);
32 internals
.debuglog(`Copying ${sourceAsset} to ${targetAsset}`);
34 if (entry
.isDirectory()) {
35 await
cp(sourceAsset
, targetAsset
, { recursive: true });
37 await
cp(sourceAsset
, targetAsset
);
42 if (error
.code
=== kFileNotFoundError
) {
43 internals
.debuglog(`No static directory found in ${source}`);