Skip to content

Commit

Permalink
chore: components, theme init script 생성
Browse files Browse the repository at this point in the history
  • Loading branch information
LeeJeongHooo committed Jul 8, 2024
1 parent 0e4d133 commit 48dbaf2
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 2 deletions.
7 changes: 5 additions & 2 deletions packages/core/sds/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
"version": "0.0.0",
"private": true,
"exports": {
".": "./src/index.ts"
".": "./src/index.ts",
"./components/": "./src/components/index.ts",
"./theme": "./src/theme/index.ts"
},
"scripts": {
"lint": "eslint . --max-warnings 0",
"type-check": "tsc --noEmit"
"type-check": "tsc --noEmit",
"generate:sds": "turbo gen sds-template"
},
"devDependencies": {
"@sambad/eslint-config": "workspace:*",
Expand Down
3 changes: 3 additions & 0 deletions packages/core/sds/src/components/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export { Button } from './Button';
export { Card } from './Card';
export { Code } from './Code';
1 change: 1 addition & 0 deletions packages/core/sds/src/theme/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { colors } from './colors';
54 changes: 54 additions & 0 deletions packages/core/sds/turbo/generators/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import type { PlopTypes } from '@turbo/gen';

export default function generator(plop: PlopTypes.NodePlopAPI): void {
plop.setGenerator('sds-template', {
description: 'Adds a new sds',
prompts: [
{
type: 'list',
name: 'type',
message: 'Enter component or theme:',
choices: [
{
name: 'components',
value: 'components',
},
{
name: 'theme',
value: 'theme',
},
],
},
{
type: 'input',
name: 'name',
message: (answers) => `What is the name of the ${answers.type}?`,
validate: (value: string) => {
if (/.+/.test(value)) {
return true;
}
return 'name is required';
},
},
],
actions: (answers) => {
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 }}'",
},
];
},
});
}
15 changes: 15 additions & 0 deletions packages/core/sds/turbo/generators/templates/component.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
'use client';

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

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

export const {{ pascalCase name }} = ({ children }: {{ pascalCase name }}Props) => {
return (
<div>
{children}
</div>
);
};
1 change: 1 addition & 0 deletions packages/core/sds/turbo/generators/templates/theme.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const {{ name }} = {};

0 comments on commit 48dbaf2

Please sign in to comment.