Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(sds): components, theme init script #55

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/core/sds/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"scripts": {
"lint": "eslint . --max-warnings 0",
"type-check": "tsc --noEmit",
"generate:sds": "turbo gen sds-template",
"storybook": "storybook dev -p 6007",
"build-storybook": "storybook build"
},
Expand Down
81 changes: 81 additions & 0 deletions packages/core/sds/turbo/generators/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
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 [];

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",
},
];
11 changes: 11 additions & 0 deletions packages/core/sds/turbo/generators/templates/component.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
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 }} = {};