<commit_before>/* eslint-env node */
var concat     = require('broccoli-sourcemap-concat');
var Funnel     = require('broccoli-funnel');
var mergeTrees = require('broccoli-merge-trees');
var replace    = require('broccoli-string-replace');
var CompileES6Modules = require('broccoli-es6modules');
var TranspileES6 = require('broccoli-babel-transpiler');
var eslint = require('broccoli-lint-eslint');
var testGenerator = require('./test-generator');
var path = require('path');

module.exports = function build(pkg, namespace) {
  namespace = namespace || pkg;

  // Generate CJS ////////////////////////////////////////////////////////////////

  var cjsSrc = new Funnel('src', {
    srcDir: '/',
    include: ['**/*.js'],
    exclude: [],
    destDir: '/'
  });
  var cjs = new CompileES6Modules(cjsSrc, { format: 'cjs' });
  cjs = new TranspileES6(cjs);
  var cjsDist = new Funnel(cjs, {
    srcDir: '/',
    destDir: 'cjs'
  });

  // Generate AMD ////////////////////////////////////////////////////////////////

  var amdSrc = new Funnel('src', {
    srcDir: '/',
    include: ['**/*.js'],
    exclude: [],
    destDir: namespace
  });
  var amd = new CompileES6Modules(amdSrc);
  amd = new TranspileES6(amd);
  // Convert module named `namespace/index` into simply `namespace`.
  amd = replace(amd, {
    files: [namespace + '/index.js'],
    pattern: {
      match:  "define('" + namespace + "/index'",
      replacement: "define('" + namespace + "'"
    }
  });
  var amdDist = concat(amd, {
    inputFiles: ['**/*.js'],
    outputFile: '/amd/' + pkg + '.js'
  });

  // Generate Dependencies and Tests /////////////////////////////////////////////

  var loader = new Funnel(path.join(require.resolve('loader.js'), '..'), {
    files: ['loader.js'],
    destDir: '/assets/'
  });

  var testSrc = new Funnel('test/tests', {
    include: ['**/*.js'],
    destDir: '/tests'
  });

  var rxjs = new Funnel(path.join(require.resolve('rxjs-es'), '..'), {
    include: ['**/*.js'],
    destDir: 'rxjs'
  });

  var symbolObservable = new Funnel(path.join(require.resolve('rxjs-es'), '..'), {
    srcDir: 'node_modules/symbol-observable/es',
    include: ['ponyfill.js'],
    destDir: '.',
    getDestinationPath: function() {
      return 'symbol-observable.js';
    }
  });

  var eslintSrc = eslint(amdSrc, { testGenerator: testGenerator });
  var eslintTests = eslint(testSrc, { testGenerator: testGenerator });
  var depSrc = mergeTrees([rxjs, symbolObservable]);

  var amdSrcWithTests = mergeTrees([amdSrc, depSrc, testSrc, eslintSrc, eslintTests], { overwrite: true });
  amdSrcWithTests = new CompileES6Modules(amdSrcWithTests);
  amdSrcWithTests = new TranspileES6(amdSrcWithTests);
  amdSrcWithTests = concat(amdSrcWithTests, {
    inputFiles: ['**/*.js'],
    outputFile: '/assets/tests.js'
  });

  var vendor = concat('', {
    inputFiles: [
      path.join(require.resolve('immutable'), '..', 'immutable.js'),
      path.join(require.resolve('rsvp'), '..', 'rsvp.js')
    ],
    outputFile: '/assets/vendor.js'
  });

  var qunit = new Funnel('node_modules', {
    srcDir: '/qunitjs/qunit',
    files: ['qunit.js', 'qunit.css'],
    destDir: '/assets'
  });

  var testSupport = concat('test', {
    inputFiles: ['../test/test-support/sinon.js', '../test/test-support/test-shims.js', '../test/test-support/test-loader.js'],
    outputFile: '/assets/test-support.js'
  });

  var testIndex = new Funnel('test', {
    srcDir: '/',
    files: ['index.html'],
    destDir: '/tests'
  });

  return mergeTrees([
    loader,
    amdDist,
    cjsDist,
    amdSrcWithTests,<commit_msg>Minor build cleanup<commit_after>/* eslint-env node */
var concat     = require('broccoli-sourcemap-concat');
var Funnel     = require('broccoli-funnel');
var mergeTrees = require('broccoli-merge-trees');
var replace    = require('broccoli-string-replace');
var CompileES6Modules = require('broccoli-es6modules');
var TranspileES6 = require('broccoli-babel-transpiler');
var eslint = require('broccoli-lint-eslint');
var testGenerator = require('./test-generator');
var path = require('path');

module.exports = function build(pkg, namespace) {
  namespace = namespace || pkg;

  // Generate CJS ////////////////////////////////////////////////////////////////

  var cjsSrc = new Funnel('src', {
    srcDir: '/',
    include: ['**/*.js'],
    exclude: [],
    destDir: '/'
  });
  var cjs = new CompileES6Modules(cjsSrc, { format: 'cjs' });
  cjs = new TranspileES6(cjs);
  var cjsDist = new Funnel(cjs, {
    srcDir: '/',
    destDir: 'cjs'
  });

  // Generate AMD ////////////////////////////////////////////////////////////////

  var amdSrc = new Funnel('src', {
    srcDir: '/',
    include: ['**/*.js'],
    exclude: [],
    destDir: namespace
  });
  var amd = new CompileES6Modules(amdSrc);
  amd = new TranspileES6(amd);
  // Convert module named `namespace/index` into simply `namespace`.
  amd = replace(amd, {
    files: [namespace + '/index.js'],
    pattern: {
      match:  "define('" + namespace + "/index'",
      replacement: "define('" + namespace + "'"
    }
  });
  var amdDist = concat(amd, {
    inputFiles: ['**/*.js'],
    outputFile: '/amd/' + pkg + '.js'
  });

  // Generate Dependencies and Tests /////////////////////////////////////////////

  var loader = new Funnel(path.join(require.resolve('loader.js'), '..'), {
    files: ['loader.js'],
    destDir: '/assets/'
  });

  var testSrc = new Funnel('test/tests', {
    include: ['**/*.js'],
    destDir: '/tests'
  });

  var rxjs = new Funnel(path.join(require.resolve('rxjs-es'), '..'), {
    include: ['**/*.js'],
    destDir: 'rxjs'
  });

  var symbolObservable = new Funnel(path.join(require.resolve('rxjs-es'), '..'), {
    srcDir: 'node_modules/symbol-observable/es',
    include: ['ponyfill.js'],
    destDir: '.',
    getDestinationPath: function() {
      return 'symbol-observable.js';
    }
  });

  var eslintSrc = eslint(amdSrc, { testGenerator: testGenerator });
  var eslintTests = eslint(testSrc, { testGenerator: testGenerator });
  var depSrc = mergeTrees([rxjs, symbolObservable]);

  var amdSrcWithTests = mergeTrees([amdSrc, depSrc, testSrc, eslintSrc, eslintTests], { overwrite: true });
  amdSrcWithTests = new CompileES6Modules(amdSrcWithTests);
  amdSrcWithTests = new TranspileES6(amdSrcWithTests);
  amdSrcWithTests = concat(amdSrcWithTests, {
    inputFiles: ['**/*.js'],
    outputFile: '/assets/tests.js'
  });

  var vendor = concat('', {
    inputFiles: [
      path.join(require.resolve('immutable'), '..', 'immutable.js'),
      path.join(require.resolve('rsvp'), '..', 'rsvp.js')
    ],
    outputFile: '/assets/vendor.js'
  });

  var qunit = new Funnel(path.join(require.resolve('qunitjs'), '..'), {
    files: ['qunit.js', 'qunit.css'],
    destDir: '/assets'
  });

  var testSupport = concat('test', {
    inputFiles: ['../test/test-support/sinon.js', '../test/test-support/test-shims.js', '../test/test-support/test-loader.js'],
    outputFile: '/assets/test-support.js'
  });

  var testIndex = new Funnel('test', {
    srcDir: '/',
    files: ['index.html'],
    destDir: '/tests'
  });

  return mergeTrees([
    loader,
    amdDist,
    cjsDist,
    amdSrcWithTests,
{'fraction_non_alphanumeric': 0.22903629536921152, 'fraction_numerical': 0.0025031289111389237, 'mean_word_length': 2.7419354838709675, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4402385', 'n_tokens_mistral': 2406, 'n_tokens_neox': 2341, 'n_words': 465}