mksnapshot-call.js 975 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. (function() {
  2. var callMksnapshot, fs, path, spawn;
  3. fs = require('fs-extra');
  4. path = require('path');
  5. spawn = require('child_process').spawn;
  6. callMksnapshot = function(mksnapshot, content, target, builddir, callback) {
  7. return fs.writeFile(path.join(builddir, 'out.js'), content, function(error) {
  8. var child;
  9. if (error) {
  10. return callback(error);
  11. }
  12. child = spawn(mksnapshot, ['out.cc', '--startup_blob', 'out.bin', 'out.js'], {
  13. cwd: builddir
  14. });
  15. child.on('error', callback);
  16. return child.on('close', function(code) {
  17. if (code !== 0) {
  18. return callback(new Error("mksnapshot returned " + code));
  19. }
  20. try {
  21. fs.copySync(path.join(builddir, 'out.bin'), target);
  22. } catch (_error) {
  23. error = _error;
  24. return callback(error);
  25. }
  26. return callback(null);
  27. });
  28. });
  29. };
  30. module.exports = callMksnapshot;
  31. }).call(this);