From 1ed7e50f940fed8b0e77758a1931430b70519395 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Lenon?= Date: Wed, 20 Apr 2022 14:44:41 -0300 Subject: [PATCH] feat: add CLI project type to New command --- package.json | 2 +- src/Cli.ts | 4 ++-- src/Commands/New.ts | 52 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 55 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index ec74bff..ef24116 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@athenna/cli", - "version": "1.0.2", + "version": "1.0.3", "description": "Athenna CLI to create new projects and install components.", "license": "MIT", "author": "Victor Tesoura Júnior ", diff --git a/src/Cli.ts b/src/Cli.ts index bd0804d..44b99f5 100644 --- a/src/Cli.ts +++ b/src/Cli.ts @@ -31,7 +31,7 @@ export class Cli { */ process.chdir(resolve(__dirname, '..')) - console.log(chalkRainbow(figlet.textSync('Athenna'))) + process.stdout.write(chalkRainbow(figlet.textSync('Athenna')) + '\n' + '\n') this.program.version(`v${version}`, '-v, --version') } @@ -44,7 +44,7 @@ export class Cli { this.program .command('new') .argument('', 'Your project name') - .option('-t, --type ', 'Current types available: http', 'http') + .option('-t, --type ', 'Current types available: http, cli', 'http') .description('Scaffold a new Athenna project') .action(newCommand.project.bind(newCommand)) .showHelpAfterError() diff --git a/src/Commands/New.ts b/src/Commands/New.ts index a1a63f7..d8e244c 100644 --- a/src/Commands/New.ts +++ b/src/Commands/New.ts @@ -95,4 +95,56 @@ export class New { console.log(`\n${table.toString()}`) } + + async cli(projectName: string) { + console.log(chalk.bold.green('[ GENERATING CLI ]\n')) + + const projectPath = Path.storage(`project/${projectName}`) + const concretePath = `${this.clientFolder}${sep}${projectName}` + + if (existsSync(concretePath)) { + this.logger.error( + `The directory ({yellow} "${projectName}") already exists. Try another project name.`, + ) + + return + } + + const cdCommand = `cd ${projectPath}` + const cloneCommand = `git clone --branch cli ${this.repositoryUrl} ${projectPath}` + const runNpmInstallCommand = `${cdCommand} && npm install --silent` + const rmGitAndCopyEnv = `${cdCommand} && rm -rf .git && rm -rf .github && cp .env.example .env && cp .env.example .env.test` + const moveProjectCommand = `mv ${projectPath} ${concretePath}` + + await runCommand( + cloneCommand, + `Cloning scaffold project from ${this.repositoryUrl} in branch cli`, + ) + + await runCommand( + rmGitAndCopyEnv, + 'Removing defaults and creating .env/.env.test files from .env.example', + ) + + await runCommand(runNpmInstallCommand, 'Installing dependencies') + await runCommand(moveProjectCommand, 'Moving project to your path') + + console.log('\n') + this.logger.success( + `Project created at ({yellow} "${projectName}") folder.`, + ) + + const table = new Table() + + const arrow = chalk.bold.green('❯') + + table.push( + [' Run following commands to get started'], + [ + ` ${arrow} cd ${projectName}\n ${arrow} npm run test\n ${arrow} npm run artisan\n ${arrow} npm run artisan:dev -- --help`, + ], + ) + + console.log(`\n${table.toString()}`) + } }