Skip to content

Commit

Permalink
refact: SDS 템플릿 생성 자동화 도구 구축
Browse files Browse the repository at this point in the history
  • Loading branch information
LeeJeongHooo committed Sep 6, 2024
1 parent c6396bb commit 01d261b
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 20 deletions.
59 changes: 43 additions & 16 deletions packages/core/sds/turbo/generators/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,50 @@ export default function generator(plop: PlopTypes.NodePlopAPI): void {
},
],
actions: (answers) => {
if (!answers) {
return [];
}
if (!answers) return [];

return [
{
type: 'add',
path: `src/{{ type }}/{{ name }}.${answers.type === 'components' ? 'tsx' : 'ts'}`,
templateFile: `templates/${answers.type === 'components' ? 'component' : 'theme'}.hbs`,
},
{
type: 'append',
path: 'src/{{ type }}/index.ts',
pattern: /(export {[^]*} from '[^]*';)/g,
template: "export { {{ name }} } from './{{ name }}'",
},
];
switch (answers.type) {
case 'components':
return componentsActions;
case 'theme':
return themeActions;
default:
return [];
}
},
});
}

const componentsActions = [
{
type: 'add',
path: `src/{{ type }}/{{ name }}/{{ name }}.tsx`,
templateFile: `templates/component.hbs`,
},
{
type: 'add',
path: `src/{{ type }}/{{ name }}/index.ts`,
template: "export { {{ pascalCase name }} } from './{{ name }}'",
},
{ type: 'add', path: `src/{{ type }}/{{ name }}/styles.ts` },
{
type: 'modify',
path: 'src/{{ type }}/index.ts',
pattern: /$(?![\s\S])/g,
template: "$&export * from './{{ name }}';\n",
},
];

const themeActions = [
{
type: 'add',
path: `src/{{ type }}/{{ name }}.ts`,
templateFile: `templates/theme.hbs`,
},
{
type: 'modify',
path: 'src/{{ type }}/index.ts',
pattern: /$(?![\s\S])/g,
template: "export { {{ name }} } from './{{ name }}';\n",
},
];
4 changes: 0 additions & 4 deletions packages/core/sds/turbo/generators/templates/component.hbs
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
'use client';

import { css } from '@emotion/react';

interface {{ pascalCase name }}Props {
children: React.ReactNode
}
Expand Down

0 comments on commit 01d261b

Please sign in to comment.