-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathesbuild.config.js
49 lines (41 loc) · 1.41 KB
/
esbuild.config.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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import fs from "fs";
import path from "path";
import { build } from "esbuild";
import { fileURLToPath } from "url";
import { nodeExternalsPlugin } from "esbuild-node-externals";
// Function to copy the templates folder recursively
function copyFiles(src, dest) {
const entries = fs.readdirSync(src, { withFileTypes: true });
fs.mkdirSync(dest, { recursive: true });
for (let entry of entries) {
const srcPath = path.join(src, entry.name);
const destPath = path.join(dest, entry.name);
entry.isDirectory()
? copyFiles(srcPath, destPath)
: fs.copyFileSync(srcPath, destPath);
}
}
// Get the directory name in ES modules
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const templateSource = path.resolve(__dirname, "./src/templates/project");
const templateDest = path.resolve(__dirname, "dist", "templates", "project");
const scriptSource = path.resolve(__dirname, "./src/scripts");
const scriptDist = path.resolve(__dirname, "dist", "scripts");
build({
entryPoints: ["./index.ts"],
bundle: true,
outfile: "dist/index.js",
platform: "node",
format: "esm",
plugins: [nodeExternalsPlugin()],
})
.then(() => {
copyFiles(templateSource, templateDest);
copyFiles(scriptSource, scriptDist);
console.log("Templates and Scripts copied successfully.");
})
.catch((error) => {
console.error("Error: ", error);
process.exit(1);
});