Skip to content

Build your own AI office with Univer Office SDK. Bring editing, calculation, collaboration, and file processing into your product for people and AI agents. Built on an extensible open-source core.

chore(storybook): implement dynamic story sourcing based on package directories

白熱a77b78bca5b3
diff --git a/common/storybook/.storybook/main.ts b/common/storybook/.storybook/main.ts
index e12792c4ee..48a14e4204 100644
--- a/common/storybook/.storybook/main.ts
+++ b/common/storybook/.storybook/main.ts
@@ -15,7 +15,9 @@
*/
import { resolve } from 'node:path';
+import { existsSync, readdirSync } from 'node:fs';
import type { StorybookConfig } from '@storybook/react-webpack5';
+import type { StoriesEntry } from '@storybook/types';
import TsconfigPathsPlugin from 'tsconfig-paths-webpack-plugin';
@@ -25,28 +27,32 @@ const tsconfigPathsPlugin = new TsconfigPathsPlugin({
});
const config: StorybookConfig = {
- stories: [
- {
- directory: '../../../packages/design/src',
- files: '**/*.stories.@(js|jsx|mjs|ts|tsx)',
- titlePrefix: 'Design',
- },
- {
- directory: '../../../packages/ui/src',
- files: '**/*.stories.@(js|jsx|mjs|ts|tsx)',
- titlePrefix: 'Base UI',
- },
- {
- directory: '../../../packages/sheets-numfmt/src',
- files: '**/*.stories.@(js|jsx|mjs|ts|tsx)',
- titlePrefix: 'Numfmt',
- },
- {
- directory: '../../../packages/find-replace/src',
- files: '**/*.stories.@(js|jsx|mjs|ts|tsx)',
- titlePrefix: 'Find & Replace',
- },
- ],
+ stories: async (): Promise<StoriesEntry[]> => {
+ const rootPaths = ['../../../packages'];
+ const isSubmodules = __dirname.includes('submodules');
+ if (isSubmodules) {
+ rootPaths.push('../../../../../packages');
+ }
+
+ const stories: StoriesEntry[] = [];
+ rootPaths.forEach((rootPath) => {
+ const rootDir = resolve(__dirname, rootPath);
+ if (existsSync(rootDir)) {
+ readdirSync(rootDir).forEach((pkg) => {
+ const pkgDir = resolve(rootDir, pkg);
+ if (existsSync(pkgDir)) {
+ stories.push({
+ directory: `${rootPath}/${pkg}/src`,
+ files: '**/*.stories.@(js|jsx|mjs|ts|tsx)',
+ titlePrefix: pkg,
+ });
+ }
+ });
+ }
+ });
+
+ return stories;
+ },
addons: [
'@storybook/addon-links',
'@storybook/addon-essentials',
diff --git a/common/storybook/package.json b/common/storybook/package.json
index 30ed23296b..a3e6f963c6 100644
--- a/common/storybook/package.json
+++ b/common/storybook/package.json
@@ -25,6 +25,7 @@
"@storybook/blocks": "8.0.0-rc.1",
"@storybook/react": "8.0.0-rc.1",
"@storybook/react-webpack5": "8.0.0-rc.1",
+ "@storybook/types": "^7.6.17",
"@univerjs/core": "workspace:*",
"@univerjs/design": "workspace:*",
"@univerjs/ui": "workspace:*",
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 83beaf3eaa..3e83e4c6b6 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -137,6 +137,9 @@ importers:
'@storybook/react-webpack5':
specifier: 8.0.0-rc.1
+ '@storybook/types':
+ specifier: ^7.6.17
+ version: 7.6.17
'@univerjs/core':
specifier: workspace:*
version: link:../../packages/core
@@ -4267,6 +4270,17 @@ packages:
- webpack-cli
dev: false
+ /@storybook/[email protected]:
+ resolution: {integrity: sha512-GFG40pzaSxk1hUr/J/TMqW5AFDDPUSu+HkeE/oqSWJbOodBOLJzHN6CReJS6y1DjYSZLNFt1jftPWZZInG/XUA==}
+ dependencies:
+ '@storybook/client-logger': 7.6.17
+ '@storybook/core-events': 7.6.17
+ '@storybook/global': 5.0.0
+ qs: 6.11.2
+ telejson: 7.2.0
+ tiny-invariant: 1.3.1
+ dev: false
+
/@storybook/[email protected]:
resolution: {integrity: sha512-RKAIVK7A1CgBAIALg3zp6KvVLwSv9FaCu2EWNH47krBD4gsaalzDcVa6PJrxqjRuPqmQLv1bkugOBhBKs1ZRyg==}
dependencies:
@@ -4327,6 +4341,12 @@ packages:
- utf-8-validate
dev: false
+ /@storybook/[email protected]:
+ resolution: {integrity: sha512-6WBYqixAXNAXlSaBWwgljWpAu10tPRBJrcFvx2gPUne58EeMM20Gi/iHYBz2kMCY+JLAgeIH7ZxInqwO8vDwiQ==}
+ dependencies:
+ '@storybook/global': 5.0.0
+ dev: false
+
/@storybook/[email protected]:
resolution: {integrity: sha512-YZ3F1LS8GVkdoE4HWIxtR854bR2gc45Qz30gNNwRAaiWmPEnPbcv2v8gCDIfvhn+dEiO0sBq6pO4rCS3ZgWW2w==}
dependencies:
@@ -4410,6 +4430,12 @@ packages:
- encoding
- supports-color
+ /@storybook/[email protected]:
+ resolution: {integrity: sha512-AriWMCm/k1cxlv10f+jZ1wavThTRpLaN3kY019kHWbYT9XgaSuLU67G7GPr3cGnJ6HuA6uhbzu8qtqVCd6OfXA==}
+ dependencies:
+ ts-dedent: 2.2.0
+ dev: false
+
/@storybook/[email protected]:
resolution: {integrity: sha512-IOgwjetxT+6YCze5ZWnXuR1uDuJOq54RfhHSXBgO8RFPM9eZ2NTggAEaFcge8gL01CfOusWEeF2Ebl2buwuTbQ==}
dependencies:
@@ -4773,6 +4799,15 @@ packages:
react-dom: 18.2.0([email protected])
dev: false
+ /@storybook/[email protected]:
+ resolution: {integrity: sha512-GRY0xEJQ0PrL7DY2qCNUdIfUOE0Gsue6N+GBJw9ku1IUDFLJRDOF+4Dx2BvYcVCPI5XPqdWKlEyZdMdKjiQN7Q==}
+ dependencies:
+ '@storybook/channels': 7.6.17
+ '@types/babel__core': 7.20.5
+ '@types/express': 4.17.21
+ file-system-cache: 2.3.0
+ dev: false
+
/@storybook/[email protected]:
resolution: {integrity: sha512-Sebh9Ju3UDSXFuk9gOZH22AP6gbs2Tk+fdjhx8GFhUWNJkvG2qY7Sgk51z9tDpMSnkoKLC/QXg0NXJUIPCgoEg==}
dependencies: