Skip to content

Commit

Permalink
feat: add CLI project type to New command
Browse files Browse the repository at this point in the history
  • Loading branch information
jlenon7 committed Apr 20, 2022
1 parent a45ed40 commit 1ed7e50
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>",
Expand Down
4 changes: 2 additions & 2 deletions src/Cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
}
Expand All @@ -44,7 +44,7 @@ export class Cli {
this.program
.command('new')
.argument('<name>', 'Your project name')
.option('-t, --type <type>', 'Current types available: http', 'http')
.option('-t, --type <type>', 'Current types available: http, cli', 'http')
.description('Scaffold a new Athenna project')
.action(newCommand.project.bind(newCommand))
.showHelpAfterError()
Expand Down
52 changes: 52 additions & 0 deletions src/Commands/New.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()}`)
}
}

0 comments on commit 1ed7e50

Please sign in to comment.