Skip to content

Commit

Permalink
feat(project): add slim type of project
Browse files Browse the repository at this point in the history
  • Loading branch information
jlenon7 committed Jul 9, 2022
1 parent 880a8dd commit b8d263c
Show file tree
Hide file tree
Showing 3 changed files with 66 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.8",
"version": "1.0.9",
"description": "Athenna CLI to create new projects and install components.",
"license": "MIT",
"author": "João Lenon <[email protected]>",
Expand Down
65 changes: 64 additions & 1 deletion src/Commands/New.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,70 @@ export class New {
table.push(
[' Run following commands to get started'],
[
` ${arrow} cd ${projectName}\n ${arrow} npm run test\n ${arrow} npm run start\n ${arrow} npm run start:dev -- --help`,
` ${arrow} cd ${projectName}\n ${arrow} npm run test\n ${arrow} npm run start\n -- --help`,
],
)

console.log(`\n${table.toString()}`)
}

/**
* The new:project -t slim command handler.
*
* @param {string} projectName
* @return {Promise<void>}
*/
async slim(projectName) {
console.log(chalk.bold.green('[ GENERATING SLIM ]\n'))

const projectPath = Path.storage(`project/${projectName}`)
const concretePath = `${this.#callPath}${sep}${projectName}`

if (await Folder.exists(concretePath)) {
this.#logger.error(
`The directory ({yellow} "${projectName}") already exists. Try another project name.`,
)

return
}

const cdCommand = `cd ${projectPath}`
const cloneCommand = `git clone --branch slim ${
this.#repositoryUrl
} ${projectPath}`
const runNpmInstallCommand = `${cdCommand} && npm install --silent`
const rmGitAndCopyEnv = `${cdCommand} && rm -rf .git && rm -rf .github && cp .env.example .env`
const moveProjectCommand = `mv ${projectPath} ${concretePath}`

await CliHelper.runCommand(
cloneCommand,
`Cloning scaffold project from ${this.#repositoryUrl} in branch cli`,
)

await CliHelper.runCommand(
rmGitAndCopyEnv,
'Removing defaults and creating .env file from .env.example',
)

await CliHelper.runCommand(runNpmInstallCommand, 'Installing dependencies')
await CliHelper.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 start\n -- --help`,
],
)

Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export class Cli {
.argument('<name>', 'Your project name.')
.option(
'-t, --type <type>',
'Current types available: http, cli.',
'Current types available: http, cli and slim.',
'http',
)
.action(newCommand.project.bind(newCommand))
Expand Down

0 comments on commit b8d263c

Please sign in to comment.