const fs = require('fs');
|
const path = require('path');
|
|
function fileExists(filePath) {
|
try {
|
return fs.statSync(filePath).isFile();
|
} catch (_error) {
|
return false;
|
}
|
}
|
|
function getDefaultConfigCandidates(options = {}) {
|
const packaged = options.packaged !== undefined ? options.packaged : Boolean(process.pkg);
|
const cwd = options.cwd || process.cwd();
|
const appDir = options.appDir || __dirname;
|
const execPath = options.execPath || process.execPath;
|
|
if (packaged) {
|
const execDir = path.dirname(execPath);
|
return [
|
path.join(execDir, 'runtime', 'config.json'),
|
path.join(execDir, 'config.json'),
|
path.join(cwd, 'config.json'),
|
];
|
}
|
|
return [
|
path.join(cwd, 'config.json'),
|
path.join(appDir, 'config.json'),
|
];
|
}
|
|
function getDefaultConfigPath(options = {}) {
|
const candidates = getDefaultConfigCandidates(options);
|
return candidates.find(fileExists) || candidates[0];
|
}
|
|
module.exports = {
|
fileExists,
|
getDefaultConfigCandidates,
|
getDefaultConfigPath,
|
};
|