-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcopy-assets.ts
More file actions
43 lines (37 loc) · 1.39 KB
/
copy-assets.ts
File metadata and controls
43 lines (37 loc) · 1.39 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
39
40
41
42
43
import fs from "fs/promises";
import path from "path";
import { fileURLToPath } from "url";
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const staticSrcPath = path.join(__dirname, ".next/static");
const staticDestPath = path.join(__dirname, ".next/standalone/.next/static");
const publicSrcPath = path.join(__dirname, "public");
const publicDestPath = path.join(__dirname, ".next/standalone/public");
function copyAssets(src: string, dest: string): Promise<unknown> {
return fs
.mkdir(dest, { recursive: true })
.then(() => fs.readdir(src, { withFileTypes: true }))
.then((items) => {
const promises = items.map((item) => {
const srcPath = path.join(src, item.name);
const destPath = path.join(dest, item.name);
if (item.isDirectory()) {
return copyAssets(srcPath, destPath);
} else {
return fs.copyFile(srcPath, destPath);
}
});
return Promise.all(promises);
})
.catch((err) => {
console.error(`Error: ${err}`);
throw err;
});
}
const greenTick = `\x1b[32m\u2713\x1b[0m`;
const redCross = `\x1b[31m\u274C\x1b[0m`;
copyAssets(staticSrcPath, staticDestPath)
.then(() => copyAssets(publicSrcPath, publicDestPath))
.then(() => console.log(`${greenTick} Assets copied successfully`))
.catch((error: Error) =>
console.error(`${redCross} Failed to copy assets: ${error}`)
);