]>
git.r.bdr.sh - rbdr/blog/blob - lib/generators/static.js
45f5a04ed1c1a763bc8e6b128ac5c6a80984934a
1 import { access
, cp
, readdir
} from 'fs/promises';
2 import { constants
} from 'fs';
3 import { join
} from 'path';
4 import { debuglog
} from 'util';
5 import { kFileNotFoundError
} from '../constants.js';
8 debuglog: debuglog('blog'),
9 kAssetsDirectoryName: 'assets'
13 * Generates the static assets required for the blog
15 * @name StaticGenerator
16 * @param {string} source the source directory
17 * @param {string} target the target directory
18 * @param {Array.<Blog.tPost>} posts the list of posts
20 export default async
function StaticGenerator(source
, target
, _
) {
23 await
access(source
, constants
.R_OK
);
25 const entries
= await
readdir(source
, { withFileTypes: true });
26 for (const entry
of entries
) {
27 const sourceAsset
= join(source
, entry
.name
);
28 const targetAsset
= join(target
, entry
.name
);
30 internals
.debuglog(`Copying ${sourceAsset} to ${targetAsset}`);
32 if (entry
.isDirectory()) {
33 await
cp(sourceAsset
, targetAsset
, { recursive: true });
36 await
cp(sourceAsset
, targetAsset
);
41 if (error
.code
=== kFileNotFoundError
) {
42 internals
.debuglog(`No static directory found in ${source}`);