Skip to content

Commit

Permalink
feat: reorganize folders (#45)
Browse files Browse the repository at this point in the history
* chore: installed vite dependencies and removed tsup

* chore: reorganize folders and fix build
  • Loading branch information
hussedev authored Oct 8, 2024
1 parent 01b45e7 commit 828861c
Show file tree
Hide file tree
Showing 158 changed files with 21,042 additions and 13,030 deletions.
39 changes: 0 additions & 39 deletions .eslintrc.js

This file was deleted.

39 changes: 39 additions & 0 deletions .github/workflows/storybook-tests-after-deployment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Storybook Tests After Deployment
on: deployment_status # deployment_status is triggered when a deployment is created or updated, for example on vercel, and you can get the URL from there
jobs:
test:
timeout-minutes: 60
runs-on: ubuntu-latest
if: github.event.deployment_status.state == 'success'
steps:
- uses: actions/checkout@v4

- name: Install pnpm
uses: pnpm/action-setup@v4
with:
version: 9
run_install: false

- uses: actions/setup-node@v4
with:
node-version-file: ".nvmrc"
cache: "pnpm"

- name: Install dependencies
run: pnpm install

- name: Cache Playwright browsers
uses: actions/cache@v4
with:
path: ~/.cache/ms-playwright
key: ${{ runner.os }}-playwright-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-playwright-
- name: Install Playwright
run: npx playwright install --with-deps

- name: Run Storybook tests
run: pnpm test
env:
TARGET_URL: "${{ github.event.deployment_status.target_url }}"
50 changes: 50 additions & 0 deletions .github/workflows/storybook-tests-on-push.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: "Storybook Tests"
on: push
jobs:
test:
timeout-minutes: 60
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Install pnpm
uses: pnpm/action-setup@v4
with:
version: 9
run_install: false

- uses: actions/setup-node@v4
with:
node-version-file: ".nvmrc"
cache: "pnpm"

- name: Install dependencies
run: pnpm install

- name: Cache Playwright browsers
uses: actions/cache@v4
with:
path: ~/.cache/ms-playwright
key: ${{ runner.os }}-playwright-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-playwright-
- name: Install Playwright
run: npx playwright install --with-deps

- name: Cache Storybook build
uses: actions/cache@v4
with:
path: storybook-static
key: ${{ runner.os }}-storybook-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-storybook-
- name: Build Storybook
run: pnpm build-storybook --quiet

- name: Serve Storybook and run tests
run: |
npx concurrently -k -s first -n "SB,TEST" -c "magenta,blue" \
"npx http-server storybook-static --port 6006 --silent" \
"npx wait-on tcp:127.0.0.1:6006 && pnpm test-storybook"
1 change: 1 addition & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pnpm exec lint-staged
3 changes: 1 addition & 2 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
auto-install-peers = true
public-hoist-pattern[]=*storybook*
package-manager=pnpm@9
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
20
8 changes: 8 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"useTabs": false,
"singleQuote": false,
"trailingComma": "all",
"semi": true,
"printWidth": 100,
"plugins": ["prettier-plugin-tailwindcss"]
}
36 changes: 12 additions & 24 deletions .storybook/main.ts
Original file line number Diff line number Diff line change
@@ -1,34 +1,22 @@
import type { StorybookConfig } from "@storybook/react-vite";

import { join, dirname } from "path";

/**
* This function is used to resolve the absolute path of a package.
* It is needed in projects that use Yarn PnP or are set up within a monorepo.
*/
function getAbsolutePath(value: string): any {
return dirname(require.resolve(join(value, "package.json")));
}
const config: StorybookConfig = {
// stories: ["../stories/*.stories.tsx", "../stories/**/*.stories.tsx"],

stories: [
"../stories/*.stories.tsx",
"../stories/**/*.stories.tsx",
"../src/**/*.mdx",
"../src/**/*.stories.@(js|jsx|mjs|ts|tsx)",
],
stories: ["../src/**/*.mdx", "../src/**/*.stories.@(js|jsx|mjs|ts|tsx)"],
addons: [
getAbsolutePath("@storybook/addon-themes"),
getAbsolutePath("@storybook/addon-links"),
getAbsolutePath("@storybook/addon-essentials"),
getAbsolutePath("@chromatic-com/storybook"),
getAbsolutePath("@storybook/addon-interactions"),
"@storybook/addon-links",
"@storybook/addon-essentials",
"@chromatic-com/storybook",
"@storybook/addon-interactions",
"@storybook/addon-themes",
"@storybook/addon-a11y",
],
framework: {
name: getAbsolutePath("@storybook/react-vite"),
name: "@storybook/react-vite",
options: {},
},
staticDirs: ["../public"],
docs: {},
core: {
disableTelemetry: true, // 👈 Used to ignore update notifications.
},
};
export default config;
12 changes: 0 additions & 12 deletions .storybook/preview-head.html

This file was deleted.

