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

IT-5852 Upgrade storybook and start with vite #382

Merged
merged 50 commits into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
816bc0a
IT-5852 Upgrade storybook and start with vite
fraszczakszymon Jul 2, 2024
6b6fda5
Merge branch 'refs/heads/master' into IT-5852-sb8-vite
tweetgeek Aug 12, 2024
35875a3
upgrade to 8.2, add support node_modules for yarn 3
tweetgeek Aug 12, 2024
8904fe9
set sb config
tweetgeek Aug 13, 2024
7678764
wrap all in defineComponent
tweetgeek Aug 13, 2024
af1120d
migrate defaultValue
tweetgeek Aug 13, 2024
c975998
fix dependencies version
tweetgeek Aug 13, 2024
4f4cabc
fix types
tweetgeek Aug 13, 2024
7c73389
fix reactivity, add 2 components in new API (Well & Tile)
tweetgeek Aug 19, 2024
a736637
set content-type on uploaded files
tweetgeek Aug 20, 2024
4429b24
remove type: module
tweetgeek Aug 20, 2024
1efe3d1
set [email protected]
tweetgeek Aug 20, 2024
1126d9b
add @types/jest
tweetgeek Aug 20, 2024
5349bc5
change jest preset
tweetgeek Aug 20, 2024
a148194
IT-5852 Handle styles in production bundles
fraszczakszymon Sep 30, 2024
00adc7b
IT-5852 Move global.css
fraszczakszymon Sep 30, 2024
c00b4f8
Merge branch 'master' into IT-5852-sb8-vite
fraszczakszymon Sep 30, 2024
71d85c1
IT-5852 Fix tests
fraszczakszymon Sep 30, 2024
786a67d
IT-5852 Fix OverlayHeader
fraszczakszymon Sep 30, 2024
5b17e08
IT-5852 Move dev dependencies
fraszczakszymon Sep 30, 2024
b9cc2ac
IT-5852 Remove vue-tsc
fraszczakszymon Sep 30, 2024
bc8de9a
IT-5852 Define type=module
fraszczakszymon Sep 30, 2024
74b6bdc
IT-5852 Fix global css
fraszczakszymon Sep 30, 2024
d4761ca
IT-5852 Fix jest config
fraszczakszymon Sep 30, 2024
5b1b74d
IT-5852 Handle global styles in dev mode
fraszczakszymon Sep 30, 2024
26ea2a3
IT-5852 Revert module
fraszczakszymon Sep 30, 2024
ef5e675
IT-5852 Clean up
fraszczakszymon Sep 30, 2024
d2901f1
IT-5852 Clean up yarn changes
fraszczakszymon Sep 30, 2024
d645a9f
IT-5852 global.scss -> preview.scss, fix IconDefinition
fraszczakszymon Sep 30, 2024
77779f2
IT-5852 Resolve fonts
fraszczakszymon Oct 1, 2024
6b5eca4
IT-5852 Fix font paths
fraszczakszymon Oct 1, 2024
b475622
IT-5852 Revert initial alias
fraszczakszymon Oct 1, 2024
6d1dd80
IT-5852 Fix stories args
fraszczakszymon Oct 1, 2024
00c0cc3
IT-5852 Fix updateArgs usages
fraszczakszymon Oct 1, 2024
28f9c9c
IT-5852 Upgrade storybook and set disableSaveFromUI
fraszczakszymon Oct 1, 2024
14ae9c6
IT-5852 Use es2019
fraszczakszymon Oct 1, 2024
a77c452
IT-5852 Move plugin to separate file and add comments
fraszczakszymon Oct 3, 2024
14c2cd9
IT-5852 Move storybook.scss
fraszczakszymon Oct 3, 2024
99493db
IT-5852 Remove comment
fraszczakszymon Oct 3, 2024
d266200
IT-5852 Remove not needed dependencies
fraszczakszymon Oct 3, 2024
9031ab2
IT-5852 Define type=module
fraszczakszymon Oct 3, 2024
5ee5862
IT-5852 Clean up isDimmed
fraszczakszymon Oct 3, 2024
c1c6e23
IT-5852 Build umd only and exclude vite.config from tsconfig
fraszczakszymon Oct 3, 2024
93014bd
IT-5852 Remove BethinkPreset
fraszczakszymon Oct 3, 2024
ccd9ee8
Merge branch 'master' into IT-5852-sb8-vite
fraszczakszymon Oct 3, 2024
d7515a6
IT-5852 Fix file types
fraszczakszymon Oct 3, 2024
e08c343
IT-5852 Fix actions
fraszczakszymon Oct 3, 2024
7e20f4b
IT-5852 Reverted DrawerSection new lines change
fraszczakszymon Oct 3, 2024
0d6cf6b
IT-5852 Disable dts in storybook build
fraszczakszymon Oct 3, 2024
dffe125
IT-5852 Fix datepicker story
fraszczakszymon Oct 3, 2024
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
File renamed without changes.
17 changes: 17 additions & 0 deletions .github/workflows/build-to-review-on-trigger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,23 @@ jobs:
- name: Push to S3 🚀
run: s3cmd put -r -P public/storybook/* s3://${{ vars.S3_REVIEW_BUCKET }}/${{ env.BRANCH_NAME }}/

- name: "Setting Content-Type to application/javascript for all .js files"
run: >-
find "$LOCAL_DIRECTORY" -type f -name "*.js" | while read FILE; do
RELATIVE_PATH="${FILE#public/storybook/}"
echo "s3://${{ vars.S3_REVIEW_BUCKET }}/${{ env.BRANCH_NAME }}/$RELATIVE_PATH"
s3cmd modify --add-header="Content-Type: application/javascript" s3://${{ vars.S3_REVIEW_BUCKET }}/${{ env.BRANCH_NAME }}/$RELATIVE_PATH
done


- name: "Set Content-Type to text/css for all .css files"
run: >-
find "$LOCAL_DIRECTORY" -type f -name "*.css" | while read FILE; do
RELATIVE_PATH="${FILE#public/storybook/}"
echo "s3://${{ vars.S3_REVIEW_BUCKET }}/${{ env.BRANCH_NAME }}/$RELATIVE_PATH"
s3cmd modify --add-header="Content-Type: text/css" s3://${{ vars.S3_REVIEW_BUCKET }}/${{ env.BRANCH_NAME }}/$RELATIVE_PATH
done

- name: Add comment with URL
uses: thollander/actions-comment-pull-request@v2
with:
Expand Down
86 changes: 0 additions & 86 deletions .storybook/main.js

This file was deleted.

42 changes: 42 additions & 0 deletions .storybook/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { StorybookConfig } from '@storybook/vue3-vite';
import { scssPreviewStylesPlugin } from './scss-preview-styles-plugin';

const isProductionMode = () => {
return process.env.NODE_ENV === 'production';
}

const ignoredProductionPlugins = [
'vite:dts',
];

const config: StorybookConfig = {
stories: ['../lib/**/*.stories.@(js|ts)'],
addons: [
'@storybook/addon-actions',
'@storybook/addon-designs',
'@storybook/addon-docs',
'@storybook/addon-controls',
'@storybook/addon-storysource',
'@storybook/addon-viewport',
],
staticDirs: [
{
from: '../lib/fonts',
to: '~design-system/lib/fonts',
}
],
framework: '@storybook/vue3-vite',
viteFinal: (config) => {
return {
...config,
plugins: [
...config.plugins.filter((plugin) => !ignoredProductionPlugins.includes((plugin as any)?.name)),
scssPreviewStylesPlugin({
isProductionMode: isProductionMode(),
})
]
};
},
};

