Skip to content

Commit

Permalink
chore: moved storybook config to config library
Browse files Browse the repository at this point in the history
  • Loading branch information
gearonix committed Aug 19, 2023
1 parent 9d6e32d commit b49a947
Show file tree
Hide file tree
Showing 37 changed files with 236 additions and 117 deletions.
28 changes: 26 additions & 2 deletions .github/workflows/master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
name: Linting project
runs-on: ubuntu-latest
steps:
# Node.js and pnpm setup
# Node.js and yarn setup
- uses: actions/checkout@v3
- name: Installing Node.js 19.x
uses: actions/setup-node@v3
Expand All @@ -28,7 +28,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
# Node.js and pnpm setup
# Node.js and yarn setup
- name: Installing Node.js 19.x
uses: actions/setup-node@v3
with:
Expand All @@ -47,3 +47,27 @@ jobs:
FOLDER: dist
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
MESSAGE: "Build: ({sha}) {msg}"
- name: Building storybook
run: yarn dlx nx run ui:storybook:build
- name: Pushing to build-storybook branch
- uses: JamesIves/github-pages-deploy-action@v4
with:
folder: dist/storybook/ui
branch: storybook-build
testing:
name: Testing project
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
# Node.js and yarn setup
- name: Installing Node.js 19.x
uses: actions/setup-node@v3
with:
node-version: 19.x
# Installing deps
- name: Installing dependencies
run: yarn install
# Main rules
- name: Testing storybook
run: yarn dlx nx run ui:storybook:test

24 changes: 12 additions & 12 deletions .yarn/releases/yarn-3.6.2.cjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion apps/client/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "cg-config/tsconfig/base.json",
"extends": "cg-config/src/tsconfig/base.json",
"compilerOptions": {
"target": "ESNext",
"module": "ESNext",
Expand Down
2 changes: 1 addition & 1 deletion apps/server/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "cg-config/tsconfig/base.json",
"extends": "cg-config/src/tsconfig/base.json",
"files": [],
"include": [],
"references": [
Expand Down
2 changes: 1 addition & 1 deletion libs/client-shared/src/storybook/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export * from './decorators'
export { createViewPorts } from './config/viewports'
export * from './lib'
11 changes: 11 additions & 0 deletions libs/client-shared/src/storybook/lib/create-storybook-variant.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Decorator } from '@storybook/react'

export const createStorybookVariant = <T>(defaultArgs: T) => {
return (additionalArgs: Partial<T> = {}, decorators: Decorator[] = []) => ({
args: {
...defaultArgs,
...additionalArgs
},
decorators
})
}
1 change: 1 addition & 0 deletions libs/client-shared/src/storybook/lib/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { createStorybookVariant } from 'src/storybook/lib/create-storybook-variant'
2 changes: 1 addition & 1 deletion libs/client-shared/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@
"path": "./tsconfig.spec.json"
}
],
"extends": "cg-config/tsconfig/base.json"
"extends": "cg-config/src/tsconfig/base.json"
}
2 changes: 1 addition & 1 deletion libs/client-shared/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default defineConfig({
plugins: [
dts({
entryRoot: 'src',
tsConfigFilePath: path.join(__dirname, 'tsconfig.lib.json'),
tsConfigFilePath: path.join(__dirname, 'tsconfig.consts.json'),
skipDiagnostics: true
}),
react(),
Expand Down
File renamed without changes.
File renamed without changes.
7 changes: 5 additions & 2 deletions libs/config/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
export * from './lib/client'
export * from './lib/server'
export * from './consts/client'
export * from './consts/server'

export { createStorybookConfig } from './storybook/create-storybook-config'
export { createPreviewDefaults } from './storybook/create-preview-defaults'
31 changes: 31 additions & 0 deletions libs/config/src/storybook/create-preview-defaults.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { Decorator, Preview } from '@storybook/react'
import { createViewPorts } from './plugins/create-viewports'

interface PreviewDefaultsPayload {
decorators: Decorator[]
}

type CreatePreviewDefaults = (args: PreviewDefaultsPayload) => Preview

export const createPreviewDefaults: CreatePreviewDefaults = ({
decorators
}) => ({
parameters: {
viewport: {
viewports: createViewPorts()
},
actions: { argTypesRegex: '^on[A-Z].*' },
controls: {
matchers: {
color: /(background|color)$/i,
date: /Date$/
}
},
backgrounds: {
values: []
},
storySort: (a, b) =>
a.id === b.id ? 0 : a.id.localeCompare(b.id, undefined, { numeric: true })
},
decorators
})
25 changes: 25 additions & 0 deletions libs/config/src/storybook/create-storybook-config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import type { StorybookConfig } from '@storybook/react-vite'

interface StorybookConfigPayload {
viteConfigPath: string
viteFinal: (config: StorybookConfig) => StorybookConfig
}

type CreateStorybookConfig = (args: StorybookConfigPayload) => StorybookConfig

export const createStorybookConfig: CreateStorybookConfig = ({
viteConfigPath,
viteFinal
}) => ({
stories: ['../src/**/*.stories.@(js|jsx|ts|tsx)'],
addons: ['@storybook/addon-essentials', '@storybook/addon-interactions'],
framework: {
name: '@storybook/react-vite',
options: {
builder: {
viteConfigPath
}
}
},
viteFinal
})
File renamed without changes.
2 changes: 1 addition & 1 deletion libs/config/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "cg-config/tsconfig/base.json",
"extends": "cg-config/src/tsconfig/base.json",
"compilerOptions": {
"module": "commonjs",
"forceConsistentCasingInFileNames": true,
Expand Down
3 changes: 2 additions & 1 deletion libs/config/tsconfig.lib.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"types": ["node"],
"baseUrl": ".",
"paths": {
"$/services": ["../services/src/index.ts"],
"$/services": ["../nest-services/src/index.ts"],
"$/client-shared": ["../client-shared/src/index.ts"],
"$/server/*": ["../../apps/server/src/*"]
}
},
Expand Down
2 changes: 1 addition & 1 deletion libs/editor/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@
"path": "./tsconfig.spec.json"
}
],
"extends": "cg-config/tsconfig/base.json"
"extends": "cg-config/src/tsconfig/base.json"
}
2 changes: 1 addition & 1 deletion libs/nest-common/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "cg-config/tsconfig/base.json",
"extends": "cg-config/src/tsconfig/base.json",
"compilerOptions": {
"module": "commonjs",
"forceConsistentCasingInFileNames": true,
Expand Down
2 changes: 1 addition & 1 deletion libs/nest-services/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "cg-config/tsconfig/base.json",
"extends": "cg-config/src/tsconfig/base.json",
"compilerOptions": {
"module": "commonjs",
"forceConsistentCasingInFileNames": true,
Expand Down
2 changes: 1 addition & 1 deletion libs/nest-services/tsconfig.lib.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "cg-config/tsconfig/base.json",
"extends": "cg-config/src/tsconfig/base.json",
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"declaration": true,
Expand Down
3 changes: 2 additions & 1 deletion libs/ui/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"../../.eslintrc.js"
],
"ignorePatterns": [
"!**/*"
"!**/*",
".storybook"
]
}
24 changes: 10 additions & 14 deletions libs/ui/.storybook/main.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,20 @@
import { createStorybookConfig } from 'cg-config/src'
import type { StorybookConfig } from '@storybook/react-vite'
import { mergeConfig } from 'vite'
import viteTsConfigPaths from 'vite-tsconfig-paths'