37 changes: 21 additions & 16 deletions .storybook/preview.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import React from "react";
import type { Preview } from "@storybook/react";
import { withThemeByDataAttribute } from "@storybook/addon-themes";
import { initialize, mswLoader } from "msw-storybook-addon";
import { handlers } from "../src/mocks/handlers";

initialize();

import "../src/styles.css";

import { ApiProvider, Web3Provider } from "../src";
Expand All @@ -12,25 +18,17 @@ const preview: Preview = {
date: /Date$/i,
},
},
options: {
storySort: {
method: "",
order: ["UI"],
locales: "",
},
msw: {
handlers,
},
// We can use MSW to mock data fetching
// msw: {
// handlers: [
// graphql.query("Rounds", ({}) => {
// return HttpResponse.json({ data: { rounds } });
// }),
// ],
// },
},
// loaders: [mswLoader],

loaders: [mswLoader],
decorators: [
withThemeByDataAttribute({
defaultTheme: "light",
themes: { light: "light", dark: "dark" },
attributeName: "data-mode",
}),
(Story, { parameters: { theme = "light" } }) => {
return (
<ApiProvider>
Expand All @@ -43,4 +41,11 @@ const preview: Preview = {
],
};

// NOTE: Example of global loaders
// export const loaders = [
// async () => ({
// userData: await fetch('/api/user').then((res) => res.json()),
// }),
// ];

export default preview;
18 changes: 18 additions & 0 deletions .storybook/test-runner.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import type { TestRunnerConfig } from "@storybook/test-runner";
import { injectAxe, checkA11y } from "axe-playwright";

const config: TestRunnerConfig = {
async preVisit(page) {
await injectAxe(page);
},
async postVisit(page) {
await checkA11y(page, "#storybook-root", {
detailedReport: true,
detailedReportOptions: {
html: true,
},
});
},
};

export default config;
5 changes: 5 additions & 0 deletions chromatic.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"onlyChanged": true,
"projectId": "add project",
"zip": true
}
25 changes: 25 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import js from "@eslint/js";
import globals from "globals";
import reactHooks from "eslint-plugin-react-hooks";
import reactRefresh from "eslint-plugin-react-refresh";
import tseslint from "typescript-eslint";

export default tseslint.config(
{ ignores: ["dist"] },
{
extends: [js.configs.recommended, ...tseslint.configs.recommended],
files: ["**/*.{ts,tsx}"],
languageOptions: {
ecmaVersion: 2020,
globals: globals.browser,
},
plugins: {
"react-hooks": reactHooks,
"react-refresh": reactRefresh,
},
rules: {
...reactHooks.configs.recommended.rules,
"react-refresh/only-export-components": ["warn", { allowConstantExport: true }],
},
},
);
26 changes: 21 additions & 5 deletions fix-mjs-imports.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,21 @@ const path = require("path");

// Function to read file contents
function readFileContents(filePath) {
return fs.readFileSync(filePath, "utf8");
try {
return fs.readFileSync(filePath, "utf8");
} catch (error) {
console.error(`Error reading file ${filePath}:`, error);
return null;
}
}

// Function to write updated contents back to the file
function writeFileContents(filePath, contents) {
fs.writeFileSync(filePath, contents, "utf8");
try {
fs.writeFileSync(filePath, contents, "utf8");
} catch (error) {
console.error(`Error writing file ${filePath}:`, error);
}
}

// Function to resolve the full path of the import
Expand Down Expand Up @@ -67,9 +76,13 @@ function updateImportStatement(fromKeyword, importPath, quote, filePath) {
const fullPath = resolveFullPath(filePath, importPath);

if (importPath === ".." || importPath === "." || isDirectory(fullPath)) {
return updateDirectoryOrDotImport(fromKeyword, importPath, quote, fullPath);
const updatedImport = updateDirectoryOrDotImport(fromKeyword, importPath, quote, fullPath);

return updatedImport;
} else if (!importPath.endsWith(".mjs")) {
return updateFileImport(fromKeyword, importPath, quote, fullPath);
const updatedImport = updateFileImport(fromKeyword, importPath, quote, fullPath);

return updatedImport;
}

return `${fromKeyword}${importPath}${quote}`;
Expand All @@ -78,12 +91,15 @@ function updateImportStatement(fromKeyword, importPath, quote, filePath) {
// Main function to update imports in .mjs files
function updateImports(filePath) {
const contents = readFileContents(filePath);
if (!contents) {
return;
}

const updatedContents = contents.replace(
/(from\s+['"])(\.\.?\/[^'"\s]+|\.|..|posthog-js\/react|@allo-team\/allo-v2-sdk\/dist\/Allo\/allo.config)(['"])/g,
(match, fromKeyword, importPath, quote) => {
return updateImportStatement(fromKeyword, importPath, quote, filePath);
}
},
);

if (contents !== updatedContents) {
Expand Down
Loading

0 comments on commit 828861c

Please sign in to comment.