const {popen} = require('./popen.node');
let fs = require("fs");
module.exports = (arg) => {

  let fn = "function js_var_export() {\n  for var in "$@"\n  do\n    echo "$var=${!var}" >> ./temp/variables.txt\n  done\n}";
  popen("if [ ! -d "temp" ]; then mkdir temp; fi");
  if(!fs.existsSync("./temp/variables.txt")) fs.openSync("./temp/variables.txt", "w");
  fs.writeFileSync("./temp/temp.sh", fn + arg);
  let ret = popen("bash ./temp/temp.sh");
  fs.unlinkSync("./temp/temp.sh");
  let _var_obj = {};
  let _vars = fs.readFileSync("./temp/variables.txt").toString().split("\n");
  _vars.pop();
  _vars.forEach(x=>_var_obj[x.split("=")[0]] = (!isNaN(x.split("=")[1])?Number(x.split("=")[1]) : x.split("=")[1]));
  fs.unlinkSync("./temp/variables.txt")
  return {text:ret,variables:_var_obj};
}