63 lines
1.4 KiB
JavaScript
63 lines
1.4 KiB
JavaScript
"use strict";
|
|
|
|
const fs = require("fs");
|
|
const path = require("path");
|
|
|
|
const rootDir = __dirname;
|
|
const distDir = path.join(rootDir, "dist");
|
|
|
|
const directoriesToCopy = [
|
|
"config",
|
|
"constants",
|
|
"controllers",
|
|
"db",
|
|
"middleware",
|
|
"models",
|
|
"routes",
|
|
"services",
|
|
"utils",
|
|
"public",
|
|
];
|
|
|
|
const filesToCopy = ["app.js", "server.js", "package.json", "package-lock.json"];
|
|
|
|
function copyFile(sourcePath, targetPath) {
|
|
fs.mkdirSync(path.dirname(targetPath), { recursive: true });
|
|
fs.copyFileSync(sourcePath, targetPath);
|
|
}
|
|
|
|
function copyDirectory(sourceDir, targetDir) {
|
|
if (!fs.existsSync(sourceDir)) {
|
|
return;
|
|
}
|
|
|
|
for (const entry of fs.readdirSync(sourceDir, { withFileTypes: true })) {
|
|
const sourcePath = path.join(sourceDir, entry.name);
|
|
const targetPath = path.join(targetDir, entry.name);
|
|
|
|
if (entry.isDirectory()) {
|
|
copyDirectory(sourcePath, targetPath);
|
|
continue;
|
|
}
|
|
|
|
if (entry.isFile()) {
|
|
copyFile(sourcePath, targetPath);
|
|
}
|
|
}
|
|
}
|
|
|
|
fs.mkdirSync(distDir, { recursive: true });
|
|
|
|
for (const directory of directoriesToCopy) {
|
|
copyDirectory(path.join(rootDir, directory), path.join(distDir, directory));
|
|
}
|
|
|
|
for (const file of filesToCopy) {
|
|
const sourcePath = path.join(rootDir, file);
|
|
if (fs.existsSync(sourcePath)) {
|
|
copyFile(sourcePath, path.join(distDir, file));
|
|
}
|
|
}
|
|
|
|
console.log(`Backend build copied runtime files to ${path.relative(rootDir, distDir)}`);
|