Skip to content

Commit 885b75f

Browse files
committed
feat: added storybook support
1 parent f6bc82e commit 885b75f

File tree

6 files changed

+113
-0
lines changed

6 files changed

+113
-0
lines changed

.hayde.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"propList": ["testProp", "testProp2"]
2323
}
2424
},
25+
"storybook",
2526
"materialUI",
2627
{
2728
"name": "chakraUI",

src/features/storybook/index.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/* eslint-disable @typescript-eslint/no-unused-vars */
2+
import {
3+
PluginInitParams,
4+
PluginInitReturn,
5+
PluginRunParams,
6+
PluginRunReturn,
7+
} from "../../creatorSettings/creatorSettings.type";
8+
import { IPluginOptions, ISettings, OutAnswers } from "./interfaces";
9+
import inquirer from "inquirer";
10+
import { questions } from "./questions";
11+
import { compileTemplate } from "@/internalFeatures/templatesLibrary";
12+
import { createFile } from "@/internalFeatures/fsLibrary";
13+
14+
export { questions } from "./questions";
15+
export { defaultSettings } from "./interfaces";
16+
17+
export const pluginName = "storybook";
18+
19+
export async function initPlugin({
20+
options,
21+
globalOptions,
22+
}: PluginInitParams<IPluginOptions>): Promise<
23+
PluginInitReturn<IPluginOptions>
24+
> {
25+
const answers = (await inquirer.prompt(
26+
questions,
27+
options
28+
)) as Required<ISettings>;
29+
30+
return {
31+
answers,
32+
};
33+
}
34+
35+
export async function runPlugin({
36+
pluginSettings,
37+
globalSettings,
38+
allAnswers,
39+
}: PluginRunParams<ISettings, OutAnswers>): Promise<PluginRunReturn> {
40+
const answers = allAnswers.storybook?.answers as Required<ISettings>;
41+
const cssContent = await compileTemplate(
42+
answers.templateName,
43+
answers.templateFolder,
44+
globalSettings,
45+
allAnswers
46+
);
47+
48+
createFile(allAnswers, `.stories.tsx`, cssContent);
49+
}

src/features/storybook/interfaces.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { PluginInitReturn } from "@/creatorSettings/creatorSettings.type";
2+
3+
export interface IPluginOptions {
4+
storybookSupport?: boolean;
5+
}
6+
7+
export interface ISettings extends IPluginOptions {
8+
templateName: string;
9+
templateFolder: string;
10+
}
11+
12+
export type OutAnswers = {
13+
storybook: PluginInitReturn<ISettings>;
14+
};
15+
16+
export const defaultSettings: ISettings = {
17+
templateName: "main",
18+
templateFolder: "storybook",
19+
};

src/features/storybook/questions.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import { Question } from "inquirer";
2+
// import { IPluginOptions } from "./interfaces";
3+
4+
export const questions: Question[] = [];

src/features/storybook/readme.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
## Storybook module
2+
3+
### Usage
4+
5+
Please create a new json file called `.hayde.json` in your project root. This file will be used to configure the Hayde.
6+
7+
And then add `storybook` to the plugins array.
8+
9+
```json
10+
{
11+
"plugins": [
12+
"general",
13+
"storybook",
14+
"reactJS",
15+
"materialUI",
16+
"chakraUI"
17+
]
18+
}
19+
```
20+
21+
### Options
22+
23+
| Option | Description | Default | Type |
24+
| -------------- | ----------- | --------- | ------ |
25+
| templateName | - | cssModule | string |
26+
| templateFolder | - | css | string |

templates/storybook/main.hbs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import type { Meta, StoryObj } from "@storybook/react";
2+
3+
import {{ general.answers.componentName }} from "./{{ general.answers.componentName }}";
4+
5+
const meta: Meta<typeof {{ general.answers.componentName }}> = {
6+
component: {{ general.answers.componentName }},
7+
};
8+
9+
export default meta;
10+
type Story = StoryObj<typeof {{ general.answers.componentName }}>;
11+
12+
export const General: Story = {
13+
render: () => <{{ general.answers.componentName }} />,
14+
};

0 commit comments

Comments
 (0)