<commit_before>// Any copyright is dedicated to the Public Domain.
// http://creativecommons.org/publicdomain/zero/1.0/

import path from 'path';
import os from 'os';

import through2 from 'through2';
import packager from 'electron-packager';
import vinyl from 'vinyl-fs';
import zip from 'gulp-vinyl-zip';

import * as BuildUtils from './utils';

const ARCH = 'x64';
const PLATFORM = os.platform();

const IGNORE = [
  // Ignore build stuff
  '/\/appveyor.yml',
  '/\/branding($|/)',
  '/\/build($|/)',
  '/\/dist($|/)',
  '/electron($|/)',
  '/README.md',
  '/scripts($|/)',
  '/test($|/)',

  // Ignore `/app` and `/shared` once we compile main process code
  // ahead of time, rather than during runtime
  // '/app($|/)',
  // '/shared($|/)',
];

const packageApp = options => new Promise((resolve, reject) => {
  const rs = through2.obj();

  packager(options, (err, packed) => {
    if (err) {
      rs.emit('error', err);
      rs.end();
      reject(err);
      return;
    }

    const globs = packed.map(d => `${d}/**`);
    vinyl.src(globs, {
      followSymlinks: false,
      ignore: packed,
      dot: true,
    }).pipe(rs);
  });

  resolve(rs);
});

export default async function() {
  const manifest = BuildUtils.getManifest();
  const electronVersion = BuildUtils.getElectronVersion();
  const appVersion = BuildUtils.getAppVersion();

  const devDeps = Object.keys(manifest.devDependencies).map(dep => `/node_modules/${dep}($|/)`);
  const pathsToIgnore = IGNORE.concat(devDeps);

  const packagedApp = await packageApp({
    arch: ARCH,
    platform: PLATFORM,
    ignore: pathsToIgnore,
    version: electronVersion,
    dir: path.join(__dirname, '..'),
    icon: path.join(__dirname, '..', 'branding', 'app-icon'),
    out: path.join(__dirname, '..', 'dist'),
  });

  const packageName = `${manifest.name}-${appVersion}-${PLATFORM}-${ARCH}.zip`;
  const distPath = path.join(__dirname, '..', 'dist', packageName);

  packagedApp.pipe(zip.dest(distPath));
}
<commit_msg>Fix the ignore list for packaging. r=jsantell<commit_after>// Any copyright is dedicated to the Public Domain.
// http://creativecommons.org/publicdomain/zero/1.0/

import path from 'path';
import os from 'os';

import through2 from 'through2';
import packager from 'electron-packager';
import vinyl from 'vinyl-fs';
import zip from 'gulp-vinyl-zip';

import * as BuildUtils from './utils';

const ARCH = 'x64';
const PLATFORM = os.platform();

const ROOT = path.resolve(path.join(__dirname, '..'));

// electron-packager compares these against paths that are rooted in the root
// but begin with "/", e.g. "/README.md"
const IGNORE = [
  // Ignore hidden files
  '/\\.',

  // Ignore build stuff
  '^/appveyor.yml',
  '^/branding($|/)',
  '^/build($|/)',
  '^/dist($|/)',
  '^/scripts($|/)',

  // Ignore the source code and tests
  '^/app($|/)',
  '^/test($|/)',

  // Ignore docs
  '^/docs($|/)',
  '\\.md$',
  '^/LICENSE$',
  '^/NOTICE$',
];

const packageApp = options => new Promise((resolve, reject) => {
  const rs = through2.obj();

  packager(options, (err, packed) => {
    if (err) {
      rs.emit('error', err);
      rs.end();
      reject(err);
      return;
    }

    const globs = packed.map(d => `${d}/**`);
    vinyl.src(globs, {
      followSymlinks: false,
      ignore: packed,
      dot: true,
    }).pipe(rs);
  });

  resolve(rs);
});

export default async function() {
  const manifest = BuildUtils.getManifest();
  const electronVersion = BuildUtils.getElectronVersion();
  const appVersion = BuildUtils.getAppVersion();

  const packagedApp = await packageApp({
    arch: ARCH,
    platform: PLATFORM,
    ignore: IGNORE,
    prune: true,
    version: electronVersion,
    dir: ROOT,
    icon: path.join(ROOT, 'branding', 'app-icon'),
    out: path.join(ROOT, 'dist'),
  });

  const packageName = `${manifest.name}-${appVersion}-${PLATFORM}-${ARCH}.zip`;
  const distPath = path.join(ROOT, 'dist', packageName);

  packagedApp.pipe(zip.dest(distPath));
}

{'fraction_non_alphanumeric': 0.1921046014583857, 'fraction_numerical': 0.00352024138798089, 'mean_word_length': 3.2866379310344827, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3354355', 'n_tokens_mistral': 1386, 'n_tokens_neox': 1340, 'n_words': 333}