mirror of
https://github.com/ksyasuda/SubMiner.git
synced 2026-04-10 04:19:25 -07:00
- Resolve J/Shift+J subtitle-cycle OSD text via track-list labels and property expansion - Add mpv proxy OSD runtime + regression coverage across IPC/main/runtime paths - Scope `make pretty` to maintained source files and add scoped Prettier script - Align release workflow with cache/install order and explicit TypeScript check - Clean up duplicate submodule entry and remove checked-in docs/plans artifacts
61 lines
1.7 KiB
TypeScript
61 lines
1.7 KiB
TypeScript
import * as fs from 'node:fs';
|
|
import * as path from 'node:path';
|
|
|
|
export interface YomitanExtensionPathOptions {
|
|
explicitPath?: string;
|
|
cwd?: string;
|
|
moduleDir?: string;
|
|
resourcesPath?: string;
|
|
userDataPath?: string;
|
|
}
|
|
|
|
function pushUnique(values: string[], candidate: string | null | undefined): void {
|
|
if (!candidate || values.includes(candidate)) {
|
|
return;
|
|
}
|
|
values.push(candidate);
|
|
}
|
|
|
|
export function getYomitanExtensionSearchPaths(
|
|
options: YomitanExtensionPathOptions = {},
|
|
): string[] {
|
|
const searchPaths: string[] = [];
|
|
|
|
pushUnique(searchPaths, options.explicitPath ? path.resolve(options.explicitPath) : null);
|
|
pushUnique(searchPaths, options.cwd ? path.resolve(options.cwd, 'build', 'yomitan') : null);
|
|
pushUnique(
|
|
searchPaths,
|
|
options.moduleDir
|
|
? path.resolve(options.moduleDir, '..', '..', '..', 'build', 'yomitan')
|
|
: null,
|
|
);
|
|
pushUnique(
|
|
searchPaths,
|
|
options.resourcesPath ? path.join(options.resourcesPath, 'yomitan') : null,
|
|
);
|
|
pushUnique(searchPaths, '/usr/share/SubMiner/yomitan');
|
|
pushUnique(searchPaths, options.userDataPath ? path.join(options.userDataPath, 'yomitan') : null);
|
|
|
|
return searchPaths;
|
|
}
|
|
|
|
export function resolveExistingYomitanExtensionPath(
|
|
searchPaths: string[],
|
|
existsSync: (path: string) => boolean = fs.existsSync,
|
|
): string | null {
|
|
for (const candidate of searchPaths) {
|
|
if (existsSync(path.join(candidate, 'manifest.json'))) {
|
|
return candidate;
|
|
}
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
export function resolveYomitanExtensionPath(
|
|
options: YomitanExtensionPathOptions = {},
|
|
existsSync: (path: string) => boolean = fs.existsSync,
|
|
): string | null {
|
|
return resolveExistingYomitanExtensionPath(getYomitanExtensionSearchPaths(options), existsSync);
|
|
}
|