other
This commit is contained in:
75
setup-backend.js
Normal file
75
setup-backend.js
Normal file
@@ -0,0 +1,75 @@
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import { fileURLToPath } from 'url';
|
||||
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = path.dirname(__filename);
|
||||
|
||||
const backendPath = path.join(__dirname, '..', 'ember-market-backend');
|
||||
const targetPath = path.join(__dirname, 'backend');
|
||||
|
||||
// Create backend directory if it doesn't exist
|
||||
if (!fs.existsSync(targetPath)) {
|
||||
fs.mkdirSync(targetPath, { recursive: true });
|
||||
}
|
||||
|
||||
// Function to copy directory recursively
|
||||
function copyDir(src, dest) {
|
||||
// Create destination directory if it doesn't exist
|
||||
if (!fs.existsSync(dest)) {
|
||||
fs.mkdirSync(dest, { recursive: true });
|
||||
}
|
||||
|
||||
// Read contents of source directory
|
||||
const entries = fs.readdirSync(src, { withFileTypes: true });
|
||||
|
||||
for (const entry of entries) {
|
||||
const srcPath = path.join(src, entry.name);
|
||||
const destPath = path.join(dest, entry.name);
|
||||
|
||||
// Skip node_modules and .git directories
|
||||
if (entry.name === 'node_modules' || entry.name === '.git') {
|
||||
console.log(`Skipping ${entry.name}`);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (entry.isDirectory()) {
|
||||
// Recursive call for directories
|
||||
copyDir(srcPath, destPath);
|
||||
} else {
|
||||
// Copy file
|
||||
fs.copyFileSync(srcPath, destPath);
|
||||
console.log(`Copied: ${srcPath} -> ${destPath}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Copy files from backend to frontend/backend
|
||||
try {
|
||||
// Copy main backend directories
|
||||
const dirsToSync = ['config', 'controllers', 'middleware', 'models', 'routes', 'scripts', 'utils'];
|
||||
|
||||
dirsToSync.forEach(dir => {
|
||||
const sourcePath = path.join(backendPath, dir);
|
||||
const destPath = path.join(targetPath, dir);
|
||||
|
||||
if (fs.existsSync(sourcePath)) {
|
||||
copyDir(sourcePath, destPath);
|
||||
} else {
|
||||
console.warn(`Warning: Directory ${sourcePath} does not exist`);
|
||||
}
|
||||
});
|
||||
|
||||
// Copy .env file (you might want to modify this for different environments)
|
||||
const envSource = path.join(backendPath, '.env');
|
||||
const envDest = path.join(__dirname, '.env.backend');
|
||||
|
||||
if (fs.existsSync(envSource)) {
|
||||
fs.copyFileSync(envSource, envDest);
|
||||
console.log(`Copied: ${envSource} -> ${envDest}`);
|
||||
}
|
||||
|
||||
console.log('Backend setup completed successfully!');
|
||||
} catch (error) {
|
||||
console.error('Error setting up backend:', error);
|
||||
}
|
||||
Reference in New Issue
Block a user