UNPKG

create-avo-tools

Version:

A CLI for creating projects with your chosen tech stack and language

263 lines (241 loc) 11.4 kB
import path from 'path'; import fs from 'fs-extra'; import { execSync } from 'child_process'; export const createProject = async (language, techStack, projectName, targetDirectory) => { const targetPath = path.join(targetDirectory, projectName); try { if (language === 'JavaScript' || language === 'TypeScript') { if (techStack === 'React') { console.log(`Creating your React project in ${language}...`); execSync(`npx create-react-app ${targetPath} ${language === 'TypeScript' ? '--template typescript' : ''}`, { stdio: 'inherit' }); console.log('✅ React project created successfully!'); } else if (techStack === 'Vue') { console.log(`Creating your Vue project in ${language}...`); execSync(`npm init vue@latest ${targetPath} ${language === 'TypeScript' ? '-- --default --typescript' : ''}`, { stdio: 'inherit' }); console.log('✅ Vue project created successfully!'); } else if (techStack === 'Angular') { console.log(`Creating your Angular project in ${language}...`); execSync(`npx @angular/cli new ${targetPath} ${language === 'TypeScript' ? '' : '--skip-tests'} --defaults`, { stdio: 'inherit' }); console.log('✅ Angular project created successfully!'); } else if (techStack === 'Svelte') { console.log(`Creating your Svelte project in ${language}...`); execSync(`npx degit sveltejs/template ${targetPath}`, { stdio: 'inherit' }); if (language === 'TypeScript') { console.log('📦 Adding TypeScript support...'); execSync(`cd ${targetPath} && node scripts/setupTypeScript.js`, { stdio: 'inherit' }); } console.log('📦 Installing dependencies...'); execSync(`cd ${targetPath} && npm install`, { stdio: 'inherit' }); console.log('✅ Svelte project created successfully!'); } } else if (language === 'Python') { if (techStack === 'Flask') { console.log(`Creating your Flask project...`); execSync(`mkdir ${targetPath} && cd ${targetPath} && python3 -m venv venv && source venv/bin/activate && pip install Flask`, { stdio: 'inherit' }); fs.writeFileSync(path.join(targetPath, 'app.py'), ` from flask import Flask app = Flask(__name__) @app.route('/') def hello_world(): return 'Hello, World!' if __name__ == '__main__': app.run(debug=True) `); console.log('✅ Flask project created successfully!'); } else if (techStack === 'Django') { console.log(`Creating your Django project...`); execSync(`pip show django || pip install django`, { stdio: 'inherit' }); execSync(`django-admin startproject ${projectName} ${targetDirectory}`, { stdio: 'inherit' }); console.log('✅ Django project created successfully!'); } else if (techStack === 'FastAPI') { console.log(`Creating your FastAPI project...`); execSync(`mkdir ${targetPath} && cd ${targetPath} && python3 -m venv venv && source venv/bin/activate && pip install fastapi uvicorn`, { stdio: 'inherit' }); fs.writeFileSync(path.join(targetPath, 'main.py'), ` from fastapi import FastAPI app = FastAPI() @app.get("/") def read_root(): return {"Hello": "World"} if __name__ == "__main__": import uvicorn uvicorn.run(app, host="0.0.0.0", port=8000) `); console.log('✅ FastAPI project created successfully!'); } else if (techStack === 'Pyramid') { console.log(`Creating your Pyramid project...`); execSync(`mkdir ${targetPath} && cd ${targetPath} && python3 -m venv venv && source venv/bin/activate && pip install pyramid`, { stdio: 'inherit' }); fs.writeFileSync(path.join(targetPath, 'app.py'), ` from wsgiref.simple_server import make_server from pyramid.config import Configurator from pyramid.response import Response def hello_world(request): return Response('Hello, World!') if __name__ == '__main__': with Configurator() as config: config.add_route('hello', '/') config.add_view(hello_world, route_name='hello') app = config.make_wsgi_app() server = make_server('0.0.0.0', 6543, app) server.serve_forever() `); console.log('✅ Pyramid project created successfully!'); } else if (techStack === 'Tornado') { console.log(`Creating your Tornado project...`); execSync(`mkdir ${targetPath} && cd ${targetPath} && python3 -m venv venv && source venv/bin/activate && pip install tornado`, { stdio: 'inherit' }); fs.writeFileSync(path.join(targetPath, 'app.py'), ` import tornado.ioloop import tornado.web class MainHandler(tornado.web.RequestHandler): def get(self): self.write("Hello, World!") def make_app(): return tornado.web.Application([ (r"/", MainHandler), ]) if __name__ == "__main__": app = make_app() app.listen(8888) tornado.ioloop.IOLoop.current().start() `); console.log('✅ Tornado project created successfully!'); } } else if (language === 'Ruby') { if (techStack === 'Rails') { console.log(`Creating your Rails project...`); try { execSync(`gem list -i rails`, { stdio: 'inherit' }); } catch (err) { console.log('Rails is not installed. Installing Rails...'); try { // Check if rbenv is installed try { execSync(`rbenv --version`, { stdio: 'inherit' }); } catch (rbenvErr) { console.log('rbenv is not installed. Installing rbenv...'); execSync(`brew install rbenv`, { stdio: 'inherit' }); execSync(`brew install ruby-build`, { stdio: 'inherit' }); } // Initialize rbenv const rbenvInit = execSync(`rbenv init -`, { stdio: 'pipe' }).toString(); const rbenvPath = execSync(`rbenv root`).toString().trim(); process.env.PATH = `${rbenvPath}/shims:${rbenvPath}/bin:${process.env.PATH}`; execSync(rbenvInit, { stdio: 'inherit', shell: '/bin/bash' }); // Install Ruby 3.1.0 using rbenv execSync(`rbenv install 3.1.0`, { stdio: 'inherit' }); execSync(`rbenv global 3.1.0`, { stdio: 'inherit' }); // Install Rails execSync(`gem install rails --user-install`, { stdio: 'inherit' }); const gemPath = execSync(`ruby -e 'puts Gem.user_dir'`).toString().trim(); process.env.PATH += `:${gemPath}/bin`; } catch (installErr) { console.error('❌ Error installing Rails:', installErr.message); return; } } execSync(`rails new ${targetPath}`, { stdio: 'inherit' }); console.log('✅ Rails project created successfully!'); } else if (techStack === 'Sinatra') { console.log(`Creating your Sinatra project...`); execSync(`mkdir ${targetPath} && cd ${targetPath} && bundle init && bundle add sinatra`, { stdio: 'inherit' }); fs.writeFileSync(path.join(targetPath, 'app.rb'), ` require 'sinatra' get '/' do 'Hello, World!' end `); console.log('✅ Sinatra project created successfully!'); } } else if (language === 'Go') { if (techStack === 'Gin') { console.log(`Creating your Gin project...`); try { execSync(`go version`, { stdio: 'inherit' }); } catch (err) { console.log('Go is not installed. Installing Go...'); execSync(`brew install go`, { stdio: 'inherit' }); } execSync(`mkdir ${targetPath} && cd ${targetPath} && go mod init ${projectName} && go get -u github.com/gin-gonic/gin`, { stdio: 'inherit' }); fs.writeFileSync(path.join(targetPath, 'main.go'), ` package main import ( "github.com/gin-gonic/gin" ) func main() { r := gin.Default() r.GET("/", func(c *gin.Context) { c.JSON(200, gin.H{ "message": "Hello, World!", }) }) r.Run() } `); console.log('✅ Gin project created successfully!'); } else if (techStack === 'Echo') { console.log(`Creating your Echo project...`); try { execSync(`go version`, { stdio: 'inherit' }); } catch (err) { console.log('Go is not installed. Installing Go...'); execSync(`brew install go`, { stdio: 'inherit' }); } execSync(`mkdir ${targetPath} && cd ${targetPath} && go mod init ${projectName} && go get -u github.com/labstack/echo/v4`, { stdio: 'inherit' }); fs.writeFileSync(path.join(targetPath, 'main.go'), ` package main import ( "net/http" "github.com/labstack/echo/v4" ) func main() { e := echo.New() e.GET("/", func(c echo.Context) error { return c.String(http.StatusOK, "Hello, World!") }) e.Start(":8080") } `); console.log('✅ Echo project created successfully!'); } } else if (language === 'Java') { if (techStack === 'Spring Boot') { console.log(`Creating your Spring Boot project...`); execSync(`curl https://start.spring.io/starter.zip -d dependencies=web -d name=${projectName} -o ${targetPath}.zip`, { stdio: 'inherit' }); execSync(`unzip ${targetPath}.zip -d ${targetPath}`, { stdio: 'inherit' }); console.log('✅ Spring Boot project created successfully!'); } else if (techStack === 'Micronaut') { console.log(`Creating your Micronaut project...`); execSync(`mn create-app ${targetPath} --features=graalvm`, { stdio: 'inherit' }); console.log('✅ Micronaut project created successfully!'); } } else if (language === 'PHP') { if (techStack === 'Laravel') { console.log(`Creating your Laravel project...`); try { execSync(`composer --version`, { stdio: 'inherit' }); } catch (err) { console.log('Composer is not installed. Installing Composer...'); execSync(`php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"`, { stdio: 'inherit' }); execSync(`php composer-setup.php`, { stdio: 'inherit' }); execSync(`php -r "unlink('composer-setup.php');"`, { stdio: 'inherit' }); } execSync(`php composer.phar create-project --prefer-dist laravel/laravel ${targetPath}`, { stdio: 'inherit' }); console.log('✅ Laravel project created successfully!'); } else if (techStack === 'Symfony') { console.log(`Creating your Symfony project...`); try { execSync(`composer --version`, { stdio: 'inherit' }); } catch (err) { console.log('Composer is not installed. Installing Composer...'); execSync(`php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"`, { stdio: 'inherit' }); execSync(`php composer-setup.php`, { stdio: 'inherit' }); execSync(`php -r "unlink('composer-setup.php');"`, { stdio: 'inherit' }); } execSync(`php composer.phar create-project symfony/skeleton ${targetPath}`, { stdio: 'inherit' }); console.log('✅ Symfony project created successfully!'); } } console.log(`👉 Get started by navigating to the project directory:\n cd ${targetPath}\n npm install\n npm start`); } catch (err) { console.error(`❌ Error creating ${techStack} project:`, err.message); } };