const config: StorybookConfig = {
stories: ['../src/**/*.stories.@(js|jsx|ts|tsx)'],
addons: ['@storybook/addon-essentials', '@storybook/addon-interactions'],
framework: {
name: '@storybook/react-vite',
options: {
builder: {
viteConfigPath: 'libs/ui/vite.config.ts'
}
}
},
viteFinal: (config) => {
const config: StorybookConfig = createStorybookConfig({
viteConfigPath: 'libs/ui/vite.config.ts',
viteFinal: (config: StorybookConfig): StorybookConfig => {
return mergeConfig(config, {
define: {
'process.env': process.env
}
},
plugins: [
viteTsConfigPaths()
]
})
}
}
})

export default config
32 changes: 6 additions & 26 deletions libs/ui/.storybook/preview.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,9 @@
import {
createViewPorts,
ThemeDecorator,
StylesDecorator
} from '$/client-shared'
import { Preview, Decorator } from '@storybook/react'
import { StylesDecorator, ThemeDecorator } from '$/client-shared'
import { Preview } from '@storybook/react'
import { createPreviewDefaults } from '$/config'

const decorators: Decorator[] = [StylesDecorator, ThemeDecorator]

const preview: Preview = {
parameters: {
viewport: {
viewports: createViewPorts()
},
actions: { argTypesRegex: '^on[A-Z].*' },
controls: {
matchers: {
color: /(background|color)$/i,
date: /Date$/
}
},
backgrounds: {
values: []
}
},
decorators
}
const preview: Preview = createPreviewDefaults({
decorators: [StylesDecorator, ThemeDecorator]
})

export default preview
3 changes: 3 additions & 0 deletions libs/ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
"require": "./index.js"
}
},
"dependencies": {
"cg-client-shared": "workspace:^"
},
"devDependencies": {
"cg-config": "workspace:^",
"cg-generator": "workspace:^"
Expand Down
17 changes: 9 additions & 8 deletions libs/ui/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"projectType": "library",
"tags": [],
"targets": {
"generate": {
"generate:ui": {
"command": "cross-env HYGEN_TMPLS=../generator/templates hygen {args.m} {args.com} --module_name={args.n}",
"options": {
"cwd": "libs/ui",
Expand All @@ -16,7 +16,7 @@
]
}
},
"storybook": {
"storybook:serve": {
"executor": "@nx/storybook:storybook",
"options": {
"port": 4400,
Expand All @@ -28,7 +28,7 @@
}
}
},
"build-storybook": {
"storybook:build": {
"executor": "@nx/storybook:build",
"outputs": [
"{options.outputDir}"
Expand All @@ -43,21 +43,22 @@
}
}
},
"test-storybook": {
"storybook:test": {
"executor": "nx:run-commands",
"options": {
"command": "test-storybook -c libs/ui/.storybook --url=http://localhost:4400"
}
},
"dependsOn": ["storybook:serve"]
},
"static-storybook": {
"storybook:preview": {
"executor": "@nx/web:file-server",
"options": {
"buildTarget": "ui:build-storybook",
"buildTarget": "ui:storybook:build",
"staticFilePath": "dist/storybook/ui"
},
"configurations": {
"ci": {
"buildTarget": "ui:build-storybook:ci"
"buildTarget": "ui:storybook:build:ci"
}
}
},
Expand Down
Loading

0 comments on commit b49a947

Please sign in to comment.