<commit_before>import * as LogManager from 'aurelia-logging';
import {Container} from 'aurelia-dependency-injection';
import {Loader} from 'aurelia-loader';
import {BindingLanguage,ResourceCoordinator, ViewSlot, ResourceRegistry} from 'aurelia-templating';
import {EventAggregator, includeEventsIn} from 'aurelia-event-aggregator';

var logger = LogManager.getLogger('aurelia');

export class Aurelia {
  constructor(loader, container, resources){
    this.loader = loader || Loader.createDefaultLoader();
    this.container = container || new Container();
    this.resources = resources || new ResourceRegistry();
    this.resourcesToLoad = [];

    this.withInstance(Aurelia, this);
    this.withInstance(Loader, this.loader);
    this.withInstance(ResourceRegistry, this.resources);
    this.withInstance(EventAggregator, includeEventsIn(this));
  }

  withInstance(type, instance){
    this.container.registerInstance(type, instance);
    return this;
  }

  withSingleton(type, implementation){
    this.container.registerSingleton(type, implementation);
    return this;
  }

  withBindingLanguage(languageType){
    this.container.registerSingleton(BindingLanguage, languageType);
    return this;
  }

  withPlugins(config, baseUrl){
    logger.error('withPlugins is not yet implemented');
    return this;
  }

  withResources(resources){
    if(Array.isArray(resources)){
      this.resourcesToLoad = this.resourcesToLoad.concat(resources);
    }else{
      this.resourcesToLoad = this.resourcesToLoad.concat(Array.prototype.slice.call(arguments));
    }

    return this;
  }

  start(){
    if(this.started){
      return;
    }

    this.started = true;
    logger.info('Aurelia Starting');

    if(!this.container.hasHandler(BindingLanguage)){
      logger.error('You must configure Aurelia with a BindingLanguage implementation.');
    }

    //TODO: configure plugins

    return this.container.get(ResourceCoordinator)
      .importResources(this.resourcesToLoad).then(resources => {
        resources.forEach(x => x.register(this.resources));
        logger.info('Aurelia Started');
        return this;
      });
  }

  setRoot(root, applicationHost){
    if (!applicationHost || typeof applicationHost == 'string') {
      this.host = document.getElementById(applicationHost || 'applicationHost') || document.body;
    } else {
      this.host = applicationHost;
    }

    this.host.aurelia = this;

    return this.container.get(ResourceCoordinator)
      .loadElement(root).then(type => {
        this.root = type.create(this.container);<commit_msg>feat(framework): enable plugin loading and config<commit_after>import * as LogManager from 'aurelia-logging';
import {Container} from 'aurelia-dependency-injection';
import {Loader} from 'aurelia-loader';
import {BindingLanguage,ResourceCoordinator, ViewSlot, ResourceRegistry} from 'aurelia-templating';
import {EventAggregator, includeEventsIn} from 'aurelia-event-aggregator';

var logger = LogManager.getLogger('aurelia');

function loadPlugins(loader, plugins){
  var toLoad = [], i, ii, current;

  for(i = 0, ii = plugins.length; i < ii; ++i){
    current = plugins[i];
    logger.debug(`Loading plugin ${current.moduleId}.`);
    toLoad.push(loader.loadModule(current.moduleId).then(exportedValue => {
      if('install' in exportedValue){
        return exportedValue.install(current.config || {}).then(() =>{
          logger.debug(`Installed plugin ${current.moduleId}.`);
        });
      }else{
        logger.debug(`Loaded plugin ${current.moduleId}.`);
      }
    }));
  }

  return Promise.all(toLoad);
}

export class Aurelia {
  constructor(loader, container, resources){
    this.loader = loader || Loader.createDefaultLoader();
    this.container = container || new Container();
    this.resources = resources || new ResourceRegistry();
    this.resourcesToLoad = [];
    this.plugins = [];

    this.withInstance(Aurelia, this);
    this.withInstance(Loader, this.loader);
    this.withInstance(ResourceRegistry, this.resources);
    this.withInstance(EventAggregator, includeEventsIn(this));
  }

  withInstance(type, instance){
    this.container.registerInstance(type, instance);
    return this;
  }

  withSingleton(type, implementation){
    this.container.registerSingleton(type, implementation);
    return this;
  }

  withBindingLanguage(languageType){
    this.container.registerSingleton(BindingLanguage, languageType);
    return this;
  }

  withPlugin(moduleId, config){
    this.plugins.push({moduleId:moduleId, config:config});
    return this;
  }

  withResources(resources){
    if(Array.isArray(resources)){
      this.resourcesToLoad = this.resourcesToLoad.concat(resources);
    }else{
      this.resourcesToLoad = this.resourcesToLoad.concat(Array.prototype.slice.call(arguments));
    }

    return this;
  }

  start(){
    if(this.started){
      return;
    }

    this.started = true;
    logger.info('Aurelia Starting');

    if(!this.container.hasHandler(BindingLanguage)){
      logger.error('You must configure Aurelia with a BindingLanguage implementation.');
    }

    return loadPlugins(this.loader, this.plugins).then(() => {
      return this.container.get(ResourceCoordinator)
        .importResources(this.resourcesToLoad).then(resources => {
          resources.forEach(x => x.register(this.resources));
          logger.info('Aurelia Started');
          return this;
        });
    });
  }

  setRoot(root, applicationHost){
    if (!applicationHost || typeof applicationHost == 'string') {
      this.host = document.getElementById(applicationHost || 'applicationHost') || document.body;
    } else {
      this.host = applicationHost;
    }

    this.host.aurelia = this;

    return this.container.get(ResourceCoordinator)
      .loadElement(root).then(type => {
        this.root = type.create(this.container);
{'fraction_non_alphanumeric': 0.12828834984625898, 'fraction_numerical': 0.00017082336863682952, 'mean_word_length': 3.883236030025021, 'pattern_counts': {'":': 0, '<': 4, '<?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': '3571926', 'n_tokens_mistral': 1675, 'n_tokens_neox': 1640, 'n_words': 312}