chore: sync with upstream e7cb442 + update zh translations

This commit is contained in:
xuxiang
2026-02-02 18:57:56 +08:00
parent 6f87d43c19
commit d7cafbe582
66 changed files with 9395 additions and 1465 deletions

View File

@@ -0,0 +1,24 @@
import { mkdirSync, readFileSync, writeFileSync, existsSync } from 'fs';
import { dirname, resolve, sep } from 'path';
export function ensureDir(path: string): void {
mkdirSync(path, { recursive: true });
}
export function readJsonFile<T>(path: string): T | null {
if (!existsSync(path)) return null;
const content = readFileSync(path, 'utf-8');
return JSON.parse(content) as T;
}
export function writeJsonFile(path: string, data: unknown): void {
ensureDir(dirname(path));
writeFileSync(path, JSON.stringify(data, null, 2) + '\n', 'utf-8');
}
export function isPathInside(targetPath: string, baseDir: string): boolean {
const resolvedTarget = resolve(targetPath);
const resolvedBase = resolve(baseDir);
const baseWithSep = resolvedBase.endsWith(sep) ? resolvedBase : resolvedBase + sep;
return resolvedTarget === resolvedBase || resolvedTarget.startsWith(baseWithSep);
}