Skip to content

Commit

Permalink
Maintenance: Add Hygen template generator to CI
Browse files Browse the repository at this point in the history
  • Loading branch information
Benjamin Scharf committed May 8, 2024
1 parent 506c295 commit 53fe71a
Show file tree
Hide file tree
Showing 12 changed files with 775 additions and 1 deletion.
28 changes: 28 additions & 0 deletions .dev/hygen/.hygen.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/

const config = require('./lib.config.js')

module.exports = {
helpers: {
componentLibrary: (libraryName, path = true) => {
if (libraryName === 'Desktop') return path ? 'apps/desktop' : 'desktop'
if (libraryName === 'Mobile') return path ? 'apps/mobile' : 'mobile'
if (libraryName === 'Shared') return 'shared'
},
composableName: (name, h) => {
return h.changeCase.camel(`use${name}`)
},
componentGenericWitPrefix: (name, h) => {
const nameWithGenericPrefix = name.replace(
new RegExp(`${config.generic.prefix}`, 'i'),
'',
)
return h.changeCase.pascal(
`${config.generic.prefix}${h.changeCase.pascal(nameWithGenericPrefix)}`,
)
},
zammadCopyright: () => {
return `Copyright (C) 2012-${new Date().getFullYear()} Zammad Foundation, https://zammad-foundation.org/`
},
},
}
10 changes: 10 additions & 0 deletions .dev/hygen/_templates/component/new/Component.vue.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
to: ../../app/frontend/<%= h.componentLibrary(libraryName) %>/components/<%= h.componentGenericWitPrefix(name, h) %>/<%= h.componentGenericWitPrefix(name, h) %>.vue
---
<!-- <%= h.zammadCopyright() %> -->

<script setup lang="ts"></script>

<template>
<div>Hello <%= h.componentGenericWitPrefix(name, h) %></div>
</template>
14 changes: 14 additions & 0 deletions .dev/hygen/_templates/component/new/componentTest.spec.ts.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
to: ../../app/frontend/<%= h.componentLibrary(libraryName) %>/components/<%= h.componentGenericWitPrefix(name, h) %>/__tests__/<%= h.componentGenericWitPrefix(name, h) %>.spec.ts
---
// <%= h.zammadCopyright() %>

import { renderComponent } from '#tests/support/components/index.ts'
import <%= h.componentGenericWitPrefix(name, h) %> from '#<%= h.componentLibrary(libraryName, false) %>/components/<%= h.componentGenericWitPrefix(name, h) %>/<%= h.componentGenericWitPrefix(name, h) %>.vue'

describe('<%= h.componentGenericWitPrefix(name, h) %>', () => {
it('renders <%= h.componentGenericWitPrefix(name, h) %>', () => {
const wrapper = renderComponent(<%= h.componentGenericWitPrefix(name, h) %>, {})
expect(wrapper).toBeInTheDocument()
})
})
6 changes: 6 additions & 0 deletions .dev/hygen/_templates/component/new/composable.ts.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
to: "../../<%= withComposable ? `app/frontend/${h.componentLibrary(libraryName, h)}/components/${h.componentGenericWitPrefix(name, h)}/${h.composableName(h.componentGenericWitPrefix(name, h), h)}.ts` : null %>"
---
// <%= h.zammadCopyright() %>

export const <%= h.composableName(h.componentGenericWitPrefix(name, h), h) %> = () => {}
14 changes: 14 additions & 0 deletions .dev/hygen/_templates/component/new/composableTest.spec.ts.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
to: "../../<%= withTypeFile ? `app/frontend/${h.componentLibrary(libraryName, h)}/components/${h.componentGenericWitPrefix(name, h)}/__tests__/${h.composableName(h.componentGenericWitPrefix(name, h), h)}.spec.ts` : null %>"
---
// <%= h.zammadCopyright() %>

import { renderComponent } from '#tests/support/components/index.ts'
import { <%= h.composableName(h.componentGenericWitPrefix(name, h), h) %> } from '#<%= h.componentLibrary(libraryName, false) %>/components/<%= h.componentGenericWitPrefix(name, h) %>/<%= h.composableName(h.componentGenericWitPrefix(name, h), h) %>.ts'

describe('<%= h.composableName(h.componentGenericWitPrefix(name, h), h) %>', () => {
it('test <%= h.composableName(h.componentGenericWitPrefix(name, h), h) %>', () => {
const composable = <%= h.composableName(h.componentGenericWitPrefix(name, h), h) %>()
expect(composable).toHaveBeenCalledOnce()
})
})
35 changes: 35 additions & 0 deletions .dev/hygen/_templates/component/new/prompt.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/

module.exports = [
{
type: 'select',
name: 'libraryName',
// eslint-disable-next-line zammad/zammad-detect-translatable-string
message: 'Where should the component be created?',
choices: [
{ libraryName: 'desktop', message: 'Desktop' },
{ libraryName: 'mobile', message: 'Mobile' },
{ libraryName: 'shared', message: 'Shared' },
],
},
{
type: 'input',
name: 'name',
// eslint-disable-next-line zammad/zammad-detect-translatable-string
message: 'Component name?',
},
{
type: 'confirm',
name: 'withComposable',
// eslint-disable-next-line zammad/zammad-detect-translatable-string
message: 'Should generate a composable?',
initial: true,
},
{
type: 'confirm',
name: 'withTypeFile',
// eslint-disable-next-line zammad/zammad-detect-translatable-string
message: 'Should generate a type file?',
initial: true,
},
]
8 changes: 8 additions & 0 deletions .dev/hygen/_templates/component/new/type.ts.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
to: "../../<%= withTypeFile ? `app/frontend/${h.componentLibrary(libraryName, h)}/components/${h.componentGenericWitPrefix(name, h)}/types.ts` : null %>"
---
// Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/

export interface Dummy {
// Add your interface here
}
8 changes: 8 additions & 0 deletions .dev/hygen/lib.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/

module.exports = {
generic: {
name: 'Zammad Generic Component',
prefix: 'Common',
},
}
8 changes: 8 additions & 0 deletions .dev/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"private": true,
"version": "1.0.0",
"description": "DX packages",
"dependencies": {
"hygen": "^6.2.11"
}
}

0 comments on commit 53fe71a

Please sign in to comment.