export default config;
2 changes: 1 addition & 1 deletion .storybook/manager.js → .storybook/manager.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { addons } from '@storybook/addons';
import { addons } from '@storybook/manager-api';

addons.setConfig({
sidebar: {
Expand Down
1 change: 1 addition & 0 deletions .storybook/preview-head.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<link rel="stylesheet" href="./preview.css">
3 changes: 3 additions & 0 deletions .storybook/preview.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@import '../lib/styles/normalize';
@import '../lib/styles/design-system';
@import './storybook';
29 changes: 11 additions & 18 deletions .storybook/preview.js → .storybook/preview.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
import 'design-system/lib/styles/_normalize.scss';
import 'design-system/lib/styles/design-system.scss';
import 'design-system/lib/styles/storybook.scss';

import { useArgs } from '@storybook/client-api';
import { initialize } from 'design-system/lib/js/icons/fontawesome';
import { app } from '@storybook/vue3';
import { initialize } from '../lib/js/icons/fontawesome';
import { initializePrimeVue } from '../lib/js';

import { setup } from '@storybook/vue3';

const customViewports = {
mobile: {
name: 'Breakpoint mobile',
Expand Down Expand Up @@ -83,6 +79,9 @@ const customViewports = {
};

export const parameters = {
controls: {
disableSaveFromUI: true,
},
viewport: { viewports: customViewports },
options: {
storySort: {
Expand All @@ -99,14 +98,8 @@ export const parameters = {
},
};

// See https://craigbaldwin.com/blog/updating-args-storybook-vue/
export const decorators = [
(story, context) => {
const [_, updateArgs] = useArgs();
return story({ ...context, updateArgs });
},
];

initializePrimeVue(app);

initialize();
setup((app) => {
// https://storybook.js.org/docs/get-started/frameworks/vue3-vite?renderer=vue#extending-the-vue-application
initializePrimeVue(app);
initialize();
});
43 changes: 43 additions & 0 deletions .storybook/scss-preview-styles-plugin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import fs from 'fs';
import path from 'path';
import sass from 'sass';

const cssFilePath = path.resolve(__dirname, '../public/storybook/preview.css');
const previewStylesPath = path.resolve(__dirname, '../.storybook/preview.scss');

// Custom plugin to compile global styles for storybook preview and load them at the very beginning
// Due to the structure of our components, it's needed to load global styles before components styles
export const scssPreviewStylesPlugin = ({ isProductionMode }) => ({
name: 'scss-preview-styles',
buildStart() {
if (isProductionMode) {
const result = sass.compile(previewStylesPath);

// Compile and save preview.css file, so we can serve it in build storybook (using preview-head.html)
if (!fs.existsSync(path.resolve(__dirname, '../public/storybook'))) {
fs.mkdirSync(path.resolve(__dirname, '../public/storybook'), { recursive: true });
}

fs.writeFileSync(cssFilePath, result.css.toString());
}
},
configureServer(server) {
server.middlewares.use((req, res, next) => {
// Serve compiled CSS file in development mode so it's not required to manually compile the file upfront
if (req.originalUrl === '/preview.css' && !isProductionMode) {
res.setHeader('Content-Type', 'text/css');
res.end(sass.compile(previewStylesPath).css);
} else {
next();
}
});
},
handleHotUpdate({ file, server }) {
// Reload whole storybook on any scss change in order to catch and apply changes in global styles
if (file.endsWith('.scss')) {
server.ws.send({
type: 'full-reload',
});
}
},
});
20 changes: 10 additions & 10 deletions lib/styles/storybook.scss → .storybook/storybook.scss
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
@import 'settings/colors/raw';
@import 'settings/colors/raw-wnl';
@import 'settings/colors/raw-bodywork';
@import 'settings/colors/tokens-variables';
@import 'settings/colors/tokens-wnl-variables';
@import 'settings/colors/tokens-bodywork-variables';
@import 'settings/colors/tokens';
@import 'settings/colors/tokens-bodywork';
@import 'settings/colors/tokens-wnl';
@import 'settings/typography/tokens';
@import '../lib/styles/settings/colors/raw';
@import '../lib/styles/settings/colors/raw-wnl';
@import '../lib/styles/settings/colors/raw-bodywork';
@import '../lib/styles/settings/colors/tokens-variables';
@import '../lib/styles/settings/colors/tokens-wnl-variables';
@import '../lib/styles/settings/colors/tokens-bodywork-variables';
@import '../lib/styles/settings/colors/tokens';
@import '../lib/styles/settings/colors/tokens-bodywork';
@import '../lib/styles/settings/colors/tokens-wnl';
@import '../lib/styles/settings/typography/tokens';

$fontFamily: 'BlinkMacSystemFont', -apple-system, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu',
'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', 'Helvetica', 'Arial', sans-serif;
Expand Down
12 changes: 0 additions & 12 deletions babel.config.json

This file was deleted.

17 changes: 16 additions & 1 deletion deploy_storybook_to_s3.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ fi

BUCKET="wnl-design-system-preview"
BRANCH=$(git symbolic-ref --short -q HEAD | grep -oE -- '[A-Z]+-[0-9]+')
LOCAL_DIRECTORY="public/storybook"

if [ ! "$BRANCH" ]
then
Expand All @@ -19,6 +20,20 @@ echo "I am building a storybook"
yarn storybook:build

echo "Deploying storybook to $BUCKET as $BRANCH"
s3cmd put -r -P public/storybook/* s3://$BUCKET/$BRANCH/
s3cmd put -r -P $LOCAL_DIRECTORY/* s3://$BUCKET/$BRANCH/

echo "Setting Content-Type to application/javascript for all .js files"
find "$LOCAL_DIRECTORY" -type f -name "*.js" | while read FILE; do
RELATIVE_PATH="${FILE#"$LOCAL_DIRECTORY/"}"
echo "s3://$BUCKET/$BRANCH/$RELATIVE_PATH"
s3cmd modify --add-header="Content-Type: application/javascript" s3://$BUCKET/$BRANCH/$RELATIVE_PATH
done

echo "Setting Content-Type to text/css for all .css files"
find "$LOCAL_DIRECTORY" -type f -name "*.css" | while read FILE; do
RELATIVE_PATH="${FILE#"$LOCAL_DIRECTORY/"}"
echo "s3://$BUCKET/$BRANCH/$RELATIVE_PATH"
s3cmd modify --add-header="Content-Type: text/css" s3://$BUCKET/$BRANCH/$RELATIVE_PATH
done
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are so many assets and it takes so long... I hope we find a better solution soon.


echo "Your storybook is available on: https://$BUCKET.s3.amazonaws.com/$BRANCH/index.html"
25 changes: 14 additions & 11 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,28 @@
module.exports = {
export default {
verbose: true,
preset: '@vue/cli-plugin-unit-jest/presets/typescript',
testEnvironment: 'jsdom',
preset: 'ts-jest',
testEnvironment: 'jest-environment-jsdom',
moduleNameMapper: {
'^design-system/lib/(.*)$': '<rootDir>/lib/$1',
'^design-system/styles/(.*)$': '<rootDir>/lib/styles/$1',
'^design-system/images/(.*)$': '<rootDir>/lib/images/$1',
'^vue-popperjs/dist/vue-popper.css': '<rootDir>/lib/js/tests/emptyModule.ts',
'^vue-popperjs/dist/vue-popper.css': '<rootDir>/lib/js/tests/emptyModule.cjs',
},
testMatch: ['<rootDir>/lib/js/**/*.spec.ts', '<rootDir>/tools/importers/*.spec.ts'],
transform: {
'^.+\\.js$': 'babel-jest',
'^.+\\.ts$': 'ts-jest',
'.*\\.(vue)$': '@vue/vue3-jest',
'^.+\\.scss': '<rootDir>/lib/js/tests/emptyTransformer.ts',
'^.+\\.svg$': '<rootDir>/lib/js/tests/emptyTransformer.ts',
'^.+\\.scss': '<rootDir>/lib/js/tests/emptyTransformer.cjs',
'^.+\\.svg$': '<rootDir>/lib/js/tests/emptyTransformer.cjs',
},
moduleFileExtensions: ['js', 'vue', 'json', 'ts'],

moduleFileExtensions: ['js', 'mjs', 'ts', 'json', 'vue'],
setupFilesAfterEnv: ['<rootDir>/lib/js/typings.d.ts', '<rootDir>/lib/js/tests/globals.ts'],
testEnvironmentOptions: {
customExportConditions: ['node', 'node-addons'],
},
globals: {
'vue-jest': {
compilerOptions: {
whitespace: 'preserve',
},
},
},
};
Loading
Loading