import * as fs from "fs";
import * as path from "path";
import renderRunScript from "../../../templates/cli/schedule/runScript.js";
export function writeRunScript(entry) {
    const scriptDir = path.dirname(entry.logDir);
    const scriptPath = path.join(scriptDir, "run.sh");
    const content = renderRunScript({
        agentDir: path.dirname(entry.agentFile),
        hasEnvFile: !!entry.envFile,
        envFile: entry.envFile,
        logDir: entry.logDir,
        agentFile: entry.agentFile,
    });
    fs.mkdirSync(scriptDir, { recursive: true });
    fs.mkdirSync(entry.logDir, { recursive: true });
    fs.writeFileSync(scriptPath, content, { mode: 0o700 });
    return scriptPath;
}
