igir
Version:
🕹 A zero-setup ROM collection manager that sorts, filters, extracts or archives, patches, and reports on collections of any size on any OS.
30 lines (29 loc) • 1.1 kB
JavaScript
import fs from 'node:fs';
import path from 'node:path';
import url from 'node:url';
/**
* Search for a {@link fileName} in {@link filePath} or any of its parent directories.
*/
function scanUpPathForFile(filePath, fileName) {
const fullPath = path.join(filePath, fileName);
if (fs.existsSync(fullPath)) {
return fullPath;
}
const parentPath = path.dirname(filePath);
if (parentPath !== filePath) {
return scanUpPathForFile(path.dirname(filePath), fileName);
}
return undefined;
}
const PACKAGE_JSON_PATH = path.resolve(scanUpPathForFile(url.fileURLToPath(new URL('.', import.meta.url)), 'package.json'));
const PACKAGE_JSON = JSON.parse(fs.readFileSync(PACKAGE_JSON_PATH).toString());
/**
* A static class of globals that are parsed from `package.json` at startup, to be used widely.
*/
export default class Package {
static DIRECTORY = path.dirname(PACKAGE_JSON_PATH);
static NAME = PACKAGE_JSON.name;
static HOMEPAGE = PACKAGE_JSON.homepage;
static VERSION = PACKAGE_JSON.version;
static ENGINES_NODE = PACKAGE_JSON.engines.node;
}