2022-01-06 13:44:13 +00:00
export default function ( plop ) {
2021-06-18 14:07:17 +00:00
plop . setHelper ( 'tagWithoutPrefix' , tag => tag . replace ( /^sl-/ , '' ) ) ;
plop . setHelper ( 'tagToTitle' , tag => {
const withoutPrefix = plop . getHelper ( 'tagWithoutPrefix' ) ;
const titleCase = plop . getHelper ( 'titleCase' ) ;
2022-03-14 12:59:21 +00:00
return titleCase ( withoutPrefix ( tag ) . replace ( /-/g , ' ' ) ) ;
2021-06-18 14:07:17 +00:00
} ) ;
plop . setGenerator ( 'component' , {
description : 'Generate a new component' ,
prompts : [
{
type : 'input' ,
name : 'tag' ,
message : 'Tag name? (e.g. sl-button)' ,
validate : value => {
// Start with sl- and include only a-z + dashes
if ( ! /^sl-[a-z-+]+/ . test ( value ) ) {
return false ;
}
// No double dashes or ending dash
if ( value . includes ( '--' ) || value . endsWith ( '-' ) ) {
return false ;
}
return true ;
}
}
] ,
actions : [
{
type : 'add' ,
path : '../../src/components/{{ tagWithoutPrefix tag }}/{{ tagWithoutPrefix tag }}.ts' ,
2023-07-24 17:00:07 +00:00
templateFile : 'templates/component/define.hbs'
} ,
{
type : 'add' ,
path : '../../src/components/{{ tagWithoutPrefix tag }}/{{ tagWithoutPrefix tag }}.component.ts' ,
2021-06-18 14:07:17 +00:00
templateFile : 'templates/component/component.hbs'
} ,
{
type : 'add' ,
2021-07-10 00:45:44 +00:00
path : '../../src/components/{{ tagWithoutPrefix tag }}/{{ tagWithoutPrefix tag }}.styles.ts' ,
2021-06-18 14:07:17 +00:00
templateFile : 'templates/component/styles.hbs'
} ,
{
type : 'add' ,
path : '../../src/components/{{ tagWithoutPrefix tag }}/{{ tagWithoutPrefix tag }}.test.ts' ,
templateFile : 'templates/component/tests.hbs'
} ,
{
type : 'add' ,
2023-06-07 20:49:27 +00:00
path : '../../docs/pages/components/{{ tagWithoutPrefix tag }}.md' ,
2021-06-18 14:07:17 +00:00
templateFile : 'templates/component/docs.hbs'
} ,
{
type : 'modify' ,
path : '../../src/shoelace.ts' ,
pattern : /\/\* plop:component \*\// ,
2023-06-22 14:56:24 +00:00
template : ` export { default as {{ properCase tag }} } from './components/{{ tagWithoutPrefix tag }}/{{ tagWithoutPrefix tag }}.js'; \n /* plop:component */ `
2021-06-18 14:07:17 +00:00
}
]
} ) ;
2022-01-06 13:44:13 +00:00
}