54 lines
1.5 KiB
TypeScript
54 lines
1.5 KiB
TypeScript
import path from "node:path";
|
|
|
|
export interface RuntimeResourcePathOptions {
|
|
isPackaged: boolean;
|
|
resourcesPath: string;
|
|
currentWorkingDirectory: string;
|
|
appPath: string;
|
|
overridePath?: string;
|
|
}
|
|
|
|
function uniqueCandidates(candidates: Array<string | undefined>) {
|
|
return candidates.filter((candidate, index, all): candidate is string => (
|
|
Boolean(candidate) && all.indexOf(candidate) === index
|
|
));
|
|
}
|
|
|
|
export function inputHelperPathCandidates({
|
|
isPackaged,
|
|
resourcesPath,
|
|
currentWorkingDirectory,
|
|
appPath,
|
|
overridePath,
|
|
}: RuntimeResourcePathOptions) {
|
|
const packagedPath = path.join(resourcesPath, "input-helper", "InputHelper.exe");
|
|
const developmentPaths = [
|
|
path.join(currentWorkingDirectory, "native", "input-helper", "bin", "publish", "InputHelper.exe"),
|
|
path.join(appPath, "native", "input-helper", "bin", "publish", "InputHelper.exe"),
|
|
];
|
|
|
|
return uniqueCandidates([
|
|
overridePath,
|
|
...(isPackaged ? [packagedPath] : [...developmentPaths, packagedPath]),
|
|
]);
|
|
}
|
|
|
|
export function ikInventoryListsPathCandidates({
|
|
isPackaged,
|
|
resourcesPath,
|
|
currentWorkingDirectory,
|
|
appPath,
|
|
overridePath,
|
|
}: RuntimeResourcePathOptions) {
|
|
const packagedPath = path.join(resourcesPath, "ik-inventorylists");
|
|
const developmentPaths = [
|
|
path.join(currentWorkingDirectory, "data", "ik-inventorylists"),
|
|
path.join(appPath, "data", "ik-inventorylists"),
|
|
];
|
|
|
|
return uniqueCandidates([
|
|
overridePath,
|
|
...(isPackaged ? [packagedPath] : [...developmentPaths, packagedPath]),
|
|
]);
|
|
}
|