<commit_before>/* eslint global-require: 0 *//* eslint prefer-template: 0 */
/* eslint quote-props: 0 */
const packager = require('electron-packager');
const path = require('path');
const util = require('util');
const tmpdir = path.resolve(require('os').tmpdir(), 'nylas-build');
const fs = require('fs-plus');
const coffeereact = require('coffee-react');
const glob = require('glob');
const babel = require('babel-core');

const packageJSON = require('../../package.json')
const babelOptions = require("../../static/babelrc");

module.exports = (grunt) => {
  function runCopyAPM(buildPath, electronVersion, platform, arch, callback) {
    // Move APM up out of the /app folder which will be inside the ASAR
    const apmTargetDir = path.resolve(buildPath, '..', 'apm');
    fs.moveSync(path.join(buildPath, 'apm'), apmTargetDir)

    // Move /apm/node_modules/atom-package-manager up a level. We're
    // essentially pulling the atom-package-manager module up outside of
    // the node_modules folder, which is necessary because npmV3 installs
    // nested dependencies in the same dir.
    const apmPackageDir = path.join(apmTargetDir, 'node_modules', 'atom-package-manager')
    for (const name of fs.readdirSync(apmPackageDir)) {
      fs.renameSync(path.join(apmPackageDir, name), path.join(apmTargetDir, name));
    }

    const apmSymlink = path.join(apmTargetDir, 'node_modules', '.bin', 'apm');
    if (fs.existsSync(apmSymlink)) {
      fs.unlinkSync(apmSymlink);
    }
    fs.rmdirSync(apmPackageDir);
    callback();
  }

  function runCopyPlatformSpecificResources(buildPath, electronVersion, platform, arch, callback) {
    // these files (like nylas-mailto-default.reg) go alongside the ASAR,
    // not inside it, so we need to move out of the `app` directory.
    const resourcesDir = path.resolve(buildPath, '..');
    if (platform === 'win32') {
      fs.copySync(path.resolve(grunt.config('appDir'), 'build', 'resources', 'win'), resourcesDir);
    }
    callback();
  }

  function runCopySymlinkedPackages(buildPath, electronVersion, platform, arch, callback) {
    console.log("---> Moving symlinked node modules / internal packages into build folder.")

    const dirs = [
      path.join(buildPath, 'internal_packages'),
      path.join(buildPath, 'node_modules'),
    ];

    dirs.forEach((dir) => {
      fs.readdirSync(dir).forEach((packageName) => {
        const packagePath = path.join(dir, packageName)
        const realPackagePath = fs.realpathSync(packagePath).replace('/private/', '/')
        if (realPackagePath !== packagePath) {
          console.log(`  ---> Copying ${realPackagePath} to ${packagePath}`);
          fs.removeSync(packagePath);
          fs.copySync(realPackagePath, packagePath);
        }
      });
    });

    callback();
  }

  /**
   * We don't need the K2 folder anymore since the previous step hard
   * copied the local-sync package (and its isomorphic-core dependency)
   * into /internal_packages. The remains of the folder are N1-Cloud
   * pieces that aren't necessary
   */
  function removeUnnecessaryFiles(buildPath, electronVersion, platform, arch, callback) {
    fs.removeSync(path.join(buildPath, 'src', 'K2'))
    callback();
  }

  function runTranspilers(buildPath, electronVersion, platform, arch, callback) {
    console.log("---> Running babel and coffeescript transpilers")

    grunt.config('source:coffeescript').forEach(pattern => {
      glob.sync(pattern, {cwd: buildPath, absolute: true}).forEach((coffeepath) => {
        if (/(node_modules|\.js$)/.test(coffeepath)) return
        console.log(`  ---> Compiling ${coffeepath.slice(coffeepath.indexOf("/app") + 4)}`)
        const outPath = coffeepath.replace(path.extname(coffeepath), '.js');
        const res = coffeereact.compile(grunt.file.read(coffeepath), {
          bare: false,
          join: false,
          separator: grunt.util.normalizelf(grunt.util.linefeed),

          sourceMap: true,
          sourceRoot: '/',
          generatedFile: path.basename(outPath),
          sourceFiles: [path.relative(buildPath, coffeepath)],
        });
        grunt.file.write(outPath, `${res.js}\n//# sourceMappingURL=${path.basename(outPath)}.map\n`);
        grunt.file.write(`${outPath}.map`, res.v3SourceMap);
        fs.unlinkSync(coffeepath);
      });
    });

    grunt.config('source:es6').forEach(pattern => {
      glob.sync(pattern, {cwd: buildPath, absolute: true}).forEach((es6Path) => {
        if (/(node_modules|\.js$)/.test(es6Path)) return
        const outPath = es6Path.replace(path.extname(es6Path), '.js');
        console.log(`  ---> Compiling ${es6Path.slice(es6Path.indexOf("/app") + 4)}`)
        const res = babel.transformFileSync(es6Path, Object.assign(babelOptions, {
          sourceMaps: true,
          sourceRoot: '/',
          sourceMapTarget: path.relative(buildPath, outPath),
          sourceFileName: path.relative(buildPath, es6Path),
        }));
        grunt.file.write(outPath, `${res.code}\n//# sourceMappingURL=${path.basename(outPath)}.map\n`);
        grunt.file.write(`${outPath}.map`, JSON.stringify(res.map));
        fs.unlinkSync(es6Path);
      });
    });

    callback();
  }

  const platform = grunt.option('platform');
  const {shouldPublishBuild} = require('./task-helpers')(grunt);

  // See: https://github.com/electron-userland/electron-packager/blob/master/usage.txt
  grunt.config.merge({
    'packager': {
      'app-version': packageJSON.version,
      'platform': platform,
      'protocols': [{
        name: "Nylas Protocol",
        schemes: ["nylas"],
      }, {
        name: "Mailto Protocol",
        schemes: ["mailto"],
      }],
      'dir': grunt.config('appDir'),
      'app-category-type': "public.app-category.business",
      'tmpdir': tmpdir,
      'arch': {
        'win32': 'ia32',
      }[platform],
      'icon': {
        darwin: path.resolve(grunt.config('appDir'), 'build', 'resources', 'mac', 'nylas.icns'),
        win32: path.resolve(grunt.config('appDir'), 'build', 'resources', 'win', 'nylas.ico'),
        linux: undefined,
      }[platform],
      'name': {
        darwin: 'Nylas N1',
        win32: 'nylas',
        linux: 'nylas',
      }[platform],
      'app-copyright': `Copyright (C) 2014-${new Date().getFullYear()} Nylas, Inc. All rights reserved.`,
      'derefSymlinks': false,
      'asar': {
        'unpack': "{" + [
          '*.node',
          '**/vendor/**',
          'examples/**',
          '**/src/tasks/**',
          '**/node_modules/spellchecker/**',
          '**/node_modules/windows-shortcuts/**',
        ].join(',') + "}",
      },
      'ignore': [
        // top level dirs we never want
        '^[\\/]+arclib',
        '^[\\/]+build',
        '^[\\/]+electron',
        '^[\\/]+flow-typed',
        '^[\\/]+spec_integration',

        // general dirs we never want
        '[\\/]+gh-pages$',
        '[\\/]+docs$',
        '[\\/]+obj[\\/]+gen',
        '[\\/]+\\.deps$',

        // specific files we never want
        '\\.DS_Store$',
        '\\.jshintrc$',
        '\\.npmignore$',
        '\\.pairs$',
        '\\.travis\\.yml$',
        'appveyor\\.yml$',
        '\\.idea$',
        '\\.editorconfig$',
        '\\.lint$',
        '\\.lintignore$',
        '\\.arcconfig$',
        '\\.flowconfig$',
        '\\.jshintignore$',
        '\\.gitattributes$',
        '\\.gitkeep$',
        '\\.pdb$',
        '\\.cc$',
        '\\.h$',
        '\\.d\\.ts$',
        '\\.js\\.flow$',
        '\\.map$',
        'binding\\.gyp$',
        'target\\.mk$',
        '\\.node\\.dYSM$',
        'autoconf-\\d*\\.tar\\.gz$',

        // specific (large) module bits we know we don't need
        'node_modules[\\/]+less[\\/]+dist$',
        'node_modules[\\/]+react[\\/]+dist$',
        'node_modules[\\/].*[\\/]tests?$',
        'node_modules[\\/].*[\\/]coverage$',
        'node_modules[\\/].*[\\/]benchmark$',
        '@paulbetts[\\/]+cld[\\/]+deps[\\/]+cld',
      ],
      'out': grunt.config('outputDir'),<commit_msg>Don't need to lint arclint<commit_after>/* eslint global-require: 0 *//* eslint prefer-template: 0 */
/* eslint quote-props: 0 */
const packager = require('electron-packager');
const path = require('path');
const util = require('util');
const tmpdir = path.resolve(require('os').tmpdir(), 'nylas-build');
const fs = require('fs-plus');
const coffeereact = require('coffee-react');
const glob = require('glob');
const babel = require('babel-core');

const packageJSON = require('../../package.json')
const babelOptions = require("../../static/babelrc");

module.exports = (grunt) => {
  function runCopyAPM(buildPath, electronVersion, platform, arch, callback) {
    // Move APM up out of the /app folder which will be inside the ASAR
    const apmTargetDir = path.resolve(buildPath, '..', 'apm');
    fs.moveSync(path.join(buildPath, 'apm'), apmTargetDir)

    // Move /apm/node_modules/atom-package-manager up a level. We're
    // essentially pulling the atom-package-manager module up outside of
    // the node_modules folder, which is necessary because npmV3 installs
    // nested dependencies in the same dir.
    const apmPackageDir = path.join(apmTargetDir, 'node_modules', 'atom-package-manager')
    for (const name of fs.readdirSync(apmPackageDir)) {
      fs.renameSync(path.join(apmPackageDir, name), path.join(apmTargetDir, name));
    }

    const apmSymlink = path.join(apmTargetDir, 'node_modules', '.bin', 'apm');
    if (fs.existsSync(apmSymlink)) {
      fs.unlinkSync(apmSymlink);
    }
    fs.rmdirSync(apmPackageDir);
    callback();
  }

  function runCopyPlatformSpecificResources(buildPath, electronVersion, platform, arch, callback) {
    // these files (like nylas-mailto-default.reg) go alongside the ASAR,
    // not inside it, so we need to move out of the `app` directory.
    const resourcesDir = path.resolve(buildPath, '..');
    if (platform === 'win32') {
      fs.copySync(path.resolve(grunt.config('appDir'), 'build', 'resources', 'win'), resourcesDir);
    }
    callback();
  }

  function runCopySymlinkedPackages(buildPath, electronVersion, platform, arch, callback) {
    console.log("---> Moving symlinked node modules / internal packages into build folder.")

    const dirs = [
      path.join(buildPath, 'internal_packages'),
      path.join(buildPath, 'node_modules'),
    ];

    dirs.forEach((dir) => {
      fs.readdirSync(dir).forEach((packageName) => {
        const packagePath = path.join(dir, packageName)
        const realPackagePath = fs.realpathSync(packagePath).replace('/private/', '/')
        if (realPackagePath !== packagePath) {
          console.log(`  ---> Copying ${realPackagePath} to ${packagePath}`);
          fs.removeSync(packagePath);
          fs.copySync(realPackagePath, packagePath);
        }
      });
    });

    callback();
  }

  /**
   * We don't need the K2 folder anymore since the previous step hard
   * copied the local-sync package (and its isomorphic-core dependency)
   * into /internal_packages. The remains of the folder are N1-Cloud
   * pieces that aren't necessary
   */
  function removeUnnecessaryFiles(buildPath, electronVersion, platform, arch, callback) {
    fs.removeSync(path.join(buildPath, 'src', 'K2'))
    callback();
  }

  function runTranspilers(buildPath, electronVersion, platform, arch, callback) {
    console.log("---> Running babel and coffeescript transpilers")

    grunt.config('source:coffeescript').forEach(pattern => {
      glob.sync(pattern, {cwd: buildPath, absolute: true}).forEach((coffeepath) => {
        if (/(node_modules|\.js$)/.test(coffeepath)) return
        console.log(`  ---> Compiling ${coffeepath.slice(coffeepath.indexOf("/app") + 4)}`)
        const outPath = coffeepath.replace(path.extname(coffeepath), '.js');
        const res = coffeereact.compile(grunt.file.read(coffeepath), {
          bare: false,
          join: false,
          separator: grunt.util.normalizelf(grunt.util.linefeed),

          sourceMap: true,
          sourceRoot: '/',
          generatedFile: path.basename(outPath),
          sourceFiles: [path.relative(buildPath, coffeepath)],
        });
        grunt.file.write(outPath, `${res.js}\n//# sourceMappingURL=${path.basename(outPath)}.map\n`);
        grunt.file.write(`${outPath}.map`, res.v3SourceMap);
        fs.unlinkSync(coffeepath);
      });
    });

    grunt.config('source:es6').forEach(pattern => {
      glob.sync(pattern, {cwd: buildPath, absolute: true}).forEach((es6Path) => {
        if (/(node_modules|\.js$)/.test(es6Path)) return
        const outPath = es6Path.replace(path.extname(es6Path), '.js');
        console.log(`  ---> Compiling ${es6Path.slice(es6Path.indexOf("/app") + 4)}`)
        const res = babel.transformFileSync(es6Path, Object.assign(babelOptions, {
          sourceMaps: true,
          sourceRoot: '/',
          sourceMapTarget: path.relative(buildPath, outPath),
          sourceFileName: path.relative(buildPath, es6Path),
        }));
        grunt.file.write(outPath, `${res.code}\n//# sourceMappingURL=${path.basename(outPath)}.map\n`);
        grunt.file.write(`${outPath}.map`, JSON.stringify(res.map));
        fs.unlinkSync(es6Path);
      });
    });

    callback();
  }

  const platform = grunt.option('platform');
  const {shouldPublishBuild} = require('./task-helpers')(grunt);

  // See: https://github.com/electron-userland/electron-packager/blob/master/usage.txt
  grunt.config.merge({
    'packager': {
      'app-version': packageJSON.version,
      'platform': platform,
      'protocols': [{
        name: "Nylas Protocol",
        schemes: ["nylas"],
      }, {
        name: "Mailto Protocol",
        schemes: ["mailto"],
      }],
      'dir': grunt.config('appDir'),
      'app-category-type': "public.app-category.business",
      'tmpdir': tmpdir,
      'arch': {
        'win32': 'ia32',
      }[platform],
      'icon': {
        darwin: path.resolve(grunt.config('appDir'), 'build', 'resources', 'mac', 'nylas.icns'),
        win32: path.resolve(grunt.config('appDir'), 'build', 'resources', 'win', 'nylas.ico'),
        linux: undefined,
      }[platform],
      'name': {
        darwin: 'Nylas N1',
        win32: 'nylas',
        linux: 'nylas',
      }[platform],
      'app-copyright': `Copyright (C) 2014-${new Date().getFullYear()} Nylas, Inc. All rights reserved.`,
      'derefSymlinks': false,
      'asar': {
        'unpack': "{" + [
          '*.node',
          '**/vendor/**',
          'examples/**',
          '**/src/tasks/**',
          '**/node_modules/spellchecker/**',
          '**/node_modules/windows-shortcuts/**',
        ].join(',') + "}",
      },
      'ignore': [
        // top level dirs we never want
        '^[\\/]+arclib',
        '^[\\/]+build',
        '^[\\/]+electron',
        '^[\\/]+flow-typed',
        '^[\\/]+spec_integration',

        // general dirs we never want
        '[\\/]+gh-pages$',
        '[\\/]+docs$',
        '[\\/]+obj[\\/]+gen',
        '[\\/]+\\.deps$',

        // specific files we never want
        '\\.DS_Store$',
        '\\.jshintrc$',
        '\\.npmignore$',
        '\\.pairs$',
        '\\.travis\\.yml$',
        'appveyor\\.yml$',
        '\\.idea$',
        '\\.editorconfig$',
        '\\.lint$',
        '\\.lintignore$',
        '\\.arcconfig$',
        '\\.arclint$',
        '\\.flowconfig$',
        '\\.jshintignore$',
        '\\.gitattributes$',
        '\\.gitkeep$',
        '\\.pdb$',
        '\\.cc$',
        '\\.h$',
        '\\.d\\.ts$',
        '\\.js\\.flow$',
        '\\.map$',
        'binding\\.gyp$',
        'target\\.mk$',
        '\\.node\\.dYSM$',
        'autoconf-\\d*\\.tar\\.gz$',

        // specific (large) module bits we know we don't need
        'node_modules[\\/]+less[\\/]+dist$',
        'node_modules[\\/]+react[\\/]+dist$',
        'node_modules[\\/].*[\\/]tests?$',
        'node_modules[\\/].*[\\/]coverage$',
        'node_modules[\\/].*[\\/]benchmark$',
        '@paulbetts[\\/]+cld[\\/]+deps[\\/]+cld',
      ],
      'out': grunt.config('outputDir'),
{'fraction_non_alphanumeric': 0.19004863449307893, 'fraction_numerical': 0.004364633994263624, 'mean_word_length': 2.538274873152438, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 27, 'https://': 2, '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': '3072313', 'n_tokens_mistral': 5298, 'n_tokens_neox': 5206, 'n_words': 978}