Skip to content

Commit

Permalink
feat: remove type and unecessary file
Browse files Browse the repository at this point in the history
  • Loading branch information
ipetinate committed May 22, 2024
1 parent 05af645 commit 124d2fc
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 18 deletions.
1 change: 0 additions & 1 deletion .clingon/templates/ReactComponent/index.tsx

This file was deleted.

40 changes: 23 additions & 17 deletions src/generators/scaffold-template.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
import { checkDirectoriesTree, createDir } from '../utils/directory.js'

/**
* @typedef {Record<keyof Omit<import('../types').CustomTemplate, "folderWrapper" | "identifier">, string>} TemplatesContent
*
* @typedef {Record<keyof Omit<import('../types').CustomTemplate, "folderWrapper" | "identifier">, boolean>} TargetPaths
*
Expand Down Expand Up @@ -96,12 +95,10 @@ function checkPaths(name, template) {
* @param {ReturnType<typeof checkPaths>} param0 Template data from meta file
*/
function getTemplatesData({ name, template, targets }) {
/**
* @type {TemplatesContent}
*/
const templatesContent = {
resource: null,
story: null,
style: null,
test: null
}

Expand All @@ -122,6 +119,12 @@ function getTemplatesData({ name, template, targets }) {
)
}

if (template?.style) {
templatesContent.style = readFileContent(
getTemplateFullPath(template?.style?.template)
)
}

return { name, template, templatesContent, targets }
} catch (error) {
console.error(error)
Expand Down Expand Up @@ -172,49 +175,52 @@ function handleTemplateReplacements({
}

/**
* Create files after processing
*
* @param {ReturnType<typeof checkPaths>} param0 Template data from meta file
* @returns {boolean}
*/
function createResources({ name, targets, template, templatesContent }) {
const created = {
resource: false,
story: undefined,
test: undefined
}
/**
* @type {string[]}
*/
let created = []

if (targets.resource) {
if (template.folderWrapper)
template.resource.path = join(template.resource?.path, name)

const fullPath = getFullPath(name, 'resource', template)

created.resource = createFileWithContent(
const resourceCreated = createFileWithContent(
fullPath,
templatesContent.resource
)

if (resourceCreated) created.push(fullPath)
}

if (targets?.test) {
if (template.folderWrapper)
template.test.path = join(template?.test?.path, name)

const fullPath = getFullPath(name, 'test', template)
const testCreated = createFileWithContent(fullPath, templatesContent.test)

created.test = createFileWithContent(fullPath, templatesContent.test)
if (testCreated) created.push(fullPath)
}

if (targets?.story) {
if (template.folderWrapper)
template.story.path = join(template?.story?.path, name)

const fullPath = getFullPath(name, 'story', template)
const storyCreated = createFileWithContent(
fullPath,
templatesContent?.story
)

created.story = createFileWithContent(fullPath, templatesContent?.story)
if (storyCreated) created.push(fullPath)
}

return {
created,
paths: targets
}
return created
}

0 comments on commit 124d2fc

Please sign in to comment.