-
Notifications
You must be signed in to change notification settings - Fork 728
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Maintenance: Add Hygen template generator to CI
- Loading branch information
Benjamin Scharf
committed
May 8, 2024
1 parent
506c295
commit 53fe71a
Showing
12 changed files
with
775 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/` | ||
}, | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
14
.dev/hygen/_templates/component/new/componentTest.spec.ts.t
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
14
.dev/hygen/_templates/component/new/composableTest.spec.ts.t
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}, | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
Oops, something went wrong.