forked from nodejs/doc-kit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcopying.mjs
More file actions
38 lines (34 loc) · 1.09 KB
/
Copy pathcopying.mjs
File metadata and controls
38 lines (34 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import { cp } from 'node:fs/promises';
import { join, basename } from 'node:path';
import logger from '../../../logger/index.mjs';
/**
* Copies static directories/files defined in `pathsToCopy` to the output directory.
* @param {import('../types').Configuration} config
*/
export async function copyStaticAssets(config) {
if (Array.isArray(config.pathsToCopy)) {
for (const item of config.pathsToCopy) {
if (!item) {
continue;
}
const copyTasks =
typeof item === 'string'
? [{ src: item, dest: join(config.output, basename(item)) }]
: Object.entries(item).map(([src, dest]) => ({
src,
dest: join(config.output, dest.replace(/^[/\\]+/, '')),
}));
for (const { src, dest } of copyTasks) {
try {
await cp(src, dest, { recursive: true, force: true });
} catch (err) {
if (err.code !== 'ENOENT') {
logger.error(
`[web-generator] Failed to copy asset from ${src} to ${dest}: ${err.message}`
);
}
}
}
}
}
}