lib/compileWASM.js
function insertEventListener (config) {
  let outFile = path.join(process.cwd(), config.outputfile);
  let tempFile = `${outFile.slice(0, outFile.lastIndexOf('.'), 0)}.temp${outFile.slice(outFile.lastIndexOf('.'))}`;
  // read in generated emscripten file
  fs.readFile(outFile, 'utf-8', (err1, data) => {
    if (err1) process.stderr.write(colors.white(err1));
    // insert eventListener
    data = data.replace(/else\{doRun\(\)\}/g, 'else{doRun()}script.dispatchEvent(doneEvent);');
    // write data to temporary file
    fs.writeFile(tempFile, data, (err2) => {
      if (err2) process.stderr.write(colors.white(err2));
      // rename temporary file to original file name
      fs.renameSync(tempFile, outFile);
    });
  });
}
function insertEventListener (config) {
  let outFile = path.join(process.cwd(), config.outputfile);
  let tempFile = `${outFile.slice(0, outFile.lastIndexOf('.'), 0)}.temp${outFile.slice(outFile.lastIndexOf('.'))}`;
  // read in generated emscripten file
  fs.readFile(outFile, 'utf-8', (err1, data) => {
    if (err1) process.stderr.write(colors.white(err1));
    // insert eventListener
    data = data.replace(/else\{doRun\(\)\}/g, 'else{doRun()}script.dispatchEvent(doneEvent);');
    // write data to temporary file
    fs.writeFile(tempFile, data, (err2) => {
      if (err2) process.stderr.write(colors.white(err2));
      // rename temporary file to original file name
      fs.renameSync(tempFile, outFile);
    });
  });
}
function insertEventListener ( config ) { let outFile = path . join ( process . cwd ( ) , config . outputfile ) ; let tempFile = ` ${ outFile . slice ( 0 , outFile . lastIndexOf ( '.' ) , 0 ) } ${ outFile . slice ( outFile . lastIndexOf ( '.' ) ) } ` ; // read in generated emscripten file fs . readFile ( outFile , 'utf-8' , ( err1 , data ) => { if ( err1 ) process . stderr . write ( colors . white ( err1 ) ) ; // insert eventListener data = data . replace ( / else\{doRun\(\)\} / g , 'else{doRun()}script.dispatchEvent(doneEvent);' ) ; // write data to temporary file fs . writeFile ( tempFile , data , ( err2 ) => { if ( err2 ) process . stderr . write ( colors . white ( err2 ) ) ; // rename temporary file to original file name fs . renameSync ( tempFile , outFile ) ; } ) ; } ) ; }
Inserts an event listener into the autogenerated lib.js file
to notify us when WebAssembly has finished loading. As of April 2017,
this is needed because Firefox doesn't reliably emmit a script onload
notification
@param {Object} config
Inserts an event listener into the autogenerated lib . js file to notify us when WebAssembly has finished loading . As of April 2017 this is needed because Firefox doesn t reliably emmit a script onload notification