diff --git a/celtix-cli/bin/index.js b/celtix-cli/bin/index.js new file mode 100644 index 0000000..05b791b --- /dev/null +++ b/celtix-cli/bin/index.js @@ -0,0 +1,18 @@ +#!/usr/bin/env node + +const { program } = require('commander'); +const createCommand = require('../commands/create'); + +// Define the main program +program + .version('1.0.0') + .description('A CLI tool for creating project structures'); + +// Define the 'create' command +program + .command('create ') + .description('Create a new project from a template') + .action(createCommand); + +// Parse the arguments from the command line +program.parse(process.argv); diff --git a/celtix-cli/commands/create.js b/celtix-cli/commands/create.js new file mode 100644 index 0000000..5d51194 --- /dev/null +++ b/celtix-cli/commands/create.js @@ -0,0 +1,51 @@ +const fs = require('fs-extra'); +const path = require('path'); +const chalk = require('chalk'); +const inquirer = require('inquirer'); + +async function createProject(projectName) { + const targetDir = path.join(process.cwd(), projectName); + + // Check if the directory already exists + if (fs.existsSync(targetDir)) { + const { overwrite } = await inquirer.prompt([ + { + type: 'confirm', + name: 'overwrite', + message: chalk.yellow(`Directory "${projectName}" already exists. Overwrite?`), + default: false, + }, + ]); + + if (!overwrite) { + console.log(chalk.red('Operation cancelled.')); + return; + } + console.log(chalk.yellow(`Overwriting directory: ${targetDir}...`)); + await fs.remove(targetDir); + } + + // Create the project directory + await fs.mkdir(targetDir); + + // Define the source of the template + const templateDir = path.join(__dirname, '..', 'templates', 'default-backend'); + + try { + // Copy the template files to the new project directory + await fs.copy(templateDir, targetDir); + + console.log(chalk.green('\n✅ Project created successfully!')); + console.log(chalk.cyan('Next steps:')); + console.log(chalk.gray(` 1. cd ${projectName}`)); + console.log(chalk.gray(' 2. npm install')); + console.log(chalk.gray(' 3. cp .env.example .env (and edit it)')); + console.log(chalk.gray(' 4. npm start\n')); + } catch (error) { + console.error(chalk.red('Error creating project:', error)); + // Clean up created directory on failure + await fs.remove(targetDir); + } +} + +module.exports = createProject; diff --git a/celtix-cli/commands/templates/ default-backend/.env.example b/celtix-cli/commands/templates/ default-backend/.env.example new file mode 100644 index 0000000..79792d3 --- /dev/null +++ b/celtix-cli/commands/templates/ default-backend/.env.example @@ -0,0 +1,2 @@ +PORT=8080 +MESSAGE="Hello from Celtrix!" diff --git a/celtix-cli/commands/templates/ default-backend/package.json b/celtix-cli/commands/templates/ default-backend/package.json new file mode 100644 index 0000000..aaf0e6d --- /dev/null +++ b/celtix-cli/commands/templates/ default-backend/package.json @@ -0,0 +1,13 @@ +{ + "name": "new-celtrix-app", + "version": "1.0.0", + "description": "A backend project generated by Celtrix CLI.", + "main": "src/index.js", + "scripts": { + "start": "node src/index.js" + }, + "dependencies": { + "express": "^4.19.2", + "dotenv": "^16.4.5" + } +} diff --git a/celtix-cli/commands/templates/ default-backend/src/index,js b/celtix-cli/commands/templates/ default-backend/src/index,js new file mode 100644 index 0000000..3221208 --- /dev/null +++ b/celtix-cli/commands/templates/ default-backend/src/index,js @@ -0,0 +1,13 @@ +require('dotenv').config(); +const express = require('express'); + +const app = express(); +const PORT = process.env.PORT || 3000; + +app.get('/', (req, res) => { + res.send(process.env.MESSAGE || 'Hello, World!'); +}); + +app.listen(PORT, () => { + console.log(`Server is running on http://localhost:${PORT}`); +}); diff --git a/celtix-cli/package.json b/celtix-cli/package.json new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/celtix-cli/package.json @@ -0,0 +1 @@ + diff --git a/index.js b/index.js index e04659a..4534c6c 100644 --- a/index.js +++ b/index.js @@ -1,3 +1,4 @@ +//raunak import inquirer from "inquirer"; import chalk from "chalk"; import gradient from "gradient-string"; diff --git a/package.json b/package.json index 9c73600..482ad24 100644 --- a/package.json +++ b/package.json @@ -1,62 +1,25 @@ -{ - "name": "celtrix", - "version": "2.0.4", - "description": "CLI to create MERN apps quickly", - "type": "module", - "main": "./bin/celtrix.js", + + { + "name": "celtrix-cli", + "version": "1.0.0", + "description": "A CLI tool to scaffold new projects.", + "main": "index.js", "bin": { - "celtrix": "./bin/celtrix.js" + "celtrix": "bin/index.js" + }, + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" }, - "files": [ - "bin/", - "index.js", - "commands/", - "utils/", - "templates/" - ], "keywords": [ - "mern", "cli", - "react", - "express", - "mongodb", - "fullstack" + "scaffolding" ], - "author": "Joe Celaster", - "license": "ISC", + "author": "Your Name", + "license": "MIT", "dependencies": { - "@octokit/rest": "^22.0.0", - "@pinecone-database/pinecone": "^6.1.2", - "boxen": "^8.0.1", - "chalk": "^5.6.0", - "dotenv": "^17.2.3", - "express": "^5.1.0", - "figlet": "^1.8.2", - "fs-extra": "^11.3.1", - "gradient-string": "^3.0.0", - "inquirer": "^12.9.4", - "log-symbols": "^7.0.1", - "node-fetch": "^3.3.2", - "ora": "^8.2.0" - }, - "scripts": { - "release:patch": "npm version patch && npm publish --access public", - "release:minor": "npm version minor && npm publish --access public", - "release:major": "npm version major && npm publish --access public", - "validate": "node scripts/validate-apis.js", - "validate:pinecone": "node scripts/validate-apis.js pinecone", - "validate:github": "node scripts/validate-apis.js github", - "validate:gemini": "node scripts/validate-apis.js gemini", - "populate-issues": "node scripts/populate-existing-issues.js", - "cleanup-issue": "node scripts/cleanup-closed-issue.js", - "cleanup-specific": "node scripts/cleanup-specific-issue.js", - "cleanup-duplicates": "node scripts/cleanup-duplicates.js --force", - "debug-db": "node scripts/debug-pinecone.js", - "clear-all": "echo '⚠️ Use: npm run clear-all:force' && exit 1", - "clear-all:force": "node scripts/clear-all-vectors.js --force", - "check-duplicates": "node scripts/check-duplicates.js" - }, - "devDependencies": { - "typescript": "^5.9.3" + "chalk": "^4.1.2", + "commander": "^12.1.0", + "fs-extra": "^11.2.0", + "inquirer": "^8.2.4" } }