mirror of
https://github.com/lobehub/lobe-chat.git
synced 2026-06-14 03:30:19 +00:00
♻️ refactor: extract server into apps/server + root namespaces into packages (#14949)
* ♻️ refactor(server-deps): extract envs/trpc/config/locales/business-server into packages * ♻️ refactor: relocate src/server backend modules to apps/server package Rebuilt on current canary: git mv the 8 server subtrees (services, routers, modules, globalConfig, utils, runtimeConfig, workflows, featureFlags) into @lobechat/server, with @/server/* dual-path alias, database vitest aliases, and instrumentation import fixup. * 📝 docs(skills): update src/server path refs to apps/server/src after relocation
This commit is contained in:
@@ -63,10 +63,10 @@ function extractKeysFromObject(obj: any, namespace: string, prefix: string = '')
|
||||
}
|
||||
|
||||
/**
|
||||
* Load all i18n keys from src/locales/default
|
||||
* Load all i18n keys from packages/locales/src/default
|
||||
*/
|
||||
function loadAllI18nKeys(): I18nKey[] {
|
||||
const defaultLocalesPath = path.join(process.cwd(), 'src/locales/default');
|
||||
const defaultLocalesPath = path.join(process.cwd(), 'packages/locales/src/default');
|
||||
const allKeys: I18nKey[] = [];
|
||||
|
||||
// Get all TypeScript files except index.ts and ignored files
|
||||
@@ -255,7 +255,7 @@ async function findAllTranslationCalls(): Promise<Set<string>> {
|
||||
// e.g., t(`mcp.details.${var}.title`) -> "mcp.details." and ".title"
|
||||
// e.g., t(`${var}.title`) -> ".title"
|
||||
let prefix = '';
|
||||
let suffix = '';
|
||||
let suffix: string;
|
||||
|
||||
if (match[2] !== undefined) {
|
||||
// Pattern has both prefix and suffix: match[1] = prefix, match[2] = suffix
|
||||
@@ -346,7 +346,7 @@ function findUnusedKeys(allKeys: I18nKey[], usedKeys: Set<string>): UnusedKey[]
|
||||
if (isProtectedKey(keyInfo.namespace, keyInfo.key)) {
|
||||
protectedKeys.push({
|
||||
...keyInfo,
|
||||
filePath: `src/locales/default/${keyInfo.namespace}.ts`,
|
||||
filePath: `packages/locales/src/default/${keyInfo.namespace}.ts`,
|
||||
});
|
||||
continue;
|
||||
}
|
||||
@@ -363,7 +363,7 @@ function findUnusedKeys(allKeys: I18nKey[], usedKeys: Set<string>): UnusedKey[]
|
||||
if (matchesPrefix) {
|
||||
protectedKeys.push({
|
||||
...keyInfo,
|
||||
filePath: `src/locales/default/${keyInfo.namespace}.ts`,
|
||||
filePath: `packages/locales/src/default/${keyInfo.namespace}.ts`,
|
||||
});
|
||||
continue;
|
||||
}
|
||||
@@ -372,7 +372,7 @@ function findUnusedKeys(allKeys: I18nKey[], usedKeys: Set<string>): UnusedKey[]
|
||||
if (!usedKeys.has(keyInfo.fullKey)) {
|
||||
unused.push({
|
||||
...keyInfo,
|
||||
filePath: `src/locales/default/${keyInfo.namespace}.ts`,
|
||||
filePath: `packages/locales/src/default/${keyInfo.namespace}.ts`,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,7 +72,7 @@ function removeKeyFromObject(obj: any, keyPath: string): boolean {
|
||||
* Clean unused keys from TypeScript default locale files
|
||||
*/
|
||||
function cleanDefaultLocaleFiles(unusedKeys: UnusedKey[], dryRun: boolean = true) {
|
||||
const defaultLocalesPath = path.join(process.cwd(), 'src/locales/default');
|
||||
const defaultLocalesPath = path.join(process.cwd(), 'packages/locales/src/default');
|
||||
|
||||
// Get ignored namespace names from IGNORED_FILES (remove .ts extension)
|
||||
const ignoredNamespaces = new Set(IGNORED_FILES.map((f) => f.replace('.ts', '')));
|
||||
|
||||
@@ -8,7 +8,7 @@ export const localesDir = resolve(root, i18nConfig.output);
|
||||
export const localeDir = (locale: string) => resolve(localesDir, locale);
|
||||
export const localeDirJsonList = (locale: string) =>
|
||||
readdirSync(localeDir(locale)).filter((name) => name.includes('.json'));
|
||||
export const srcLocalesDir = resolve(root, './src/locales');
|
||||
export const srcLocalesDir = resolve(root, './packages/locales/src');
|
||||
export const entryLocaleJsonFilepath = (file: string) =>
|
||||
resolve(localesDir, i18nConfig.entryLocale, file);
|
||||
export const outputLocaleJsonFilepath = (locale: string, file: string) =>
|
||||
|
||||
@@ -6,7 +6,7 @@ import prettier from '@prettier/sync';
|
||||
import { consola } from 'consola';
|
||||
import { colors } from 'consola/utils';
|
||||
|
||||
import { toLodashPath } from '../../src/locales/utils';
|
||||
import { toLodashPath } from '../../packages/locales/src/utils';
|
||||
import { localeDir, localeDirJsonList, localesDir, srcDefaultLocales } from './const';
|
||||
|
||||
const prettierOptions = prettier.resolveConfig(resolve(__dirname, '../../.prettierrc.js')) ?? {};
|
||||
@@ -123,7 +123,7 @@ const flattenLocaleJsons = () => {
|
||||
};
|
||||
|
||||
const run = async () => {
|
||||
consola.start('Flattening src/locales/default...');
|
||||
consola.start('Flattening packages/locales/src/default...');
|
||||
await flattenDefaultLocales();
|
||||
|
||||
consola.start('Flattening locales JSON files...');
|
||||
|
||||
Reference in New Issue
Block a user