<commit_before>// common-grunt-rules

/// <reference path='../../../third_party/typings/node/node.d.ts' />

import path = require('path');
import fs = require('fs');

export interface RuleConfig {
  // The path where code in this repository should be built in.
  devBuildPath :string;
  // The path from where third party libraries should be copied. e.g. as used by
  // sample apps.
  thirdPartyBuildPath :string;
  // The path to copy modules from this repository into. e.g. as used by sample
  // apps.
  localLibsDestPath :string;
}

export interface JasmineRule {
  src :string[];
  options ?:{
    specs :string[];
    outfile ?:string;
    keepRunner ?:boolean;
  };
}

export interface BrowserifyRule {
  src :string[];
  dest :string;
  options ?:{
    debug ?:boolean;
  };
}

export interface CopyFilesDescription {
  src     : string[];
  dest    : string;
  expand ?: boolean;
  cwd    ?: string;
  nonull ?: boolean;
  onlyIf ?: string; // can be: 'modified'
}

export interface CopyRule {
  files :CopyFilesDescription[];
}

function assertFileExists(filePath:string, info:string = '') {
  if (!fs.existsSync(filePath)) throw new Error(info + '\nMissing file: ' + filePath);
}

function assertFilesExist(filePaths:string[], info?:string) {
  filePaths.forEach((p) => { assertFileExists(p, info); });
}

export class Rule {
  constructor(public config :RuleConfig) {}

  // Grunt Jasmine target creator
  // Assumes that the each spec file is a fully browserified js file.
  public jasmineSpec(name:string, morefiles?:string[]) : JasmineRule {
    if (!morefiles) { morefiles = []; }
    return {
      src: [
        require.resolve('arraybuffer-slice'),
        path.join(path.dirname(require.resolve('es6-promise/package.json')),
                  'dist/promise-1.0.0.js')
      ].concat(morefiles),
      options: {
        specs: [ path.join(this.config.devBuildPath, name, '/**/*.spec.static.js') ],
        outfile: path.join(this.config.devBuildPath, name, '/SpecRunner.html'),
        keepRunner: true,
        template: require('grunt-template-jasmine-istanbul'),
        templateOptions: {
          files: ['**/*', '!node_modules/**'],
          // Output location for coverage results
          coverage: path.join(this.config.devBuildPath, name, 'coverage/results.json'),
          report: [
            { type: 'html',
              options: {
                dir: path.join(this.config.devBuildPath, name, 'coverage')
              }
            },
            { type: 'lcov',
              options: {
                dir: path.join(this.config.devBuildPath, name, 'coverage')
              }
            }
          ]
        }
      }
    }
  }

  // Grunt browserify target creator
  public browserify(filepath:string) : BrowserifyRule {
    var file = path.join(this.config.devBuildPath, filepath + '.js');
    assertFileExists(file, 'browserify:' + filepath);
    return {
      src: [ file ],
      dest: path.join(this.config.devBuildPath, filepath + '.static.js'),
      options: {
        debug: false,
      }
    };
  }

  // Grunt browserify target creator, instrumented for istanbul
  public browserifySpec(filepath:string) : BrowserifyRule {
    var file = path.join(this.config.devBuildPath, filepath + '.spec.js');
    assertFileExists(file, 'browserifySpec:' + filepath);
    return {
      src: [ file ],
      dest: path.join(this.config.devBuildPath, filepath + '.spec.static.js'),
      options: {
        debug: false,
        transform: [['browserify-istanbul',
                    { ignore: ['**/mocks/**', '**/*.spec.js'] }]]
      }
    };
  }

