<commit_before>/* global require, module, escape */
'use strict';

/**
@module ember-cli
*/
var fs           = require('fs');
var existsSync   = require('exists-sync');
var path         = require('path');
var p            = require('ember-cli-preprocess-registry/preprocessors');
var chalk        = require('chalk');
var escapeRegExp = require('escape-string-regexp');
var EOL          = require('os').EOL;

var Project      = require('../models/project');
var cleanBaseURL = require('clean-base-url');
var SilentError  = require('silent-error');

var preprocessJs  = p.preprocessJs;
var preprocessCss = p.preprocessCss;
var isType        = p.isType;

var preprocessTemplates = p.preprocessTemplates;

var preprocessMinifyCss = p.preprocessMinifyCss;

var Babel  = require('broccoli-babel-transpiler');
var concat = require('broccoli-concat');

var ConfigReplace = require('broccoli-config-replace');
var ConfigLoader  = require('broccoli-config-loader');
var mergeTrees    = require('./merge-trees');
var WatchedDir    = require('broccoli-source').WatchedDir;
var UnwatchedDir  = require('broccoli-source').UnwatchedDir;

var merge         = require('lodash/merge');
var defaultsDeep  = require('lodash/defaultsDeep');
var omitBy        = require('lodash/omitBy');
var isNull        = require('lodash/isNull');
var Funnel        = require('broccoli-funnel');
var funnelReducer = require('broccoli-funnel-reducer');


var DEFAULT_CONFIG = {
  es3Safe: true,
  storeConfigInMeta: true,
  autoRun: true,
  outputPaths: {
    app: {
      html: 'index.html'
    },
    tests: {
      js: '/assets/tests.js'
    },
    vendor: {
      css: '/assets/vendor.css',
      js: '/assets/vendor.js'
    },
    testSupport: {
      css: '/assets/test-support.css',
      js: {
        testSupport: '/assets/test-support.js',
        testLoader: '/assets/test-loader.js'
      }
    }
  },
  minifyCSS: {
    options: { relativeTo: 'assets' }
  },
  sourcemaps: {},
  trees: {},
  jshintrc: {},
  addons: {}
};

module.exports = EmberApp;

/**
  EmberApp is the main class Ember CLI uses to manage the Broccoli trees
  for your application. It is very tightly integrated with Broccoli and has
  an `toTree()` method you can use to get the entire tree for your application.

  Available init options:
    - es3Safe, defaults to `true`,
    - storeConfigInMeta, defaults to `true`,
    - autoRun, defaults to `true`,
    - outputPaths, defaults to `{}`,
    - minifyCSS, defaults to `{enabled: !!isProduction,options: { relativeTo: 'assets' }},
    - minifyJS, defaults to `{enabled: !!isProduction},
    - sourcemaps, defaults to `{}`,
    - trees, defaults to `{},`
    - jshintrc, defaults to `{},`
    - vendorFiles, defaults to `{}`

  @class EmberApp
  @constructor
  @param {Object} [defaults]
  @param {Object} [options={}] Configuration options
*/
function EmberApp(defaults, options) {
  if (arguments.length === 0) {
    options = {};
  } else if (arguments.length === 1) {
    options = defaults;
  } else {
    defaultsDeep(options, defaults);
  }

  this._initProject(options);
  this.name = options.name || this.project.name();

  this.env  = EmberApp.env();
  this.isProduction = (this.env === 'production');

  this.registry = options.registry || p.defaultRegistry(this);

  this.bowerDirectory = this.project.bowerDirectory;

  this._initTestsAndHinting(options);
  this._initOptions(options);
  this._initVendorFiles();

  this._styleOutputFiles       = {};
  this._scriptOutputFiles      = {};

  this.legacyFilesToAppend     = [];
  this.vendorStaticStyles      = [];
  this.otherAssetPaths         = [];
  this.legacyTestFilesToAppend = [];
  this.vendorTestStaticStyles  = [];

  this.trees = this.options.trees;

  this.populateLegacyFiles();
  p.setupRegistry(this);
  this._notifyAddonIncluded();

  if (!this._addonInstalled('loader.js') && !this.options._ignoreMissingLoader) {
    throw new SilentError('The loader.js addon is missing from your project, please add it to `package.json`.');
  }
}

