mirror of
https://github.com/sweetwisdom/everything-claude-code-zh.git
synced 2026-03-22 06:20:10 +00:00
chore: sync with upstream e7cb442 + update zh translations
This commit is contained in:
24
.claude/skills/oneskill/src/core/fs.ts
Normal file
24
.claude/skills/oneskill/src/core/fs.ts
Normal 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);
|
||||
}
|
||||
Reference in New Issue
Block a user