-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdocs.js
27 lines (23 loc) · 852 Bytes
/
docs.js
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
const { readdir, mkdir, copyFile, readFile, writeFile } = require('fs').promises;
const { join } = require('path');
const copyDirectory = async (src, dest) => {
const [entries] = await Promise.all([
readdir(src, { withFileTypes: true }),
mkdir(dest, { recursive: true }),
]);
await Promise.all(
entries.map((entry) => {
const srcPath = join(src, entry.name);
const destPath = join(dest, entry.name);
return entry.isDirectory()
? copyDirectory(srcPath, destPath)
: copyFile(srcPath, destPath);
}),
);
};
(async () => {
copyDirectory('./dist/js', './docs/assets/js');
copyDirectory('./dist/css', './docs/assets/css');
const scriptSource = await readFile('./docs/script.js', 'utf8');
await writeFile('./docs/script.js', scriptSource.replace(/\.\.\/dist\//g, 'assets/'), 'utf8');
})();