From 7a2e951474367e23f3f9bffe57c6e7c85bb9fff8 Mon Sep 17 00:00:00 2001 From: Joel Date: Thu, 13 Nov 2025 17:14:01 +0800 Subject: [PATCH] feat: support auto gen and support alias --- web/app/(commonLayout)/layout.tsx | 4 ++ web/app/edition/saas/sub/sub-c.css | 0 web/app/edition/saas/sub/sub-sub/index.tsx | 12 ++++++ web/app/edition/saas/sub/sub-sub/sss.tsx | 0 web/app/edition/saas/sub/sub.ts | 0 web/next.config.js | 49 ++++++++++++++++++---- web/tsconfig.json | 3 +- 7 files changed, 58 insertions(+), 10 deletions(-) create mode 100644 web/app/edition/saas/sub/sub-c.css create mode 100644 web/app/edition/saas/sub/sub-sub/index.tsx create mode 100644 web/app/edition/saas/sub/sub-sub/sss.tsx create mode 100644 web/app/edition/saas/sub/sub.ts diff --git a/web/app/(commonLayout)/layout.tsx b/web/app/(commonLayout)/layout.tsx index e30b08acb5..4eebf33a80 100644 --- a/web/app/(commonLayout)/layout.tsx +++ b/web/app/(commonLayout)/layout.tsx @@ -12,6 +12,8 @@ import GotoAnything from '@/app/components/goto-anything' import Zendesk from '@/app/components/base/zendesk' import Splash from '../components/splash' import Test from '@edition/test' +import SubSubIndex from '@edition/sub/sub-sub/index' +import SubSub from '@edition/sub/sub-sub' const Layout = ({ children }: { children: ReactNode }) => { return ( @@ -23,6 +25,8 @@ const Layout = ({ children }: { children: ReactNode }) => { + +
diff --git a/web/app/edition/saas/sub/sub-c.css b/web/app/edition/saas/sub/sub-c.css new file mode 100644 index 0000000000..e69de29bb2 diff --git a/web/app/edition/saas/sub/sub-sub/index.tsx b/web/app/edition/saas/sub/sub-sub/index.tsx new file mode 100644 index 0000000000..f97c8e3204 --- /dev/null +++ b/web/app/edition/saas/sub/sub-sub/index.tsx @@ -0,0 +1,12 @@ +'use client' +import type { FC } from 'react' +import React from 'react' + +const SubSub: FC = () => { + return ( +
+ Sub Sub +
+ ) +} +export default React.memo(SubSub) diff --git a/web/app/edition/saas/sub/sub-sub/sss.tsx b/web/app/edition/saas/sub/sub-sub/sss.tsx new file mode 100644 index 0000000000..e69de29bb2 diff --git a/web/app/edition/saas/sub/sub.ts b/web/app/edition/saas/sub/sub.ts new file mode 100644 index 0000000000..e69de29bb2 diff --git a/web/next.config.js b/web/next.config.js index 6c4dff7f2e..e3cc33a398 100644 --- a/web/next.config.js +++ b/web/next.config.js @@ -1,4 +1,5 @@ const { codeInspectorPlugin } = require('code-inspector-plugin') +const fs = require('fs') const path = require('path') const withPWA = require('next-pwa')({ dest: 'public', @@ -88,12 +89,42 @@ const hasSetWebPrefix = process.env.NEXT_PUBLIC_WEB_PREFIX const port = process.env.PORT || 3000 const locImageURLs = !hasSetWebPrefix ? [new URL(`http://localhost:${port}/**`), new URL(`http://127.0.0.1:${port}/**`)] : [] const remoteImageURLs = [hasSetWebPrefix ? new URL(`${process.env.NEXT_PUBLIC_WEB_PREFIX}/**`) : '', ...locImageURLs].filter(item => !!item) -const editionPath = - process.env.NEXT_PUBLIC_EDITION === 'CLOUD' - ? './app/edition/saas/test.tsx' - : './app/edition/community/test.tsx' -path.resolve(__dirname, editionPath, '*') -console.log(editionPath) + +const isSaaS = process.env.NEXT_PUBLIC_EDITION === 'CLOUD' +const supportPostfixReg = /\.(ts|tsx|css|svg|jpg|jpeg|png)$/ +const editionPaths = (() => { + const editionDir = `./app/edition/${isSaaS ? 'saas' : 'community'}` + + const result = {} + + function walk(dir) { + const files = fs.readdirSync(dir) + for (const file of files) { + const fullPath = path.join(dir, file) + const stat = fs.statSync(fullPath) + if (stat.isDirectory()) { + walk(fullPath) + } else if (supportPostfixReg.test(file)) { + const relPath = path.relative(editionDir, fullPath) + const key = `@edition/${relPath.replace(/\\/g, '/')}`.replace(/\.(ts|tsx|css)$/, '') + const fullPathWithoutPrefix = `./${fullPath.replace(supportPostfixReg, '')}` + result[key] = fullPathWithoutPrefix + if (key.endsWith('/index')) { + const dirKey = key.replace(/\/index$/, '') + result[dirKey] = fullPathWithoutPrefix + } + } + } + } + + if (fs.existsSync(editionDir)) { + walk(editionDir) + } + + return result +})() + +console.log(JSON.stringify(editionPaths, null, 2)) /** @type {import('next').NextConfig} */ const nextConfig = { @@ -103,9 +134,9 @@ const nextConfig = { rules: codeInspectorPlugin({ bundler: 'turbopack' }), - // resolveAlias: { - // '@edition/test': editionPath, - // } + resolveAlias: { + ...editionPaths, + } }, productionBrowserSourceMaps: false, // enable browser source map generation during the production build // Configure pageExtensions to include md and mdx diff --git a/web/tsconfig.json b/web/tsconfig.json index 0a30ff596e..7ce35e88b7 100644 --- a/web/tsconfig.json +++ b/web/tsconfig.json @@ -31,7 +31,8 @@ "./*" ], "@edition/*": [ - "./app/edition/community/*" + "./app/edition/saas/*", + "./app/edition/community/*", ] } },