<commit_before>var electronPackager = Meteor.wrapAsync(Npm.require("electron-packager"));
var fs = Npm.require('fs');
var mkdirp = Meteor.wrapAsync(Npm.require('mkdirp'));
var path = Npm.require('path');
var proc = Npm.require('child_process');

var writeFile = Meteor.wrapAsync(fs.writeFile);

var exec = Meteor.wrapAsync(function(command, options, callback){
  proc.exec(command, options, function(err, stdout, stderr){
    callback(err, {stdout: stdout, stderr: stderr});
  });
});

createBinaries = function() {
  // Use a predictable directory so that other scripts can locate the builds, also so that the builds
  // may be cached:
  // TODO(jeff): Use existing binaries if the app hasn't changed.
  var workingDir = path.join(process.env.PWD, '.meteor-electron');
  mkdirp(workingDir);

  //TODO probably want to allow users to add other more unusual
  //architectures if they want (ARM, 32 bit, etc.)
  var platform = "darwin";

  //TODO seed the binaryDir from the package assets

  // *binaryDir* holds the vanilla electron apps
  var binaryDir = path.join(workingDir, "releases");
  mkdirp(binaryDir);

  // *appDir* holds the electron application that points to a meteor app
  var appDir = path.join(workingDir, "apps");
  mkdirp(appDir);

  // *buildDir* contains the uncompressed apps
  var buildDir = path.join(workingDir, "builds");
  mkdirp(buildDir);

  // *finalDir* contains zipped apps ready to be downloaded
  var finalDir = path.join(workingDir, "final");
  mkdirp(finalDir);


  var electronSettings = Meteor.settings.electron || {};
  var appVersion = electronSettings.version;
  var appName = electronSettings.name;

  [
    "autoUpdater.js",
    "main.js",
    "menu.js",
    "package.json",
    "preload.js",
    "proxyWindowEvents.js"
  ].forEach(function(filename) {
    var fileContents = Assets.getText(path.join("app", filename));

    // Replace parameters in `package.json`.
    if (filename === "package.json") {
      var packageJSON = JSON.parse(fileContents);
      if (appVersion) packageJSON.version = appVersion;
      if (appName) {
        packageJSON.name = appName.toLowerCase().replace(/\s/g, '-');
        packageJSON.productName = appName;
      }
      fileContents = JSON.stringify(packageJSON);
    }

    writeFile(path.join(appDir, filename), fileContents);
  });

  //TODO be smarter about caching this..
  exec("npm install", {cwd: appDir});

  var settings = _.defaults({}, electronSettings, {
    rootUrl: process.env.ROOT_URL
  });

  var signingIdentity = electronSettings.sign;
  if (canServeUpdates()) {
    // Enable the auto-updater if possible.
    if ((platform === 'darwin') && !signingIdentity) {
      // If the app isn't signed and we try to use the auto-updater, it will
      // throw an exception.
      console.error('Developer ID signing identity is missing: remote updates will not work.');
    } else {
      settings.updateFeedUrl = settings.rootUrl + UPDATE_FEED_PATH;
    }
  }

  writeFile(path.join(appDir, "electronSettings.json"), JSON.stringify(settings));

  var packagerSettings = {
    dir: appDir,
    name: appName || "Electron",
    platform: platform,
    arch: "x64",
    version: "0.35.0",
    out: buildDir,
    cache: binaryDir,
    overwrite: true
  };
  if (appVersion) {
    packagerSettings['app-version'] = appVersion;
  }
  if (electronSettings.icon) {
    var icon = platformSpecificSetting(electronSettings.icon);
    if (icon) {
      var iconPath = path.join(process.cwd(), 'assets', 'app', icon);
      packagerSettings.icon = iconPath;
    }
  }
  if (signingIdentity) {
    packagerSettings.sign = signingIdentity;
  }

  var build = electronPackager(packagerSettings)[0];
  console.log("Build created at", build);


  // Package the build for download.

  // The auto-updater framework only supports installing ZIP releases:
  // https://github.com/Squirrel/Squirrel.Mac#update-json-format<commit_msg>Upgrade Electron to pick up `window.open` fix<commit_after>var electronPackager = Meteor.wrapAsync(Npm.require("electron-packager"));
var fs = Npm.require('fs');
var mkdirp = Meteor.wrapAsync(Npm.require('mkdirp'));
var path = Npm.require('path');
var proc = Npm.require('child_process');

var writeFile = Meteor.wrapAsync(fs.writeFile);

var exec = Meteor.wrapAsync(function(command, options, callback){
  proc.exec(command, options, function(err, stdout, stderr){
    callback(err, {stdout: stdout, stderr: stderr});
  });
});

createBinaries = function() {
  // Use a predictable directory so that other scripts can locate the builds, also so that the builds
  // may be cached:
  // TODO(jeff): Use existing binaries if the app hasn't changed.
  var workingDir = path.join(process.env.PWD, '.meteor-electron');
  mkdirp(workingDir);

  //TODO probably want to allow users to add other more unusual
  //architectures if they want (ARM, 32 bit, etc.)
  var platform = "darwin";

  //TODO seed the binaryDir from the package assets

  // *binaryDir* holds the vanilla electron apps
  var binaryDir = path.join(workingDir, "releases");
  mkdirp(binaryDir);

  // *appDir* holds the electron application that points to a meteor app
  var appDir = path.join(workingDir, "apps");
  mkdirp(appDir);

  // *buildDir* contains the uncompressed apps
  var buildDir = path.join(workingDir, "builds");
  mkdirp(buildDir);

  // *finalDir* contains zipped apps ready to be downloaded
  var finalDir = path.join(workingDir, "final");
  mkdirp(finalDir);


  var electronSettings = Meteor.settings.electron || {};
  var appVersion = electronSettings.version;
  var appName = electronSettings.name;

  [
    "autoUpdater.js",
    "main.js",
    "menu.js",
    "package.json",
    "preload.js",
    "proxyWindowEvents.js"
  ].forEach(function(filename) {
    var fileContents = Assets.getText(path.join("app", filename));

    // Replace parameters in `package.json`.
    if (filename === "package.json") {
      var packageJSON = JSON.parse(fileContents);
      if (appVersion) packageJSON.version = appVersion;
      if (appName) {
        packageJSON.name = appName.toLowerCase().replace(/\s/g, '-');
        packageJSON.productName = appName;
      }
      fileContents = JSON.stringify(packageJSON);
    }

    writeFile(path.join(appDir, filename), fileContents);
  });

  //TODO be smarter about caching this..
  exec("npm install", {cwd: appDir});

  var settings = _.defaults({}, electronSettings, {
    rootUrl: process.env.ROOT_URL
  });

  var signingIdentity = electronSettings.sign;
  if (canServeUpdates()) {
    // Enable the auto-updater if possible.
    if ((platform === 'darwin') && !signingIdentity) {
      // If the app isn't signed and we try to use the auto-updater, it will
      // throw an exception.
      console.error('Developer ID signing identity is missing: remote updates will not work.');
    } else {
      settings.updateFeedUrl = settings.rootUrl + UPDATE_FEED_PATH;
    }
  }

  writeFile(path.join(appDir, "electronSettings.json"), JSON.stringify(settings));

  var packagerSettings = {
    dir: appDir,
    name: appName || "Electron",
    platform: platform,
    arch: "x64",
    version: "0.35.4",
    out: buildDir,
    cache: binaryDir,
    overwrite: true
  };
  if (appVersion) {
    packagerSettings['app-version'] = appVersion;
  }
  if (electronSettings.icon) {
    var icon = platformSpecificSetting(electronSettings.icon);
    if (icon) {
      var iconPath = path.join(process.cwd(), 'assets', 'app', icon);
      packagerSettings.icon = iconPath;
    }
  }
  if (signingIdentity) {
    packagerSettings.sign = signingIdentity;
  }

  var build = electronPackager(packagerSettings)[0];
  console.log("Build created at", build);


  // Package the build for download.

  // The auto-updater framework only supports installing ZIP releases:
  // https://github.com/Squirrel/Squirrel.Mac#update-json-format
{'fraction_non_alphanumeric': 0.13076139546727783, 'fraction_numerical': 0.002291825821237586, 'mean_word_length': 3.5828471411901983, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4592315', 'n_tokens_mistral': 2493, 'n_tokens_neox': 2377, 'n_words': 649}