Skip to content

Commit

Permalink
Merge pull request #34 from AthennaIO/develop
Browse files Browse the repository at this point in the history
feat(commands): create template:customize command
  • Loading branch information
jlenon7 authored Jul 8, 2022
2 parents 3df80e3 + 148bbde commit edb92f9
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@athenna/artisan",
"version": "1.3.3",
"version": "1.3.4",
"description": "The Athenna CLI application. Built on top of commander.",
"license": "MIT",
"author": "João Lenon <[email protected]>",
Expand Down
81 changes: 81 additions & 0 deletions src/Commands/Template/Customize.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/**
* @athenna/artisan
*
* (c) João Lenon <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

import { Command } from '#src/index'
import { Path, Module, Folder } from '@secjs/utils'
import { join } from 'node:path'

export class TemplateCustomize extends Command {
/**
* The name and signature of the console command.
*
* @return {string}
*/
get signature() {
return 'template:customize'
}

/**
* The console command description.
*
* @return {string}
*/
get description() {
return 'Creates a folder called templates in your project root with all templates of Athenna.'
}

/**
* Set additional flags in the commander instance.
* This method is executed when registering your command.
*
* @param {import('commander').Command} commander
* @return {import('commander').Command}
*/
addFlags(commander) {
return commander
}

/**
* Execute the console command.
*
* @return {Promise<void>}
*/
async handle() {
this.simpleLog(`[ MOVING TEMPLATES ]`, 'rmNewLineStart', 'bold', 'green')

const path = Path.pwd('templates')

await new Folder(path).load()

const Kernel = await Module.getFrom(Path.console('Kernel.js'))

const kernel = new Kernel()

const templates = [
...new Folder(
join(
Module.createDirname(import.meta.url),
'..',
'..',
'..',
'templates',
),
).loadSync().files,
kernel.templates,
]

const promises = templates.map(template =>
template.copy(Path.pwd('templates')),
)

await Promise.all(promises)

this.success('Template files successfully moved.')
}
}

0 comments on commit edb92f9

Please sign in to comment.