@bodheesh/create-bodhi-node-app
Version:
Create a production-ready Node.js REST API with zero configuration
49 lines (39 loc) ⢠1.58 kB
JavaScript
const fs = require('fs-extra');
const path = require('path');
const chalk = require('chalk');
async function createProject(projectName, projectPath, options) {
const { template, database } = options;
try {
// Copy template files
const templatePath = path.join(__dirname, '..', 'templates', template);
if (!fs.existsSync(templatePath)) {
throw new Error(`Template ${template} not found`);
}
console.log(chalk.blue('\nš Creating your project...'));
await fs.copy(templatePath, projectPath);
// Create necessary directories if they don't exist
const dirs = ['src', 'src/controllers', 'src/models', 'src/routes', 'src/middleware', 'src/utils'];
for (const dir of dirs) {
await fs.ensureDir(path.join(projectPath, dir));
}
// Update package.json
const packageJsonPath = path.join(projectPath, 'package.json');
const packageJson = await fs.readJson(packageJsonPath);
packageJson.name = projectName;
await fs.writeJson(packageJsonPath, packageJson, { spaces: 2 });
// Create .env file from .env.example
const envExamplePath = path.join(projectPath, '.env.example');
const envPath = path.join(projectPath, '.env');
if (fs.existsSync(envExamplePath)) {
await fs.copy(envExamplePath, envPath);
}
console.log(chalk.green('\nā
Project structure created'));
console.log(chalk.blue('\nš¦ Installing dependencies...'));
} catch (error) {
console.error(chalk.red('\nā Error creating project:'), error);
throw error;
}
}
module.exports = {
createProject
};