Skip to content

Commit

Permalink
Merge pull request #7109 from Sage/dotenvx
Browse files Browse the repository at this point in the history
build: use dotenvx to customise storybook setup depending on runtime environment
  • Loading branch information
Parsium authored Dec 13, 2024
2 parents 7158549 + 9818944 commit 844523f
Show file tree
Hide file tree
Showing 15 changed files with 425 additions and 190 deletions.
6 changes: 4 additions & 2 deletions .env
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
STORYBOOK_DEBUG_THEME="true"
STORYBOOK_BUILD="true"
STORYBOOK_BUILD=true
USE_VERSION_PICKER=false
IGNORE_TESTS=false
STORYBOOK_VIEW_MODE=docs
4 changes: 4 additions & 0 deletions .env.production
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
STORYBOOK_BUILD=true
USE_VERSION_PICKER=true
IGNORE_TESTS=true
STORYBOOK_VIEW_MODE=docs
2 changes: 1 addition & 1 deletion .github/workflows/semantic-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ jobs:
- run: npm ci
- name: Generate metadata file
run: npm run generate-metadata
- run: NODE_ENV=production IGNORE_TESTS=true STORYBOOK_VIEW_MODE=docs npm run build-storybook
- run: npm run build-storybook:prod
- uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/storybook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
with:
node-version: ">=20.9.0 20"
- run: npm ci
- run: NODE_ENV=production IGNORE_TESTS=true STORYBOOK_VIEW_MODE=docs npm run build-storybook
- run: npm run build-storybook:prod
- uses: aws-actions/configure-aws-credentials@v2
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
Expand Down
2 changes: 1 addition & 1 deletion .storybook/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ const config: StorybookConfig = {
},
"@storybook/addon-toolbars",
"@storybook/addon-viewport",
"@storybook/addon-webpack5-compiler-swc",
"@chromatic-com/storybook",
"@storybook/addon-webpack5-compiler-babel",
],

staticDirs: ["../.assets", "../logo"],
Expand Down
6 changes: 4 additions & 2 deletions .storybook/manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import { ADDON_ID, TOOL_ID } from "./version-picker/constants";
import { VersionPicker } from "./version-picker";
import { API_PreparedIndexEntry, API_StatusObject } from "@storybook/types";

if (process.env.NODE_ENV === "production") {
const useVersionPicker = process.env.USE_VERSION_PICKER === "true";

if (useVersionPicker) {
addons.register(ADDON_ID, () => {
addons.add(TOOL_ID, {
type: types.TOOL,
Expand All @@ -23,7 +25,7 @@ addons.setConfig({
patterns: (
item: API_PreparedIndexEntry & {
status: Record<string, API_StatusObject | null>;
}
},
): boolean => {
return !(item.tags ?? []).includes("hideInSidebar");
},
Expand Down
5 changes: 0 additions & 5 deletions .storybook/withThemeProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import isChromatic from "./isChromatic";
import React from "react";
import styled from "styled-components";
import CarbonProvider from "../src/components/carbon-provider";
import sageDebugTheme from "../src/style/design-tokens/debug-theme.util";
import { noTheme, sageTheme } from "../src/style/themes";
import { config } from "react-transition-group";

Expand All @@ -12,10 +11,6 @@ const themes = [noTheme, sageTheme].reduce((themesObject, theme) => {
return themesObject;
}, {});

if (!isChromatic() && process.env.STORYBOOK_DEBUG_THEME === "true") {
themes["sage-debug"] = sageDebugTheme;
}

const render = (
Story,
themeName,
Expand Down
Loading

0 comments on commit 844523f

Please sign in to comment.