  // Copies libs from npm, local libraries, and third party libraries to the
  // destination folder.
  public copyLibs(copyInfo:{
    // The names of npm libraries who's package exports should be copied (a
    // single JS file, see: https://docs.npmjs.com/files/package.json#main), or
    // the names of individual files from npm modules, using the require.resolve
    // nameing style, see: https://github.com/substack/node-resolve
    npmLibNames ?:string[]
    // Paths within this repository's build directory to be copied.
    pathsFromDevBuild ?:string[]
    // Paths within third party to be copied.
    pathsFromThirdPartyBuild ?:string[]<commit_msg>removed asserts; Grunt crappyness: eval is static before tasks are run<commit_after>// common-grunt-rules

/// <reference path='../../../third_party/typings/node/node.d.ts' />

import path = require('path');
import fs = require('fs');

export interface RuleConfig {
  // The path where code in this repository should be built in.
  devBuildPath :string;
  // The path from where third party libraries should be copied. e.g. as used by
  // sample apps.
  thirdPartyBuildPath :string;
  // The path to copy modules from this repository into. e.g. as used by sample
  // apps.
  localLibsDestPath :string;
}

export interface JasmineRule {
  src :string[];
  options ?:{
    specs :string[];
    outfile ?:string;
    keepRunner ?:boolean;
  };
}

export interface BrowserifyRule {
  src :string[];
  dest :string;
  options ?:{
    debug ?:boolean;
  };
}

export interface CopyFilesDescription {
  src     : string[];
  dest    : string;
  expand ?: boolean;
  cwd    ?: string;
  nonull ?: boolean;
  onlyIf ?: string; // can be: 'modified'
}

export interface CopyRule {
  files :CopyFilesDescription[];
}

export class Rule {
  constructor(public config :RuleConfig) {}

  // Grunt Jasmine target creator
  // Assumes that the each spec file is a fully browserified js file.
  public jasmineSpec(name:string, morefiles?:string[]) : JasmineRule {
    if (!morefiles) { morefiles = []; }
    return {
      src: [
        require.resolve('arraybuffer-slice'),
        path.join(path.dirname(require.resolve('es6-promise/package.json')),
                  'dist/promise-1.0.0.js')
      ].concat(morefiles),
      options: {
        specs: [ path.join(this.config.devBuildPath, name, '/**/*.spec.static.js') ],
        outfile: path.join(this.config.devBuildPath, name, '/SpecRunner.html'),
        keepRunner: true,
        template: require('grunt-template-jasmine-istanbul'),
        templateOptions: {
          files: ['**/*', '!node_modules/**'],
          // Output location for coverage results
          coverage: path.join(this.config.devBuildPath, name, 'coverage/results.json'),
          report: [
            { type: 'html',
              options: {
                dir: path.join(this.config.devBuildPath, name, 'coverage')
              }
            },
            { type: 'lcov',
              options: {
                dir: path.join(this.config.devBuildPath, name, 'coverage')
              }
            }
          ]
        }
      }
    }
  }

  // Grunt browserify target creator
  public browserify(filepath:string) : BrowserifyRule {
    var file = path.join(this.config.devBuildPath, filepath + '.js');
    return {
      src: [ file ],
      dest: path.join(this.config.devBuildPath, filepath + '.static.js'),
      options: {
        debug: false,
      }
    };
  }

  // Grunt browserify target creator, instrumented for istanbul
  public browserifySpec(filepath:string) : BrowserifyRule {
    var file = path.join(this.config.devBuildPath, filepath + '.spec.js');
    return {
      src: [ file ],
      dest: path.join(this.config.devBuildPath, filepath + '.spec.static.js'),
      options: {
        debug: false,
        transform: [['browserify-istanbul',
                    { ignore: ['**/mocks/**', '**/*.spec.js'] }]]
      }
    };
  }

  // Copies libs from npm, local libraries, and third party libraries to the
  // destination folder.
  public copyLibs(copyInfo:{
    // The names of npm libraries who's package exports should be copied (a
    // single JS file, see: https://docs.npmjs.com/files/package.json#main), or
    // the names of individual files from npm modules, using the require.resolve
    // nameing style, see: https://github.com/substack/node-resolve
    npmLibNames ?:string[]
    // Paths within this repository's build directory to be copied.
    pathsFromDevBuild ?:string[]
    // Paths within third party to be copied.
    pathsFromThirdPartyBuild ?:string[]
{'fraction_non_alphanumeric': 0.13465999267488707, 'fraction_numerical': 0.0009766817238432426, 'mean_word_length': 2.5447858070099523, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 6, 'https://': 4, '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': '798556', 'n_tokens_mistral': 2471, 'n_tokens_neox': 2426, 'n_words': 640}