Skip to content

Commit

Permalink
Merge pull request #117 from icaldana/release/0.0.21
Browse files Browse the repository at this point in the history
Release/0.0.21
  • Loading branch information
icaldana authored Dec 20, 2024
2 parents c6e8ad5 + bf69118 commit 4637094
Show file tree
Hide file tree
Showing 9 changed files with 5,468 additions and 12,250 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ dist
build
coverage
.DS_Store
./package-lock.json
./package-lock.json
/.storybook/stories
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ repos:
- id: post_commit_hook
stages: [post-commit]
- repo: https://github.com/melisource/fury_datasec-git-hooks
rev: 1.2.0
rev: 1.2.2
hooks:
- id: pre_commit_hook
stages: [commit]
Expand Down
31 changes: 0 additions & 31 deletions .storybook/examples.stories.tsx

This file was deleted.

59 changes: 59 additions & 0 deletions .storybook/generate-stories.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
const fs = require('fs');
const path = require('path');

const examplesDir = path.join(__dirname, '../examples');
const storiesDir = path.join(__dirname, './stories');

if (!fs.existsSync(storiesDir)) {
fs.mkdirSync(storiesDir, { recursive: true });
}

const storyTemplate = (componentPath, storyTitle, exportName) => `
import React, { useEffect, useState } from 'react';
import { Meta, StoryFn } from '@storybook/react';
const ExampleComponent = ({ file }) => {
const [component, setComponent] = useState<React.ReactElement | null>(null);
console.log('Loading component', \`../../examples/\${file}\`);
useEffect(() => {
import(\`../../examples/\${file}\`).then(({ default: App }) => {
setComponent(
<React.StrictMode>
<App />
</React.StrictMode>
);
});
}, [file]);
return component;
};
export default {
title: '${storyTitle}',
component: ExampleComponent,
} as Meta;
export const ${exportName}: StoryFn = () => <ExampleComponent file="${componentPath}" />;
`;

const processDirectory = (currentDir) => {
fs.readdirSync(currentDir, { withFileTypes: true }).forEach((entry) => {
const fullPath = path.join(currentDir, entry.name);
if (entry.isDirectory()) {
processDirectory(fullPath);
} else if (entry.isFile() && fullPath.includes('/bricks/')) {
const relativePath = path.relative(examplesDir, fullPath).replace(/\\/g, '/');
const storyName = path.basename(entry.name, '.tsx').replace(/^\d+-|-/g, '');
const storyFileName = `${relativePath.split('/')[1]}-${storyName}.stories.tsx`;
const storyPath = path.join(storiesDir, storyFileName);
const storyTitle = relativePath.substring(0, relativePath.lastIndexOf('/'));

const storyContent = storyTemplate(relativePath, storyTitle, storyName);
fs.writeFileSync(storyPath, storyContent.trim());
}
});
};

processDirectory(examplesDir);
12 changes: 8 additions & 4 deletions .storybook/main.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
module.exports = {
stories: ['./examples.stories.tsx'],
features: {
storyStoreV7: false,
},
stories: ['./stories/**/*.stories.tsx'],
addons: ['@storybook/addon-webpack5-compiler-babel'],
features: {},

framework: {
name: '@storybook/react-webpack5',
options: {},
},

typescript: {
reactDocgen: 'react-docgen-typescript',
},
};
2 changes: 1 addition & 1 deletion .storybook/preview.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export const parameters = {
actions: { argTypesRegex: '^on[A-Z].*' },
actions: {},
controls: {
matchers: {
color: /(background|color)$/i,
Expand Down
Loading

0 comments on commit 4637094

Please sign in to comment.