Hello, I have a script (not mine) that relies on the spawn method to instantiate nodejs and it works well. However, it is imperative that my app be packaged inside an ASAR archive, which forces me to switch to execFile instead of spawn.Now I consider myself to be of intermediate level when it comes to Nodejs, but this issue has boggled me entirely for months, and I have come to ask for help. Documentation and search about the pipe method haven't been helpful at all and I am just barely able to understand what's done here. My code:var _ = require('lodash'); var join = require('path').join; var shell = require('shelljs'); module.exports = function($){ return new Electron($); }; function Electron($){ this.$ = $; this.log = require('./log')($, 'electrify:electron'); } Electron.prototype.package = function(packager_options, done) { var packager = require('electron-packager'); // fetches electron version from core temp folder var version = require(join( __dirname, '..', 'node_modules', 'electron-prebuilt', 'package.json' )).version; // app name require('.electrify/package.json').name var name = require(join(this.$.env.app.root, 'package.json')).name; this.log.info( 'packaging "'+ name +'" for platform '+ this.$.env.sys.platform + '-' + this.$.env.sys.arch + ' using electron v' + version ); // temp dir for packaging the app var tmp_package_dir = join(this.$.env.core.tmp, 'package'); shell.rm('-rf', tmp_package_dir); shell.mkdir('-p', tmp_package_dir); console.log(this.$.env.sys.arch); console.log(this.$.env.sys.platform); var args = { name: require(join(this.$.env.app.root, 'package.json')).name, version: version, arch: this.$.env.sys.arch, platform: this.$.env.sys.platform, dir: this.$.env.app.root, out: tmp_package_dir }; _.extend(args, packager_options); var self = this; packager(args, function(err /*, appdir */) { if(err) throw err; // moving pakcaged app to .dist folder shell.rm('-rf', self.$.env.app.dist); shell.mv(tmp_package_dir, self.$.env.app.dist); self.log.info('wrote new app to ', self.$.env.app.dist); if(done) done(); }); }; How would you go about refactoring this code to replace the spawn calls with execFile? Any indication or help is most welcome.Thank you.PS: I'm sorry if there are markdown errors in my post. This is my first time posting on Reddit, and there is no preview option.
Submitted December 07, 2016 at 08:37AM by Unforgiven-wanda
No comments:
Post a Comment