Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | import { readFileSync, existsSync } from 'fs';
import path from 'path';
import { getRepoRoot } from './config.js';
/**
* Parse a shell-style KEY=VALUE / KEY="VALUE" config file.
* Skips blank lines and comments. Strips matching surrounding quotes.
* This intentionally does NOT execute the file as shell.
*/
export function parseShellConfig(content) {
const out = {};
for (const rawLine of content.split('\n')) {
const line = rawLine.trim();
if (!line || line.startsWith('#')) continue;
const eqIdx = line.indexOf('=');
if (eqIdx <= 0) continue;
const key = line.substring(0, eqIdx).replace(/^export\s+/, '').trim();
let value = line.substring(eqIdx + 1).trim();
if (
(value.startsWith('"') && value.endsWith('"')) ||
(value.startsWith("'") && value.endsWith("'"))
) {
value = value.substring(1, value.length - 1);
}
out[key] = value;
}
return out;
}
export function readReleaseConfig(relPath) {
const fullPath = path.join(getRepoRoot(), relPath);
if (!existsSync(fullPath)) return null;
const content = readFileSync(fullPath, 'utf8');
return parseShellConfig(content);
}
export function resolveWorkItem({ explicit, envVar, releaseConfigPath }) {
if (explicit) return explicit;
if (envVar && process.env[envVar]) {
return process.env[envVar];
}
if (releaseConfigPath) {
const cfg = readReleaseConfig(releaseConfigPath);
if (cfg && envVar && cfg[envVar]) return cfg[envVar];
}
return null;
}
|