From cf837ee21c5aed6b31a533b8d6fbc302d9fee56d Mon Sep 17 00:00:00 2001 From: Aleksei Gurianov Date: Tue, 27 Jan 2026 01:28:56 +0300 Subject: [PATCH] feat: add configuration files and scripts for mise, enhance project setup and CI/CD workflows --- .config/mise/conf.d/aliases.toml | 2 + .config/mise/conf.d/config.toml | 5 ++ .config/mise/conf.d/local.toml | 9 +++ .config/mise/conf.d/tasks-build.toml | 58 ++++++++++++++ .config/mise/conf.d/tasks-dev.toml | 30 +++++++ .config/mise/conf.d/tasks-prepare.toml | 30 +++++++ .config/mise/conf.d/tasks-quality.toml | 39 ++++++++++ .config/mise/conf.d/tasks-test.toml | 30 +++++++ mise.toml => .config/mise/conf.d/tools.toml | 2 + .../{storybook-deploy.yml => deploy.yml} | 31 ++------ .github/workflows/test.yml | 24 ++---- .gitignore | 5 +- .storybook/main.ts | 12 +-- .storybook/preview.tsx | 10 ++- README.md | 78 ++----------------- bun.lock | 2 +- components.json | 10 +-- package.json | 25 +++--- panda.config.ts | 7 +- src/main.tsx | 2 +- tsconfig.app.json | 3 +- tsconfig.base.json | 7 +- tsconfig.node.json | 5 +- vite.config.ts | 11 ++- vitest.config.ts | 32 +++----- 25 files changed, 298 insertions(+), 171 deletions(-) create mode 100644 .config/mise/conf.d/aliases.toml create mode 100644 .config/mise/conf.d/config.toml create mode 100644 .config/mise/conf.d/local.toml create mode 100644 .config/mise/conf.d/tasks-build.toml create mode 100644 .config/mise/conf.d/tasks-dev.toml create mode 100644 .config/mise/conf.d/tasks-prepare.toml create mode 100644 .config/mise/conf.d/tasks-quality.toml create mode 100644 .config/mise/conf.d/tasks-test.toml rename mise.toml => .config/mise/conf.d/tools.toml (53%) rename .github/workflows/{storybook-deploy.yml => deploy.yml} (54%) diff --git a/.config/mise/conf.d/aliases.toml b/.config/mise/conf.d/aliases.toml new file mode 100644 index 0000000..2d42e18 --- /dev/null +++ b/.config/mise/conf.d/aliases.toml @@ -0,0 +1,2 @@ +[shell_alias] +mr = "mise run" diff --git a/.config/mise/conf.d/config.toml b/.config/mise/conf.d/config.toml new file mode 100644 index 0000000..b64355f --- /dev/null +++ b/.config/mise/conf.d/config.toml @@ -0,0 +1,5 @@ +[task_config] +dir = "{{ config_root }}" + +[env] +'_'.path = { path = "./node_modules/.bin" } diff --git a/.config/mise/conf.d/local.toml b/.config/mise/conf.d/local.toml new file mode 100644 index 0000000..8688dcb --- /dev/null +++ b/.config/mise/conf.d/local.toml @@ -0,0 +1,9 @@ +[env] +## This is the template that is copied to mise.local.toml for local overrides +## This copy is committed to VCS to provide an example of local overrides +## Update it whenever new env vars are added to the project that may need local overrides +# Local environment overrides +# Uncomment and modify the variables below as needed + +# VITE_PORT = 5173 +# STORYBOOK_PORT = 6006 diff --git a/.config/mise/conf.d/tasks-build.toml b/.config/mise/conf.d/tasks-build.toml new file mode 100644 index 0000000..0222eb0 --- /dev/null +++ b/.config/mise/conf.d/tasks-build.toml @@ -0,0 +1,58 @@ +[vars] +build_dir = ".var/dist" +webapp_out_dir = "{{ vars.build_dir }}/webapp" +storybook_out_dir = "{{ vars.build_dir }}/storybook" +gh_pages_out_dir = "{{ vars.build_dir }}/gh-pages" + +# exposing defaults to terminal so that +# direct commands can be run consistently with tasks +[env] +# asserted in vite.config.ts +WEBAPP_OUT_DIR = "{{ vars.webapp_out_dir }}" +WEBAPP_BASE_URL = "/" +# asserted in .storybook/main.ts +STORYBOOK_BASE_URL = "/" +# expected in .github/workflows/deploy.yml +GH_PAGES_OUT_DIR = "{{ vars.gh_pages_out_dir }}" + +[tasks."build:webapp:base"] +hide = true +usage = ''' +arg "" env="WEBAPP_OUT_DIR" default="{{ vars.webapp_out_dir }}" help="Output directory for the webapp build" +arg "" env="WEBAPP_BASE_URL" default="/" help="Base URL for the webapp" +''' +run = "WEBAPP_OUT_DIR=${usage_dir?} WEBAPP_BASE_URL=${usage_base?} vite build" + +[tasks."build:webapp"] +description = "Build Application" +run = "mise run build:webapp:base" +sources = ["src/**/*.{ts,tsx}", "index.html", "vite.config.ts"] +outputs = ["{{ vars.webapp_out_dir }}/**/*"] + +[tasks."build:storybook:base"] +hide = true +usage = ''' +arg "" env="STORYBOOK_OUT_DIR" default="{{ vars.storybook_out_dir }}" help="Output directory for the Storybook build" +arg "" env="STORYBOOK_BASE_URL" default="/" help="Base URL for the Storybook" +''' +run = "STORYBOOK_BASE_URL=${usage_base?} storybook build -o ${usage_dir?}" + +[tasks."build:storybook"] +description = "Build Storybook" +run = "mise run build:storybook:base" +sources = ["src/**/*.{ts,tsx,stories.tsx}", ".storybook/**/*"] +outputs = ["{{ vars.storybook_out_dir }}/**/*"] + +[tasks."build"] +description = "Run all build tasks" +run = [{ task = "build:webapp" }, { task = "build:storybook" }] + +[tasks."build:gh-pages"] +description = "Prepare deployment artifacts (combine builds for GitHub Pages)" +run = [ + "mise run build:webapp:base {{ vars.gh_pages_out_dir }} /modern-stack/", + "mise run build:storybook:base {{ vars.gh_pages_out_dir }}/storybook /modern-stack/storybook", +] +sources = ["src/**/*.{ts,tsx}", "index.html", "vite.config.ts", ".storybook/**/*"] +outputs = ["{{ vars.gh_pages_out_dir }}/**/*"] + diff --git a/.config/mise/conf.d/tasks-dev.toml b/.config/mise/conf.d/tasks-dev.toml new file mode 100644 index 0000000..85e6df8 --- /dev/null +++ b/.config/mise/conf.d/tasks-dev.toml @@ -0,0 +1,30 @@ +# Development tasks + +[vars] +vite_port = "5173" +storybook_port = "6006" + +[tasks.dev] +description = "Start Vite dev server" +usage = ''' +flag "-p --port " default="{{ vars.vite_port }}" help="Port for the Vite dev server" +arg "[rest]" help="Additional arguments to pass to Vite" +''' +run = "vite --port ${usage_port?} ${usage_rest}" + +[tasks.storybook] +description = "Start Storybook dev server" +alias = "sb" +usage = ''' +flag "-p --port " default="{{ vars.storybook_port }}" help="Port for the Storybook dev server" +''' +run = "storybook dev -p ${usage_port?}" + +[tasks.preview] +description = "Preview production build" +depends = ["build:webapp"] +run = "vite preview" + +[tasks.clean] +description = "Clean build artifacts and caches" +run = ["rm -rf .var", "rm -rf node_modules/.vite", "rm -rf coverage"] diff --git a/.config/mise/conf.d/tasks-prepare.toml b/.config/mise/conf.d/tasks-prepare.toml new file mode 100644 index 0000000..bb1ff67 --- /dev/null +++ b/.config/mise/conf.d/tasks-prepare.toml @@ -0,0 +1,30 @@ +[vars] +panda_outdir = "src/shared/styled-system" +panda_config = "panda.config.ts" + +[env] +PANDA_OUTDIR = "{{ vars.panda_outdir }}" + +[tasks."prepare:panda"] +description = "Run Panda code generation" +run = "panda codegen" + +sources = ["{{ vars.panda_config }}", "theme/**/*.ts", "components.json"] +outputs = ["{{ vars.panda_outdir }}/**/*"] + +[tasks."prepare:git-hooks"] +description = "Install Git hooks" +run = "lefthook install" +sources = ["lefthook.yml"] + +[tasks."prepare:local-overrides"] +description = "Setup local overrides file if not exists" +run = "if [ ! -f mise.local.toml ]; then sed '/^##/d' .config/mise/conf.d/local.toml > mise.local.toml; fi" + +[tasks.prepare] +description = "Prepare project" +run = [ + { task = "prepare:panda" }, + { task = "prepare:git-hooks" }, + { task = "prepare:local-overrides" }, +] diff --git a/.config/mise/conf.d/tasks-quality.toml b/.config/mise/conf.d/tasks-quality.toml new file mode 100644 index 0000000..ce16171 --- /dev/null +++ b/.config/mise/conf.d/tasks-quality.toml @@ -0,0 +1,39 @@ +# Code quality tasks + +[tasks.format] +description = "Format code with oxfmt" +alias = "fmt" +run = "oxfmt --write ." + +[tasks."format:check"] +description = "Check code formatting" +alias = "fmt:check" +run = "oxfmt --check ." + +[tasks.lint] +description = "Lint code with oxlint" +run = "oxlint ." + +[tasks.typecheck] +description = "Type check with TypeScript" +alias = "tc" +run = "tsc -b" +sources = ["src/**/*.{ts,tsx}", "tsconfig*.json"] + +[tasks.validate] +description = "Run all quality checks (format, lint, typecheck, test). Default validation task for LLMs" +run = [ # + { task = "prepare" }, + { task = "format" }, + { tasks = ["lint", "typecheck", "test:run"] }, +] + +[tasks.ci] +description = "Run all CI checks. No auto-fixes" +run = [ + { task = "format:check" }, + { task = "lint" }, + { task = "typecheck" }, + { task = "test:coverage" }, + { task = "build" }, +] diff --git a/.config/mise/conf.d/tasks-test.toml b/.config/mise/conf.d/tasks-test.toml new file mode 100644 index 0000000..8e5e389 --- /dev/null +++ b/.config/mise/conf.d/tasks-test.toml @@ -0,0 +1,30 @@ +# Testing tasks + +[vars] +test_timeout = "10000" +coverage_threshold_lines = "80" +coverage_threshold_functions = "80" +coverage_threshold_branches = "75" +coverage_threshold_statements = "80" + +[env] +TEST_TIMEOUT = "{{ vars.test_timeout }}" +COVERAGE_THRESHOLD_LINES = "{{ vars.coverage_threshold_lines }}" +COVERAGE_THRESHOLD_FUNCTIONS = "{{ vars.coverage_threshold_functions }}" +COVERAGE_THRESHOLD_BRANCHES = "{{ vars.coverage_threshold_branches }}" +COVERAGE_THRESHOLD_STATEMENTS = "{{ vars.coverage_threshold_statements }}" + +[tasks.test] +description = "Run tests in watch mode" +alias = "t" +run = "vitest" + +[tasks."test:run"] +description = "Run tests once" +alias = "tr" +run = "vitest run" + +[tasks."test:coverage"] +description = "Run tests with coverage" +alias = "tcov" +run = "vitest run --coverage" diff --git a/mise.toml b/.config/mise/conf.d/tools.toml similarity index 53% rename from mise.toml rename to .config/mise/conf.d/tools.toml index a15572d..60dbf4a 100644 --- a/mise.toml +++ b/.config/mise/conf.d/tools.toml @@ -1,3 +1,5 @@ +# Tool versions [tools] bun = "1.3.6" node = "lts" +jq = "latest" diff --git a/.github/workflows/storybook-deploy.yml b/.github/workflows/deploy.yml similarity index 54% rename from .github/workflows/storybook-deploy.yml rename to .github/workflows/deploy.yml index b02ff95..a56fdd7 100644 --- a/.github/workflows/storybook-deploy.yml +++ b/.github/workflows/deploy.yml @@ -18,10 +18,10 @@ jobs: steps: - name: Checkout code - uses: actions/checkout@v4 + uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1 - name: Setup mise - uses: jdx/mise-action@v2 + uses: jdx/mise-action@6d1e696aa24c1aa1bcc1adea0212707c71ab78a8 # v3.6.1 with: install: true cache: true @@ -29,30 +29,13 @@ jobs: - name: Install dependencies run: bun install --frozen-lockfile - - name: Run prepare script - run: bun run prepare - - - name: Build app - run: bun run build - - - name: Verify app build - run: test -f dist/index.html || exit 1 - - - name: Build Storybook - run: bun run build-storybook - - - name: Verify Storybook build - run: test -f storybook-static/index.html || exit 1 - - - name: Combine builds - run: | - mkdir -p dist/storybook - cp -r storybook-static/. dist/storybook/ + - name: Build artifacts + run: mise run build:gh-pages - name: Upload artifact - uses: actions/upload-pages-artifact@v3 + uses: actions/upload-pages-artifact@7b1f4a764d45c48632c6b24a0339c27f5614fb0b # v4.0.0 with: - path: ./dist + path: ${{ env.GH_PAGES_OUT_DIR }} deploy: needs: build @@ -69,4 +52,4 @@ jobs: steps: - name: Deploy to GitHub Pages id: deployment - uses: actions/deploy-pages@v4 + uses: actions/deploy-pages@d6db90164ac5ed86f2b6aed7e0febac5b3c0c03e # v4.0.5 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 287ec16..6f63c22 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -15,16 +15,16 @@ jobs: steps: - name: Checkout code - uses: actions/checkout@v4 + uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1 - name: Setup mise - uses: jdx/mise-action@v2 + uses: jdx/mise-action@6d1e696aa24c1aa1bcc1adea0212707c71ab78a8 # v3.6.1 with: install: true cache: true - name: Cache Bun dependencies - uses: actions/cache@v4 + uses: actions/cache@8b402f58fbc84540c8b491a91e594a4576fec3d7 # v5.0.2 with: path: | ~/.bun/install/cache @@ -39,25 +39,13 @@ jobs: - name: Install Playwright browsers run: bunx playwright install --with-deps chromium - - name: Run prepare script - run: bun run prepare - - - name: Type check - run: bun run typecheck - - - name: Format check - run: bun run format:check - - - name: Lint - run: bun run lint - - - name: Run Storybook tests - run: xvfb-run --auto-servernum -- bun run test:run --coverage + - name: Run CI checks + run: mise run ci env: CI: true - name: Upload coverage reports - uses: actions/upload-artifact@v4 + uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0 if: success() with: name: coverage-reports diff --git a/.gitignore b/.gitignore index 8a9d884..74725c8 100644 --- a/.gitignore +++ b/.gitignore @@ -21,10 +21,12 @@ report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json .env.test.local .env.production.local .env.local +mise.local.toml # caches .eslintcache .cache +.var *.tsbuildinfo # IntelliJ based IDEs @@ -36,9 +38,10 @@ report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json ## Panda styled-system styled-system-studio + +# Storybook *storybook.log storybook-static -docs # ralphex progress logs progress*.txt diff --git a/.storybook/main.ts b/.storybook/main.ts index 1bc033b..a708b9f 100644 --- a/.storybook/main.ts +++ b/.storybook/main.ts @@ -1,4 +1,8 @@ import { defineMain } from '@storybook/react-vite/node' +import assert from 'node:assert' + +const base = process.env['STORYBOOK_BASE_URL'] +assert(base, 'STORYBOOK_BASE_URL env var is not set') export default defineMain({ core: { disableTelemetry: true }, @@ -9,12 +13,8 @@ export default defineMain({ }, stories: ['../src/**/*.stories.@(js|jsx|mjs|ts|tsx)'], addons: ['@storybook/addon-vitest', '@storybook/addon-a11y', '@storybook/addon-docs'], - viteFinal: (config, { configType }) => { - if (process.env['CI'] === 'true' && configType === 'PRODUCTION') { - config.base = '/modern-stack/storybook/' - } else { - config.base = '/' - } + viteFinal: (config) => { + config.base = base return config }, }) diff --git a/.storybook/preview.tsx b/.storybook/preview.tsx index 73de6d5..5a29ec6 100644 --- a/.storybook/preview.tsx +++ b/.storybook/preview.tsx @@ -1,11 +1,14 @@ +import { context } from '@reatom/core' + import '../src/index.css' import '../src/reatom.init.ts' -import { context } from '@reatom/core' import { reatomContext } from '@reatom/react' import addonA11y from '@storybook/addon-a11y' import { definePreview } from '@storybook/react-vite' import { useMemo, type PropsWithChildren } from 'react' +import { css } from '#styled-system/css' + function ReatomDecorator({ children }: PropsWithChildren) { // Create fresh context once per story mount to prevent state pollution const frame = useMemo(() => context.start(), []) @@ -20,6 +23,11 @@ const preview = definePreview({ ), + (Story) => ( +
+ +
+ ), ], parameters: { controls: { diff --git a/README.md b/README.md index 79ab42c..a949dfe 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,10 @@ # modern-stack -A modern React application demonstrating best practices with Bun, React 19, Reatom state management, Panda CSS styling, and Storybook with Vitest integration. +A modern React application demonstrating opinionated setup with Bun, React 19, Reatom state management, Panda CSS styling, and Storybook with Vitest integration. ## Stack -- Runtime: Bun +- Package Manager: Bun - Framework: React 19 - State Management: Reatom - Styling: Panda CSS @@ -21,13 +21,7 @@ Install dependencies: bun install ``` -Run the prepare script to generate Panda CSS artifacts and install git hooks: - -```bash -bun run prepare -``` - -This will: +This will also run `prepare` script: - Generate Panda CSS styled-system - Install Lefthook git hooks for pre-commit checks @@ -42,60 +36,12 @@ bun run dev ## Live -- App: https://guria.github.io/modern-stack/ -- Storybook: https://guria.github.io/modern-stack/storybook/ - -Run Storybook for component development: - -```bash -bun run storybook -``` - -Build Storybook for deployment: - -```bash -bun run build-storybook -``` - -## Testing - -Run tests in watch mode: - -```bash -bun run test -``` - -Run tests once: +- [App](https://guria.github.io/modern-stack/) +- [Storybook](https://guria.github.io/modern-stack/storybook/) -```bash -bun run test:run -``` +## Validation loop -## Code Quality - -Format code: - -```bash -bun run format -``` - -Check formatting without modifications: - -```bash -bun run format:check -``` - -Lint code: - -```bash -bun run lint -``` - -Type check: - -```bash -bun run typecheck -``` +- `mise run validate` ## Git Hooks @@ -133,12 +79,4 @@ Automatically deploys to GitHub Pages on push to main: - Combines both into a single deployment (app at root, Storybook at /storybook) - Deploys to GitHub Pages with proper permissions and concurrency controls -Configuration: .github/workflows/storybook-deploy.yml - -Both workflows use: - -- Bun for fast package management and script execution -- Playwright with Chromium for browser testing -- Modern GitHub Actions (v4) with proper timeouts and artifact retention - -This project was created using Bun. [Bun](https://bun.com) is a fast all-in-one JavaScript runtime. +Configuration: .github/workflows/deploy.yml diff --git a/bun.lock b/bun.lock index b20e2a3..0575a59 100644 --- a/bun.lock +++ b/bun.lock @@ -34,7 +34,7 @@ "vitest": "^4.0.18", }, "peerDependencies": { - "typescript": "^5", + "typescript": "^5.8", }, }, }, diff --git a/components.json b/components.json index 61b1f83..d04c48b 100644 --- a/components.json +++ b/components.json @@ -5,11 +5,9 @@ "config": "panda.config.ts" }, "aliases": { - "components": "#shared/components", - "hooks": "#shared/hooks", - "lib": "#shared/lib", - "recipes": "#theme/recipes", - "theme": "#theme", - "ui": "#shared/components/ui" + "components": "src/shared/components", + "recipes": "theme/recipes", + "theme": "theme", + "ui": "src/shared/components/ui" } } diff --git a/package.json b/package.json index 0fa899c..7aa29ef 100644 --- a/package.json +++ b/package.json @@ -10,19 +10,18 @@ "#*": "./src/*" }, "scripts": { - "build": "vite build", - "build-storybook": "storybook build", - "dev": "vite", - "format": "oxfmt --write .", - "format:check": "oxfmt .", - "lint": "oxlint .", - "prepare": "panda codegen && lefthook install", - "preview": "vite preview", - "storybook": "storybook dev -p 6006", - "test": "vitest", - "test:coverage": "vitest run --coverage", - "test:run": "vitest run", - "typecheck": "tsc -b --noEmit" + "build": "mise run build:webapp", + "dev": "mise run dev", + "format": "mise run format", + "lint": "mise run lint", + "prepare": "mise run prepare", + "preview": "mise run preview", + "storybook": "mise run storybook", + "test": "mise run test", + "test:coverage": "mise run test:coverage", + "test:run": "mise run test:run", + "typecheck": "mise run typecheck", + "validate": "mise run validate" }, "dependencies": { "@ark-ui/react": "^5.30.0", diff --git a/panda.config.ts b/panda.config.ts index 32fdd1c..4ccd26d 100644 --- a/panda.config.ts +++ b/panda.config.ts @@ -1,4 +1,5 @@ import { defineConfig } from '@pandacss/dev' +import assert from 'node:assert' import { animationStyles } from '#theme/animation-styles.ts' import { green } from '#theme/colors/green.ts' @@ -16,6 +17,9 @@ import { durations } from '#theme/tokens/durations.ts' import { shadows } from '#theme/tokens/shadows.ts' import { zIndex } from '#theme/tokens/z-index.ts' +const outdir = process.env['PANDA_OUTDIR'] +assert(outdir, 'PANDA_OUTDIR env var is not set') + export default defineConfig({ jsxFramework: 'react', // Whether to use css reset @@ -107,8 +111,7 @@ export default defineConfig({ }, }, - // The output directory for your css system - outdir: 'src/shared/styled-system', + outdir: outdir, globalCss: globalCss, conditions: conditions, diff --git a/src/main.tsx b/src/main.tsx index 9e5a185..199f536 100644 --- a/src/main.tsx +++ b/src/main.tsx @@ -9,7 +9,7 @@ import { css } from '#styled-system/css' const root = document.getElementById('root') assert(root, 'Root element not found') -root.className = css({ colorPalette: 'orange' }) +root.classList.add(css({ colorPalette: 'orange' })) const rootFrame = context.start() if (import.meta.env['DEV']) { diff --git a/tsconfig.app.json b/tsconfig.app.json index 0baacb3..8a29505 100644 --- a/tsconfig.app.json +++ b/tsconfig.app.json @@ -11,7 +11,8 @@ "#.storybook/*": ["./.storybook/*"], "#styled-system/*": ["./src/shared/styled-system/*"], "#*": ["./src/*"] - } + }, + "tsBuildInfoFile": ".var/local/ts/app.tsbuildinfo" }, "include": ["src", ".storybook/**/*"] } diff --git a/tsconfig.base.json b/tsconfig.base.json index 5dbad14..c230657 100644 --- a/tsconfig.base.json +++ b/tsconfig.base.json @@ -23,6 +23,11 @@ "skipLibCheck": true, "forceConsistentCasingInFileNames": true, "erasableSyntaxOnly": true, - "baseUrl": "." + "baseUrl": ".", + "paths": { + "#styled-system/*": ["./src/shared/styled-system/*"], + "#theme/*": ["./theme/*"], + "#*": ["./src/*"] + } } } diff --git a/tsconfig.node.json b/tsconfig.node.json index 25b3215..6e4082a 100644 --- a/tsconfig.node.json +++ b/tsconfig.node.json @@ -4,7 +4,8 @@ "lib": ["ESNext"], "types": ["bun-types", "vitest/globals"], "allowImportingTsExtensions": true, - "composite": true + "composite": true, + "tsBuildInfoFile": ".var/local/ts/node.tsbuildinfo" }, - "include": ["vite.config.ts", "*.config.ts", ".storybook/main.ts", "panda.config.ts", "theme"] + "include": ["*.config.ts", ".storybook/main.ts", "theme"] } diff --git a/vite.config.ts b/vite.config.ts index 0e8e374..6fa8914 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -1,9 +1,14 @@ import react from '@vitejs/plugin-react' +import assert from 'node:assert' import { defineConfig } from 'vite' -const isCI = process.env['CI'] === 'true' +const outDir = process.env['WEBAPP_OUT_DIR'] +const base = process.env['WEBAPP_BASE_URL'] +assert(outDir, 'WEBAPP_OUT_DIR env var is not set') +assert(base, 'WEBAPP_BASE_URL env var is not set') -export default defineConfig(({ command }) => ({ +export default defineConfig(() => ({ + build: { outDir }, plugins: [react()], - base: command === 'build' && isCI ? '/modern-stack/' : '/', + base, })) diff --git a/vitest.config.ts b/vitest.config.ts index 034d2b0..6fc27a4 100644 --- a/vitest.config.ts +++ b/vitest.config.ts @@ -4,7 +4,13 @@ import path from 'node:path' import { fileURLToPath } from 'node:url' import { defineConfig } from 'vitest/config' -const isCI = process.env['CI'] === 'true' +const testTimeout = Number(process.env['TEST_TIMEOUT']) +const coverageThresholds = { + lines: Number(process.env['COVERAGE_THRESHOLD_LINES']), + branches: Number(process.env['COVERAGE_THRESHOLD_BRANCHES']), + functions: Number(process.env['COVERAGE_THRESHOLD_FUNCTIONS']), + statements: Number(process.env['COVERAGE_THRESHOLD_STATEMENTS']), +} // More info at: https://storybook.js.org/docs/next/writing-tests/integrations/vitest-addon export default defineConfig({ @@ -24,12 +30,7 @@ export default defineConfig({ 'src/shared/components/ui/**', 'src/main.tsx', ], - thresholds: { - lines: 80, - functions: 80, - branches: 75, - statements: 80, - }, + thresholds: coverageThresholds, }, projects: [ { @@ -43,24 +44,13 @@ export default defineConfig({ ], test: { name: 'storybook', - testTimeout: isCI ? 60000 : 10000, - hookTimeout: isCI ? 60000 : 10000, + testTimeout: testTimeout, + hookTimeout: testTimeout, browser: { enabled: true, headless: true, screenshotFailures: false, - provider: playwright({ - launchOptions: { - args: isCI - ? [ - '--no-sandbox', - '--disable-setuid-sandbox', - '--disable-dev-shm-usage', - '--disable-gpu', - ] - : [], - }, - }), + provider: playwright(), instances: [{ browser: 'chromium' }], }, },