<commit_before>/// <reference path="../defs/tsd.d.ts"/>
/// <reference path="./modules/interfaces.d.ts"/>
/// <reference path="../defs/csproj2ts/csproj2ts.d.ts" />
/*
 * grunt-ts
 * Licensed under the MIT license.
 */
// Typescript imports
var _ = require('lodash');
var path = require('path');
var fs = require('fs');
var csproj2ts = require('csproj2ts');
// Modules of grunt-ts
var utils = require('./modules/utils');
var compileModule = require('./modules/compile');
var referenceModule = require('./modules/reference');
var amdLoaderModule = require('./modules/amdLoader');
var html2tsModule = require('./modules/html2ts');
var templateCacheModule = require('./modules/templateCache');
var transformers = require('./modules/transformers');
// plain vanilla imports
var Promise = require('es6-promise').Promise;
/**
 * Time a function and print the result.
 *
 * @param makeIt the code to time
 * @returns the result of the block of code
 */
function timeIt(makeIt) {
    var starttime = new Date().getTime();
    var it = makeIt();
    var endtime = new Date().getTime();
    return {
        it: it,
        time: endtime - starttime
    };
}
/**
 * Run a map operation async in series (simplified)
 */
function asyncSeries(arr, iter) {
    arr = arr.slice(0);
    var memo = [];
    // Run one at a time
    return new Promise(function (resolve, reject) {
        var next = function () {
            if (arr.length === 0) {
                resolve(memo);
                return;
            }
            Promise.cast(iter(arr.shift())).then(function (res) {
                memo.push(res);
                next();
            }, reject);
        };
        next();
    });
}
function pluginFn(grunt) {
    /////////////////////////////////////////////////////////////////////
    // The grunt task
    ////////////////////////////////////////////////////////////////////
    // Note: this function is called once for each target
    // so task + target options are a bit blurred inside this function
    grunt.registerMultiTask('ts', 'Compile TypeScript files', function () {
        var currenttask = this;
        // make async
        var done = currenttask.async();
        var watch;
        // tracks which index in the task "files" property is next for processing
        var filesCompilationIndex = 0;
        // setup default options
        var options = currenttask.options({
            allowBool: false,
            allowImportModule: false,
            compile: true,
            declaration: false,
            mapRoot: '',
            module: null,
            noImplicitAny: false,
            noResolve: false,
            comments: null,
            removeComments: null,
            sourceMap: true,
            sourceRoot: '',
            target: 'es5',
            verbose: false,
            fast: 'watch',
            compiler: '',
            htmlOutputTemplate: null,
            htmlModuleTemplate: '<%= filename %>',
            htmlVarTemplate: '<%= ext %>',
            htmlOutDir: null,
            htmlOutDirFlatten: false,
            failOnTypeErrors: true,
            noEmitOnError: false,
            preserveConstEnums: false,
            suppressImplicitAnyIndexErrors: false
        });
        // get unprocessed templates from configuration
        var rawTaskOptions = (grunt.config.getRaw(currenttask.name + '.options') || {});
        var rawTargetConfig = (grunt.config.getRaw(currenttask.name + '.' + currenttask.target) || {});
        var rawTargetOptions = (grunt.config.getRaw(currenttask.name + '.' + currenttask.target + '.options') || {});
        var vs = getVSSettings(rawTargetConfig);
        if (vs) {
            csproj2ts.getTypeScriptSettings({
                ProjectFileName: vs.project,
                ActiveConfiguration: vs.config || undefined
            }).then(function (vsConfig) {
                proceed(vsConfig);
            }).catch(function (error) {
                var errormessage;
                if (error.errno === 34) {
                    errormessage = 'In task "' + currenttask.target + '" - could not find VS project at "' + error.path + '".';
                }
                else {
                    errormessage = 'In task "' + currenttask.target + '".  Error #' + error.errno + '.  ' + error;
                }
                grunt.fail.warn(errormessage, error.errno);
                done(error);
            });
        }
        else {
            proceed();
        }
        function proceed(vsProjectTypeScriptSettings) {
            if (vsProjectTypeScriptSettings && !vs.ignoreSettings) {
                options.declaration = utils.firstElementWithValue([vsProjectTypeScriptSettings.GeneratesDeclarations, options.declaration]);
                options.mapRoot = utils.firstElementWithValue([vsProjectTypeScriptSettings.MapRoot, options.mapRoot]);
                options.module = utils.firstElementWithValue([vsProjectTypeScriptSettings.ModuleKind, options.module]);
                if (options.module === 'none') {
                    options.module = null;
                }
                options.noEmitOnError = utils.firstElementWithValue([vsProjectTypeScriptSettings.NoEmitOnError, options.noEmitOnError]);
                options.noImplicitAny = utils.firstElementWithValue([vsProjectTypeScriptSettings.NoImplicitAny, options.noImplicitAny]);
                options.noResolve = utils.firstElementWithValue([vsProjectTypeScriptSettings.NoResolve, options.noResolve]);
                rawTargetConfig.outDir = utils.firstElementWithValue([vsProjectTypeScriptSettings.OutDir, rawTargetConfig.outDir]);
                rawTargetConfig.out = utils.firstElementWithValue([vsProjectTypeScriptSettings.OutFile, rawTargetConfig.out]);
                options.preserveConstEnums = utils.firstElementWithValue([vsProjectTypeScriptSettings.PreserveConstEnums, options.preserveConstEnums]);
                options.removeComments = utils.firstElementWithValue([vsProjectTypeScriptSettings.RemoveComments, options.removeComments]);
                if (options.removeComments) {
                    options.comments = null;
                }
                else {
                    options.comments = true;
                }
                options.sourceMap = utils.firstElementWithValue([vsProjectTypeScriptSettings.SourceMap, options.sourceMap]);
                options.sourceRoot = utils.firstElementWithValue([vsProjectTypeScriptSettings.SourceRoot, options.sourceRoot]);
                options.suppressImplicitAnyIndexErrors = utils.firstElementWithValue([vsProjectTypeScriptSettings.SuppressImplicitAnyIndexErrors, options.suppressImplicitAnyIndexErrors]);
                options.target = utils.firstElementWithValue([vsProjectTypeScriptSettings.Target, options.target]);
            }
            var srcFromVS_RelativePathsFromGruntFile = [];
            if (vsProjectTypeScriptSettings) {
                // make all VS project paths relative to the gruntfile.
                var absolutePathToVSProjectFolder = path.resolve(vsProjectTypeScriptSettings.VSProjectDetails.ProjectFileName, '..');
                if (!vs.ignoreFiles) {
                    _.map(_.uniq(vsProjectTypeScriptSettings.files), function (file) {
                        var absolutePathToFile = path.normalize(path.join(absolutePathToVSProjectFolder, file));
                        var relativePathToFile = path.relative(path.resolve('.'), absolutePathToFile).replace(new RegExp('\\' + path.sep, 'g'), '/');
                        if (srcFromVS_RelativePathsFromGruntFile.indexOf(relativePathToFile) === -1 && currenttask.filesSrc.indexOf(relativePathToFile) === -1) {
                            srcFromVS_RelativePathsFromGruntFile.push(relativePathToFile);
                        }
                    });
                    if (srcFromVS_RelativePathsFromGruntFile.length > 0) {
                        currenttask.files.push({ src: srcFromVS_RelativePathsFromGruntFile });
                    }
                }
                if (!vs.ignoreSettings) {
                    if (vsProjectTypeScriptSettings.OutDir) {
                        rawTargetConfig.outDir = path.relative(path.resolve('.'), path.normalize(path.join(absolutePathToVSProjectFolder, vsProjectTypeScriptSettings.OutDir)));
                    }
                    if (vsProjectTypeScriptSettings.OutFile) {
                        rawTargetConfig.out = path.relative(path.resolve('.'), path.normalize(path.join(absolutePathToVSProjectFolder, vsProjectTypeScriptSettings.OutFile)));
                    }
                }
            }
            options.htmlModuleTemplate = rawTargetOptions.htmlModuleTemplate || rawTaskOptions.htmlModuleTemplate;
            options.htmlVarTemplate = rawTargetOptions.htmlVarTemplate || rawTaskOptions.htmlVarTemplate;
            options.htmlOutDir = rawTargetConfig.htmlOutDir;
            options.htmlOutDirFlatten = rawTargetConfig.htmlOutDirFlatten;
            // fix the properly cased options to their appropriate values
            options.allowBool = 'allowbool' in options ? options['allowbool'] : options.allowBool;
            options.allowImportModule = 'allowimportmodule' in options ? options['allowimportmodule'] : options.allowImportModule;
            options.sourceMap = 'sourcemap' in options ? options['sourcemap'] : options.sourceMap;
            // Warn the user of invalid values
            if (options.fast !== 'watch' && options.fast !== 'always' && options.fast !== 'never') {
                console.warn(('"fast" needs to be one of : "watch" (default) | "always" | "never" but you provided: ' + options.fast).magenta);
                if (currenttask.files) {
                    options.fast = 'never'; // to keep things simple, we are not supporting fast with files.
                }
                else {
                    options.fast = 'watch';
                }
            }
            if ((options.fast === 'watch' || options.fast === 'always') && rawTargetConfig.files) {
                grunt.log.writeln(('Warning: Task "' + currenttask.target + '" is attempting to use fast compilation with "files".  This is not currently supported.  Setting "fast" to "never".').magenta);
                options.fast = 'never';
            }
            logBadConfigWithFiles(rawTargetConfig, currenttask, rawTargetOptions);
            if (!options.htmlModuleTemplate) {
                // use default value
                options.htmlModuleTemplate = '<%= filename %>';
            }
            if (!options.htmlVarTemplate) {
                // use default value
                options.htmlVarTemplate = '<%= ext %>';
            }<commit_msg>fixing it - thanks ben8p<commit_after>/// <reference path="../defs/tsd.d.ts"/>
/// <reference path="./modules/interfaces.d.ts"/>
/// <reference path="../defs/csproj2ts/csproj2ts.d.ts" />
/*
 * grunt-ts
 * Licensed under the MIT license.
 */
// Typescript imports
var _ = require('lodash');
var path = require('path');
var fs = require('fs');
var csproj2ts = require('csproj2ts');
// Modules of grunt-ts
var utils = require('./modules/utils');
var compileModule = require('./modules/compile');
var referenceModule = require('./modules/reference');
var amdLoaderModule = require('./modules/amdLoader');
var html2tsModule = require('./modules/html2ts');
var templateCacheModule = require('./modules/templateCache');
var transformers = require('./modules/transformers');
// plain vanilla imports
var Promise = require('es6-promise').Promise;
/**
 * Time a function and print the result.
 *
 * @param makeIt the code to time
 * @returns the result of the block of code
 */
function timeIt(makeIt) {
    var starttime = new Date().getTime();
    var it = makeIt();
    var endtime = new Date().getTime();
    return {
        it: it,
        time: endtime - starttime
    };
}
/**
 * Run a map operation async in series (simplified)
 */
function asyncSeries(arr, iter) {
    arr = arr.slice(0);
    var memo = [];
    // Run one at a time
    return new Promise(function (resolve, reject) {
        var next = function () {
            if (arr.length === 0) {
                resolve(memo);
                return;
            }
            Promise.cast(iter(arr.shift())).then(function (res) {
                memo.push(res);
                next();
            }, reject);
        };
        next();
    });
}
function pluginFn(grunt) {
    /////////////////////////////////////////////////////////////////////
    // The grunt task
    ////////////////////////////////////////////////////////////////////
    // Note: this function is called once for each target
    // so task + target options are a bit blurred inside this function
    grunt.registerMultiTask('ts', 'Compile TypeScript files', function () {
        var currenttask = this;
        // make async
        var done = currenttask.async();
        var watch;
        // tracks which index in the task "files" property is next for processing
        var filesCompilationIndex = 0;
        // setup default options
        var options = currenttask.options({
            allowBool: false,
            allowImportModule: false,
            compile: true,
            declaration: false,
            mapRoot: '',
            module: null,
            noImplicitAny: false,
            noResolve: false,
            comments: null,
            removeComments: null,
            sourceMap: true,
            sourceRoot: '',
            target: 'es5',
            verbose: false,
            fast: 'watch',
            compiler: '',
            htmlOutputTemplate: null,
            htmlModuleTemplate: '<%= filename %>',
            htmlVarTemplate: '<%= ext %>',
            htmlOutDir: null,
            htmlOutDirFlatten: false,
            failOnTypeErrors: true,
            noEmitOnError: false,
            preserveConstEnums: false,
            suppressImplicitAnyIndexErrors: false
        });
        // get unprocessed templates from configuration
        var rawTaskOptions = (grunt.config.getRaw(currenttask.name + '.options') || {});
        var rawTargetConfig = (grunt.config.getRaw(currenttask.name + '.' + currenttask.target) || {});
        var rawTargetOptions = (grunt.config.getRaw(currenttask.name + '.' + currenttask.target + '.options') || {});
        var vs = getVSSettings(rawTargetConfig);
        if (vs) {
            csproj2ts.getTypeScriptSettings({
                ProjectFileName: vs.project,
                ActiveConfiguration: vs.config || undefined
            }).then(function (vsConfig) {
                proceed(vsConfig);
            }).catch(function (error) {
                var errormessage;
                if (error.errno === 34) {
                    errormessage = 'In task "' + currenttask.target + '" - could not find VS project at "' + error.path + '".';
                }
                else {
                    errormessage = 'In task "' + currenttask.target + '".  Error #' + error.errno + '.  ' + error;
                }
                grunt.fail.warn(errormessage, error.errno);
                done(error);
            });
        }
        else {
            proceed();
        }
        function proceed(vsProjectTypeScriptSettings) {
            if (vsProjectTypeScriptSettings && !vs.ignoreSettings) {
                options.declaration = utils.firstElementWithValue([vsProjectTypeScriptSettings.GeneratesDeclarations, options.declaration]);
                options.mapRoot = utils.firstElementWithValue([vsProjectTypeScriptSettings.MapRoot, options.mapRoot]);
                options.module = utils.firstElementWithValue([vsProjectTypeScriptSettings.ModuleKind, options.module]);
                if (options.module === 'none') {
                    options.module = null;
                }
                options.noEmitOnError = utils.firstElementWithValue([vsProjectTypeScriptSettings.NoEmitOnError, options.noEmitOnError]);
                options.noImplicitAny = utils.firstElementWithValue([vsProjectTypeScriptSettings.NoImplicitAny, options.noImplicitAny]);
                options.noResolve = utils.firstElementWithValue([vsProjectTypeScriptSettings.NoResolve, options.noResolve]);
                rawTargetConfig.outDir = utils.firstElementWithValue([vsProjectTypeScriptSettings.OutDir, rawTargetConfig.outDir]);
                rawTargetConfig.out = utils.firstElementWithValue([vsProjectTypeScriptSettings.OutFile, rawTargetConfig.out]);
                options.preserveConstEnums = utils.firstElementWithValue([vsProjectTypeScriptSettings.PreserveConstEnums, options.preserveConstEnums]);
                options.removeComments = utils.firstElementWithValue([vsProjectTypeScriptSettings.RemoveComments, options.removeComments]);
                if (options.removeComments) {
                    options.comments = null;
                }
                else {
                    options.comments = true;
                }
                options.sourceMap = utils.firstElementWithValue([vsProjectTypeScriptSettings.SourceMap, options.sourceMap]);
                options.sourceRoot = utils.firstElementWithValue([vsProjectTypeScriptSettings.SourceRoot, options.sourceRoot]);
                options.suppressImplicitAnyIndexErrors = utils.firstElementWithValue([vsProjectTypeScriptSettings.SuppressImplicitAnyIndexErrors, options.suppressImplicitAnyIndexErrors]);
                options.target = utils.firstElementWithValue([vsProjectTypeScriptSettings.Target, options.target]);
            }
            var srcFromVS_RelativePathsFromGruntFile = [];
            if (vsProjectTypeScriptSettings) {
                // make all VS project paths relative to the gruntfile.
                var absolutePathToVSProjectFolder = path.resolve(vsProjectTypeScriptSettings.VSProjectDetails.ProjectFileName, '..');
                if (!vs.ignoreFiles) {
                    _.map(_.uniq(vsProjectTypeScriptSettings.files), function (file) {
                        var absolutePathToFile = path.normalize(path.join(absolutePathToVSProjectFolder, file));
                        var relativePathToFile = path.relative(path.resolve('.'), absolutePathToFile).replace(new RegExp('\\' + path.sep, 'g'), '/');
                        if (srcFromVS_RelativePathsFromGruntFile.indexOf(relativePathToFile) === -1 && currenttask.filesSrc.indexOf(relativePathToFile) === -1) {
                            srcFromVS_RelativePathsFromGruntFile.push(relativePathToFile);
                        }
                    });
                    if (srcFromVS_RelativePathsFromGruntFile.length > 0) {
                        currenttask.files.push({ src: srcFromVS_RelativePathsFromGruntFile });
                    }
                }
                if (!vs.ignoreSettings) {
                    if (vsProjectTypeScriptSettings.OutDir) {
                        rawTargetConfig.outDir = path.relative(path.resolve('.'), path.normalize(path.join(absolutePathToVSProjectFolder, vsProjectTypeScriptSettings.OutDir)));
                    }
                    if (vsProjectTypeScriptSettings.OutFile) {
                        rawTargetConfig.out = path.relative(path.resolve('.'), path.normalize(path.join(absolutePathToVSProjectFolder, vsProjectTypeScriptSettings.OutFile)));
                    }
                }
            }
            options.htmlOutputTemplate = rawTargetOptions.htmlOutputTemplate || rawTaskOptions.htmlOutputTemplate;
            options.htmlModuleTemplate = rawTargetOptions.htmlModuleTemplate || rawTaskOptions.htmlModuleTemplate;
            options.htmlVarTemplate = rawTargetOptions.htmlVarTemplate || rawTaskOptions.htmlVarTemplate;
            options.htmlOutDir = rawTargetConfig.htmlOutDir;
            options.htmlOutDirFlatten = rawTargetConfig.htmlOutDirFlatten;
            // fix the properly cased options to their appropriate values
            options.allowBool = 'allowbool' in options ? options['allowbool'] : options.allowBool;
            options.allowImportModule = 'allowimportmodule' in options ? options['allowimportmodule'] : options.allowImportModule;
            options.sourceMap = 'sourcemap' in options ? options['sourcemap'] : options.sourceMap;
            // Warn the user of invalid values
            if (options.fast !== 'watch' && options.fast !== 'always' && options.fast !== 'never') {
                console.warn(('"fast" needs to be one of : "watch" (default) | "always" | "never" but you provided: ' + options.fast).magenta);
                if (currenttask.files) {
                    options.fast = 'never'; // to keep things simple, we are not supporting fast with files.
                }
                else {
                    options.fast = 'watch';
                }
            }
            if ((options.fast === 'watch' || options.fast === 'always') && rawTargetConfig.files) {
                grunt.log.writeln(('Warning: Task "' + currenttask.target + '" is attempting to use fast compilation with "files".  This is not currently supported.  Setting "fast" to "never".').magenta);
                options.fast = 'never';
            }
            logBadConfigWithFiles(rawTargetConfig, currenttask, rawTargetOptions);
            if (!options.htmlModuleTemplate) {
                // use default value
                options.htmlModuleTemplate = '<%= filename %>';
            }
            if (!options.htmlVarTemplate) {
                // use default value
                options.htmlVarTemplate = '<%= ext %>';
            }
{'fraction_non_alphanumeric': 0.12084339587590563, 'fraction_numerical': 0.001625487646293888, 'mean_word_length': 2.069127708095781, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 19, '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': '3040076', 'n_tokens_mistral': 5388, 'n_tokens_neox': 5240, 'n_words': 1106}