mirror of
https://github.com/ksyasuda/SubMiner.git
synced 2026-03-30 18:12:08 -07:00
refactor: deduplicate ensureDir into shared/fs-utils
5 copies of mkdir-p-if-not-exists consolidated into one shared module with ensureDir (directory path) and ensureDirForFile (file path) variants.
This commit is contained in:
@@ -1,6 +1 @@
|
||||
import * as fs from 'fs';
|
||||
|
||||
export function ensureDir(dirPath: string): void {
|
||||
if (fs.existsSync(dirPath)) return;
|
||||
fs.mkdirSync(dirPath, { recursive: true });
|
||||
}
|
||||
export { ensureDir } from '../../shared/fs-utils';
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
import { ensureDir } from '../../shared/fs-utils';
|
||||
import type { AnilistCharacterDictionaryProfileScope } from '../../types';
|
||||
import type {
|
||||
CharacterDictionarySnapshotProgressCallbacks,
|
||||
@@ -63,12 +64,6 @@ export interface CharacterDictionaryAutoSyncRuntimeDeps {
|
||||
onSyncComplete?: (result: { mediaId: number; mediaTitle: string; changed: boolean }) => void;
|
||||
}
|
||||
|
||||
function ensureDir(dirPath: string): void {
|
||||
if (!fs.existsSync(dirPath)) {
|
||||
fs.mkdirSync(dirPath, { recursive: true });
|
||||
}
|
||||
}
|
||||
|
||||
function normalizeMediaId(rawMediaId: number): number | null {
|
||||
const mediaId = Math.max(1, Math.floor(rawMediaId));
|
||||
return Number.isFinite(mediaId) ? mediaId : null;
|
||||
|
||||
Reference in New Issue
Block a user