"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getMinimalEnvironment = getMinimalEnvironment;
exports.createSortCommandForFile = createSortCommandForFile;
exports.spawnSortProcess = spawnSortProcess;
const child_process_1 = require("child_process");
function getMinimalEnvironment() {
    return {
        ...process.env,
        LC_ALL: 'C',
    };
}
function createSortCommandForFile(file) {
    // BED files use columns 1,2 (0-based) for chromosome and start position
    return `(grep "^#" "${file}"; grep -v "^#" "${file}" | sort -t"\`printf '\\t'\`" -k1,1 -k2,2n)`;
}
function spawnSortProcess(options) {
    const command = createSortCommandForFile(options.file);
    const env = getMinimalEnvironment();
    return (0, child_process_1.spawn)('sh', ['-c', command], {
        env,
        stdio: 'inherit',
    });
}
