mirror of
https://github.com/lobehub/lobehub.git
synced 2026-03-26 13:19:34 +07:00
* v2 init * chore: update eslint suppressions and package dependencies - Removed several eslint suppressions related to array sorting and reversing from eslint-suppressions.json to clean up the configuration. - Updated @lobehub/lint package version from 2.0.0-beta.6 to 2.0.0-beta.7 in package.json for improvements and bug fixes. - Made minor formatting adjustments in vitest.config.mts and various SKILL.md files for better readability and consistency. Signed-off-by: Innei <tukon479@gmail.com> * fix: clean up import statements and formatting - Removed unnecessary whitespace in replaceComponentImports.ts for improved readability. - Standardized import statements in contextEngineering.ts and createAgentExecutors.ts by adding missing spaces for consistency. Signed-off-by: Innei <tukon479@gmail.com> * chore: update eslint suppressions and clean up code formatting * 🐛 fix: use vi.hoisted for mock variable initialization Fix TDZ error in persona service test by using vi.hoisted() to ensure mock variables are available when vi.mock factory runs. --------- Signed-off-by: Innei <tukon479@gmail.com>
68 lines
2.2 KiB
TypeScript
68 lines
2.2 KiB
TypeScript
import { readFileSync, writeFileSync } from 'node:fs';
|
|
import { resolve } from 'node:path';
|
|
|
|
import prettier from '@prettier/sync';
|
|
import { consola } from 'consola';
|
|
import { colors } from 'consola/utils';
|
|
|
|
import i18nConfig from './i18nConfig';
|
|
|
|
const prettierOptions = prettier.resolveConfig(resolve(__dirname, '../../.prettierrc.js'));
|
|
|
|
export const readJSON = (filePath: string) => {
|
|
const data = readFileSync(filePath, 'utf8');
|
|
return JSON.parse(data);
|
|
};
|
|
|
|
export const writeJSON = (filePath: string, data: any) => {
|
|
const jsonStr = JSON.stringify(data, null, 2);
|
|
writeFileSync(filePath, jsonStr, 'utf8');
|
|
};
|
|
|
|
export const writeJSONWithPrettier = (filePath: string, data: any) => {
|
|
const jsonStr = JSON.stringify(data, null, 2);
|
|
const formatted = prettier.format(jsonStr, {
|
|
...prettierOptions,
|
|
parser: 'json',
|
|
});
|
|
writeFileSync(filePath, formatted, 'utf8');
|
|
};
|
|
|
|
export const genResourcesContent = (locales: string[]) => {
|
|
let index = '';
|
|
let indexObj = '';
|
|
|
|
for (const locale of locales) {
|
|
index += `import ${locale} from "./${locale}";\n`;
|
|
indexObj += ` "${locale.replace('_', '-')}": ${locale},\n`;
|
|
}
|
|
|
|
return `${index}
|
|
const resources = {
|
|
${indexObj}} as const;
|
|
export default resources;
|
|
export const defaultResources = ${i18nConfig.entryLocale};
|
|
export type Resources = typeof resources;
|
|
export type DefaultResources = typeof defaultResources;
|
|
export type Namespaces = keyof DefaultResources;
|
|
export type Locales = keyof Resources;
|
|
`;
|
|
};
|
|
|
|
export const genNamespaceList = (files: string[], locale: string) => {
|
|
return files.map((file) => ({
|
|
name: file.replace('.json', ''),
|
|
path: resolve(i18nConfig.output, locale, file),
|
|
}));
|
|
};
|
|
|
|
export const tagBlue = (text: string) => colors.bgBlueBright(colors.black(` ${text} `));
|
|
export const tagYellow = (text: string) => colors.bgYellowBright(colors.black(` ${text} `));
|
|
export const tagGreen = (text: string) => colors.bgGreenBright(colors.black(` ${text} `));
|
|
export const tagWhite = (text: string) => colors.bgWhiteBright(colors.black(` ${text} `));
|
|
|
|
export const split = (name: string) => {
|
|
consola.log('');
|
|
consola.log(colors.gray(`========================== ${name} ==============================`));
|
|
};
|