From 148bbde47b8c69b52cde868d9fb1fa25c084bbe5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Lenon?= Date: Thu, 7 Jul 2022 21:47:09 -0300 Subject: [PATCH] feat(commands): create template:customize command --- package.json | 2 +- src/Commands/Template/Customize.js | 81 ++++++++++++++++++++++++++++++ 2 files changed, 82 insertions(+), 1 deletion(-) create mode 100644 src/Commands/Template/Customize.js diff --git a/package.json b/package.json index c029a09..551ca9d 100644 --- a/package.json +++ b/package.json @@ -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 ", diff --git a/src/Commands/Template/Customize.js b/src/Commands/Template/Customize.js new file mode 100644 index 0000000..fd874d9 --- /dev/null +++ b/src/Commands/Template/Customize.js @@ -0,0 +1,81 @@ +/** + * @athenna/artisan + * + * (c) João Lenon + * + * 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} + */ + 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.') + } +}