/**
  @private
  @method _initTestsAndHinting
  @param {Object} options
*/
EmberApp.prototype._initTestsAndHinting = function(options) {
  var testsEnabledDefault = process.env.EMBER_CLI_TEST_COMMAND || !this.isProduction;

  this.tests   = options.hasOwnProperty('tests')   ? options.tests   : testsEnabledDefault;
  this.hinting = options.hasOwnProperty('hinting') ? options.hinting : testsEnabledDefault;
};

/**
  @private
  @method _initProject
  @param {Object} options
*/
EmberApp.prototype._initProject = function(options) {
  var app = this;

  this.project = options.project || Project.closestSync(process.cwd());

  if (options.configPath) {
    this.project.configPath = function() { return app._resolveLocal(options.configPath); };
  }
};

/**
  @private
  @method _initOptions
  @param {Object} options
*/
EmberApp.prototype._initOptions = function(options) {
  var babelOptions = {};

  if (this._addonInstalled('ember-cli-babel')) {
    var amdNameResolver = require('amd-name-resolver').moduleResolve;
    babelOptions = {
      compileModules: true,
      modules: 'amdStrict',
      moduleIds: true,
      resolveModuleSource: amdNameResolver
    };
  }

  this.options = defaultsDeep(options, {
    babel: babelOptions,
    jshintrc: {
      app: this.project.root,
      tests: this._resolveLocal('tests')
    },
    minifyCSS: {
      enabled: !!this.isProduction
    },
    minifyJS: {
      enabled: !!this.isProduction
    },<commit_msg>broccoli/ember-app: Add documentation<commit_after>/* global require, module, escape */
'use strict';

/**
@module ember-cli
*/
var fs           = require('fs');
var existsSync   = require('exists-sync');
var path         = require('path');
var p            = require('ember-cli-preprocess-registry/preprocessors');
var chalk        = require('chalk');
var escapeRegExp = require('escape-string-regexp');
var EOL          = require('os').EOL;

var Project      = require('../models/project');
var cleanBaseURL = require('clean-base-url');
var SilentError  = require('silent-error');

var preprocessJs  = p.preprocessJs;
var preprocessCss = p.preprocessCss;
var isType        = p.isType;

var preprocessTemplates = p.preprocessTemplates;

var preprocessMinifyCss = p.preprocessMinifyCss;

var Babel  = require('broccoli-babel-transpiler');
var concat = require('broccoli-concat');

var ConfigReplace = require('broccoli-config-replace');
var ConfigLoader  = require('broccoli-config-loader');
var mergeTrees    = require('./merge-trees');
var WatchedDir    = require('broccoli-source').WatchedDir;
var UnwatchedDir  = require('broccoli-source').UnwatchedDir;

var merge         = require('lodash/merge');
var defaultsDeep  = require('lodash/defaultsDeep');
var omitBy        = require('lodash/omitBy');
var isNull        = require('lodash/isNull');
var Funnel        = require('broccoli-funnel');
var funnelReducer = require('broccoli-funnel-reducer');


var DEFAULT_CONFIG = {
  es3Safe: true,
  storeConfigInMeta: true,
  autoRun: true,
  outputPaths: {
    app: {
      html: 'index.html'
    },
    tests: {
      js: '/assets/tests.js'
    },
    vendor: {
      css: '/assets/vendor.css',
      js: '/assets/vendor.js'
    },
    testSupport: {
      css: '/assets/test-support.css',
      js: {
        testSupport: '/assets/test-support.js',
        testLoader: '/assets/test-loader.js'
      }
    }
  },
  minifyCSS: {
    options: { relativeTo: 'assets' }
  },
  sourcemaps: {},
  trees: {},
  jshintrc: {},
  addons: {}
};

module.exports = EmberApp;

/**
  EmberApp is the main class Ember CLI uses to manage the Broccoli trees
  for your application. It is very tightly integrated with Broccoli and has
  an `toTree()` method you can use to get the entire tree for your application.

  Available init options:
    - es3Safe, defaults to `true`,
    - storeConfigInMeta, defaults to `true`,
    - autoRun, defaults to `true`,
    - outputPaths, defaults to `{}`,
    - minifyCSS, defaults to `{enabled: !!isProduction,options: { relativeTo: 'assets' }},
    - minifyJS, defaults to `{enabled: !!isProduction},
    - sourcemaps, defaults to `{}`,
    - trees, defaults to `{},`
    - jshintrc, defaults to `{},`
    - vendorFiles, defaults to `{}`

  @class EmberApp
  @constructor
  @param {Object} [defaults]
  @param {Object} [options={}] Configuration options
*/
function EmberApp(defaults, options) {
  if (arguments.length === 0) {
    options = {};
  } else if (arguments.length === 1) {
    options = defaults;
  } else {
    defaultsDeep(options, defaults);
  }

  this._initProject(options);
  this.name = options.name || this.project.name();

  this.env  = EmberApp.env();
  this.isProduction = (this.env === 'production');

  this.registry = options.registry || p.defaultRegistry(this);

  this.bowerDirectory = this.project.bowerDirectory;

  this._initTestsAndHinting(options);
  this._initOptions(options);
  this._initVendorFiles();

  this._styleOutputFiles       = {};
  this._scriptOutputFiles      = {};

  this.legacyFilesToAppend     = [];
  this.vendorStaticStyles      = [];
  this.otherAssetPaths         = [];
  this.legacyTestFilesToAppend = [];
  this.vendorTestStaticStyles  = [];

  this.trees = this.options.trees;

  this.populateLegacyFiles();
  p.setupRegistry(this);
  this._notifyAddonIncluded();

  if (!this._addonInstalled('loader.js') && !this.options._ignoreMissingLoader) {
    throw new SilentError('The loader.js addon is missing from your project, please add it to `package.json`.');
  }
}

/**
  Initializes the `tests` and `hinting` properties.

  Defaults to `false` unless `ember test` was used or this is *not* a production build.

  @private
  @method _initTestsAndHinting
  @param {Object} options
*/
EmberApp.prototype._initTestsAndHinting = function(options) {
  var testsEnabledDefault = process.env.EMBER_CLI_TEST_COMMAND || !this.isProduction;

  this.tests   = options.hasOwnProperty('tests')   ? options.tests   : testsEnabledDefault;
  this.hinting = options.hasOwnProperty('hinting') ? options.hinting : testsEnabledDefault;
};

/**
  Initializes the `project` property from `options.project` or the
  closest Ember CLI project from the current working directory.

  @private
  @method _initProject
  @param {Object} options
*/
EmberApp.prototype._initProject = function(options) {
  var app = this;

  this.project = options.project || Project.closestSync(process.cwd());

  if (options.configPath) {
    this.project.configPath = function() { return app._resolveLocal(options.configPath); };
  }
};

/**
  Initializes the `options` property from the `options` parameter and
  a set of default values from Ember CLI.

  @private
  @method _initOptions
  @param {Object} options
*/
EmberApp.prototype._initOptions = function(options) {
  var babelOptions = {};

  if (this._addonInstalled('ember-cli-babel')) {
    var amdNameResolver = require('amd-name-resolver').moduleResolve;
    babelOptions = {
      compileModules: true,
      modules: 'amdStrict',
      moduleIds: true,
      resolveModuleSource: amdNameResolver
    };
  }

  this.options = defaultsDeep(options, {
    babel: babelOptions,
    jshintrc: {
      app: this.project.root,
      tests: this._resolveLocal('tests')
    },
    minifyCSS: {
      enabled: !!this.isProduction
    },
    minifyJS: {
      enabled: !!this.isProduction
    },
{'fraction_non_alphanumeric': 0.1382407325878313, 'fraction_numerical': 0.0007044113762437263, 'mean_word_length': 3.476941269215609, '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': '1042490', 'n_tokens_mistral': 3620, 'n_tokens_neox': 3520, 'n_words': 787}