mirror of
https://github.com/lobehub/lobehub.git
synced 2026-03-28 13:39:28 +07:00
* 🔧 chore: Add writeJSONWithPrettier utility and update locale generation scripts * 🔧 chore: Implement genRemoveDiff utility for locale diff analysis and update workflow * chore: update script * chore: revert * 🔧 chore: Refactor genDiff to improve diff analysis and streamline locale processing
50 lines
1.4 KiB
TypeScript
50 lines
1.4 KiB
TypeScript
import { consola } from 'consola';
|
|
import { colors } from 'consola/utils';
|
|
import { diff } from 'just-diff';
|
|
import { unset } from 'lodash';
|
|
import { existsSync } from 'node:fs';
|
|
|
|
import {
|
|
entryLocaleJsonFilepath,
|
|
i18nConfig,
|
|
outputLocaleJsonFilepath,
|
|
srcDefaultLocales,
|
|
} from './const';
|
|
import { readJSON, tagWhite, writeJSONWithPrettier } from './utils';
|
|
|
|
export const genDiff = () => {
|
|
consola.start(`Remove diff analysis...`);
|
|
|
|
const resources = require(srcDefaultLocales);
|
|
const data = Object.entries(resources.default);
|
|
|
|
for (const [ns, devJSON] of data) {
|
|
const filepath = entryLocaleJsonFilepath(`${ns}.json`);
|
|
if (!existsSync(filepath)) continue;
|
|
const previousProdJSON = readJSON(filepath);
|
|
|
|
const diffResult = diff(previousProdJSON, devJSON as any);
|
|
if (diffResult.length === 0) {
|
|
consola.success(tagWhite(ns), colors.gray(filepath));
|
|
continue;
|
|
}
|
|
|
|
const clearLocals = [];
|
|
|
|
for (const locale of i18nConfig.outputLocales) {
|
|
const localeFilepath = outputLocaleJsonFilepath(locale, `${ns}.json`);
|
|
if (!existsSync(localeFilepath)) continue;
|
|
const localeJSON = readJSON(localeFilepath);
|
|
|
|
for (const item of diffResult) {
|
|
unset(localeJSON, item.path);
|
|
}
|
|
|
|
writeJSONWithPrettier(localeFilepath, localeJSON);
|
|
clearLocals.push(locale);
|
|
}
|
|
consola.info('clear', clearLocals);
|
|
consola.success(tagWhite(ns), colors.gray(filepath));
|
|
}
|
|
};
|