Skip to content

Commit

Permalink
Merge pull request #43 from AthennaIO/develop
Browse files Browse the repository at this point in the history
refactor(templates): get the template by resource
  • Loading branch information
jlenon7 authored Sep 2, 2022
2 parents 10f0e88 + b3c1cf0 commit 97f6db7
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 11 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/artisan",
"version": "1.3.7",
"version": "1.3.8",
"description": "The Athenna CLI application. Built on top of commander.",
"license": "MIT",
"author": "João Lenon <[email protected]>",
Expand Down
12 changes: 5 additions & 7 deletions src/Helpers/TemplateHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,15 +205,13 @@ export class TemplateHelper {
}

/**
* Get the template file by name or undefined.
* Get the template file by resource.
*
* @param {string} templateName
* @param {string} resource
* @return {File}
*/
static getTemplate(templateName) {
templateName = `${templateName}.js.ejs`

const predicate = file => file.base === templateName
static getTemplateByResource(resource) {
const predicate = file => file.base.includes(resource)

return (
this.#customTemplates.find(file => predicate(file)) ||
Expand Down Expand Up @@ -503,7 +501,7 @@ export class TemplateHelper {
*/
static async getResourceFile(name, resource, subPath) {
name = TemplateHelper.normalizeName(name, resource)
const template = TemplateHelper.getTemplate(`__name__${resource}`)
const template = TemplateHelper.getTemplateByResource(resource)

const replacedName = TemplateHelper.replaceTemplateName(name, template.base)
const path = subPath.concat('/', replacedName)
Expand Down
6 changes: 3 additions & 3 deletions src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,12 +254,12 @@ export class TemplateHelper {
static normalizeName(name: string, resource: string): string

/**
* Get the template file by name or undefined.
* Get the template file by resource.
*
* @param {string} templateName
* @param {string} resource
* @return {File}
*/
static getTemplate(templateName: string): File
static getTemplateByResource(resource: string): File

/**
* Replace the name of the template file with values.
Expand Down

0 comments on commit 97f6db7

Please sign in to comment.