#!/usr/bin/env node

import fs from 'fs-extra';
import path from 'path';
import { fileURLToPath } from 'url';

const __dirname = path.dirname(fileURLToPath(import.meta.url));
const templateDir = path.join(__dirname, 'template');

let projectName = process.argv[2];

if (!projectName) {
  projectName = 'my-stock-system';
}

console.log(`🚀 Creating Cactus Stock Management System...`);
console.log(`📁 Project: ${projectName}\n`);

const targetDir = path.join(process.cwd(), projectName);

if (fs.existsSync(targetDir)) {
  console.error(`❌ Error: Folder "${projectName}" already exists!`);
  process.exit(1);
}

fs.copySync(templateDir, targetDir);

console.log(`✅ Success! Project created successfully.\n`);
console.log(`📌 Next: cd ${projectName}`);
console.log(`Then install dependencies in both backend-project and frontend-project.`);
console.log(`🎉 Happy Coding with Cactus!`);