<commit_before>module.exports = function(grunt) {

  var path = require('path');
  var fs = require('fs');
  var amberc = require('../../bin/amberc.js');

  /**
     A full example entry for a Gruntfile.js is available below.
     Please note that the verbose level is either specified globally
     or on a target specific level.
     However, it can additionally be triggered on the commandline by
     adding the '-v' or '--verbose' flag.

     Example Gruntfile.js entry:

     amberc: {
       options: {
         amber_dir: process.cwd(),     // REQUIRED
         verbose: true                 // optional
       },
       helloWorld: {
         options: {                             // the 'options' object is optional
           verbose: true
         },
         src: ['projects/HelloWorld/st/HelloWorld.st'], // REQUIRED
         output_dir: 'projects/HelloWorld/js',  // optional
         libraries: 'Canvas',                   // optional
         jsGlobals: ['global1', 'global2'],     // optional
         main_class: 'HelloWorld',              // optional
         output_name: 'helloWorld',             // optional
         amd_namespace: 'MyNamespace',          // optional (default: 'amber')
         main_file: 'myMain.js',                // optional
         output_suffix: 'mySuffix',             // optional
         library_suffix: '-0.9'                 // optional
       },
     },

   */
  grunt.registerMultiTask('amberc', 'Compile Smalltalk files with the amberc compiler', function() {
    // mark task as async task
    var done = this.async();

    var options = this.options({
      amber_dir: undefined,
      verbose: grunt.option('verbose') || false
    });
    this.data.verbose = options.verbose;

    // mark required properties
    this.requiresConfig('amberc.options.amber_dir');
    // raise error on missing source files
    if (this.filesSrc.length === 0) {
        grunt.fail.fatal('No source files to compile or link.');
    }

    // create and initialize amberc
    var compiler = new amberc.Compiler(grunt.config('amberc.options.amber_dir'));

    // generate the amberc configuration out of the given target properties
    var configuration = generateCompilerConfiguration(this.data, this.filesSrc, grunt.config('amberc.options.amber_dir'));

    // run the compiler and call the async callback once finished
    var self = this;
    compiler.main(configuration, function(){
      // signal that task has finished
      done();
    });
  });


  function generateCompilerConfiguration(data, sourceFiles, amber_dir) {
    var configuration = amberc.createDefaults(amber_dir);
    var parameters = [];

    var libraries = data.libraries;
    if (undefined !== libraries) {
      configuration.load = libraries;<commit_msg>grunt-amberc.js: add library_dirs parameter to 'options' which can be used to specify additional library locations<commit_after>module.exports = function(grunt) {

  var path = require('path');
  var fs = require('fs');
  var amberc = require('../../bin/amberc.js');

  /**
     A full example entry for a Gruntfile.js is available below.
     Please note that the verbose level is either specified globally
     or on a target specific level.
     However, it can additionally be triggered on the commandline by
     adding the '-v' or '--verbose' flag.

     Example Gruntfile.js entry:

     amberc: {
       options: {
         amber_dir: process.cwd(),                // REQUIRED
         library_dirs: ['dir1', '/usr/local/js'], // optional
         verbose: true                            // optional
       },
       helloWorld: {
         // this 'options' object is optional as well as all parameters inside it
         // they can be used to override the global 'options'
         options: {
           library_dirs: ['dir1', '/usr/local/js'], // optional
           verbose: true
         },
         src: ['projects/HelloWorld/st/HelloWorld.st'], // REQUIRED
         output_dir: 'projects/HelloWorld/js',  // optional
         libraries: 'Canvas',                   // optional
         jsGlobals: ['global1', 'global2'],     // optional
         main_class: 'HelloWorld',              // optional
         output_name: 'helloWorld',             // optional
         amd_namespace: 'MyNamespace',          // optional (default: 'amber')
         main_file: 'myMain.js',                // optional
         output_suffix: 'mySuffix',             // optional
         library_suffix: '-0.9'                 // optional
       },
     },

   */
  grunt.registerMultiTask('amberc', 'Compile Smalltalk files with the amberc compiler', function() {
    // mark task as async task
    var done = this.async();

    var options = this.options({
      amber_dir: undefined,
      library_dirs: [],
      verbose: grunt.option('verbose') || false
    });
    this.data.verbose = options.verbose;
    this.data.library_dirs = options.library_dirs;

    // mark required properties
    this.requiresConfig('amberc.options.amber_dir');
    // raise error on missing source files
    if (this.filesSrc.length === 0) {
        grunt.fail.fatal('No source files to compile or link.');
    }

    // create and initialize amberc
    var compiler = new amberc.Compiler(grunt.config('amberc.options.amber_dir'));

    // generate the amberc configuration out of the given target properties
    var configuration = generateCompilerConfiguration(this.data, this.filesSrc, grunt.config('amberc.options.amber_dir'));

    // run the compiler and call the async callback once finished
    var self = this;
    compiler.main(configuration, function(){
      // signal that task has finished
      done();
    });
  });


  function generateCompilerConfiguration(data, sourceFiles, amber_dir) {
    var configuration = amberc.createDefaults(amber_dir);
    var parameters = [];

    var libraries = data.libraries;
    if (undefined !== libraries) {
      configuration.load = libraries;
    }
    var library_dirs = data.library_dirs;
    if (undefined !== library_dirs) {
      configuration.jsLibraryDirs = library_dirs;
{'fraction_non_alphanumeric': 0.11193293885601578, 'fraction_numerical': 0.0019723865877712033, 'mean_word_length': 2.2178741406663143, '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': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7120511', 'n_tokens_mistral': 1654, 'n_tokens_neox': 1587, 'n_words': 476}