Skip to content

Commit

Permalink
feat: add style to generated assets and update meta file template
Browse files Browse the repository at this point in the history
  • Loading branch information
ipetinate committed May 23, 2024
1 parent 6049a77 commit e7df1d2
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 16 deletions.
3 changes: 3 additions & 0 deletions .clingon/templates/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
story:
path: 'src/components'
template: './ReactComponent/Component.stories.tsx'
style:
path: 'src/components'
template: './ReactComponent/Component.styles.css'

- identifier: async-function
case: 'kebab-case'
Expand Down
57 changes: 46 additions & 11 deletions src/generators/scaffold-template.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,40 +47,53 @@ function checkPaths(name, template) {
const targets = {
resource: false,
test: false,
story: false
story: false,
style: false
}

const resourcePath = template?.folderWrapper
? join(template?.resource?.path, name)
: template?.resource?.path

const storyPath = template?.folderWrapper
? join(template?.story?.path, name)
: template?.story?.path

const testPath = template?.folderWrapper
? join(template?.test?.path, name)
: template?.test?.path

targets.resource = checkDirectoriesTree(splitPathString(resourcePath))

if (!targets?.resource) {
targets.resource = createDir(getTargetFullPath(resourcePath))
}

if (template?.test) {
const testPath = template?.folderWrapper
? join(template?.test?.path, name)
: template?.test?.path

targets.test = checkDirectoriesTree(splitPathString(testPath))

if (!targets.test) {
targets.resource = createDir(getTargetFullPath(testPath))
targets.test = createDir(getTargetFullPath(testPath))
}
}

if (template?.story) {
const storyPath = template?.folderWrapper
? join(template?.story?.path, name)
: template?.story?.path

targets.story = checkDirectoriesTree(splitPathString(storyPath))

if (!targets.story) {
targets.resource = createDir(getTargetFullPath(storyPath))
targets.story = createDir(getTargetFullPath(storyPath))
}
}

if (template?.style) {
const stylePath = template?.folderWrapper
? join(template?.style?.path, name)
: template?.style?.path

targets.style = checkDirectoriesTree(splitPathString(stylePath))

if (!targets.style) {
targets.style = createDir(getTargetFullPath(stylePath))
}
}

Expand Down Expand Up @@ -168,6 +181,15 @@ function handleTemplateReplacements({
template
)
}

if (templatesContent?.style) {
templatesContent.style = replaceContentFromSideResource(
name,
templatesContent.style,
'style',
template
)
}
}

return { name, template, templatesContent, targets }
Expand Down Expand Up @@ -208,6 +230,19 @@ function createResources({ name, targets, template, templatesContent }) {
if (testCreated) created.push(fullPath)
}

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

const fullPath = getFullPath(name, 'style', template)
const styleCreated = createFileWithContent(
fullPath,
templatesContent?.style
)

if (styleCreated) created.push(fullPath)
}

if (targets?.story) {
if (template.folderWrapper)
template.story.path = join(template?.story?.path, name)
Expand Down
1 change: 0 additions & 1 deletion src/schemas/custom-template.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,5 @@ export const templateResourceTypeMap = {
*/
export const customTemplateTypeMap = {
identifier: 'string',
case: 'string',
resource: templateResourceTypeMap
}
16 changes: 12 additions & 4 deletions src/templates/core/meta.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
# Auto generated by Clingon CLI
# This file is only a example, feel free to edit them
# ┌-----------------------------------------------------------------┐
# ⎪ Auto generated by Clingon CLI ⎪
# ⎪ This file is only a example, feel free to edit them ⎪
# ⎪ ⎪
# ⎪ In the README file you will find more details and a complete ⎪
# ⎪ guide on how to use this feature: .clingon/templates/README.md ⎪
# ⎪ ------------------------------- ⎪
# ⎪ AFTER READ, REMOVE THIS SECTION ⎪
# └-----------------------------------------------------------------┘

# In the README file you will find more details and a complete guide on how to use this feature:
# .clingon/templates/README.md
# Component

- identifier: component
folderWrapper: true
Expand All @@ -19,6 +25,8 @@
path: 'src/components'
template: './component/Component.styles.css'

# Async Function

- identifier: async-function
resource:
path: src/utils
Expand Down
1 change: 1 addition & 0 deletions src/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ import {
* resource: TemplateResource
* test?: TemplateResource
* story?: TemplateResource
* style?: TemplateResource
* }} CustomTemplate - Custom template from meta file
*
* @typedef {"bigint" | "boolean" | "function" | "number" | "object" | "string" | "symbol" | "undefined"} Primitives - JS Primities
Expand Down

0 comments on commit e7df1d2

Please sign in to comment.