<commit_before>/*
 * grunt-topcoat
 *
 */

'use strict';

var fs = require('fs'),
    request = require('request');

module.exports = function(grunt) {

    // Please see the grunt documentation for more information regarding task
    // creation: https://github.com/gruntjs/grunt/blob/devel/docs/toc.md
    grunt.registerMultiTask('topcoat', 'Downloads specified repos for use in the TopDoat build process.', function() {
        var _ = grunt.util._,
            async = grunt.util.async,
            done = this.async(),
            spawn = grunt.util.spawn,
            file = grunt.file,
            options = this.options(),
            prefix = "https://github.com/",
            suffix = "/archive/",
            ext = ".zip",
            srcPath = options.srcPath || "src/",
            deps = options.repos,
            controls = deps.controls || {},
            skins = deps.skins || {},
            theme = deps.theme || {};

        var getRepoName = function(key) {
                if (key) return key.split('/')[1];
            };

        var curl = function(url, path, callback) {
            request.get({
                'url': url,
                'encoding': 'binary'
            },
            function(error, result, body) {
                if (!error) {
                    fs.writeFileSync(path, body, 'binary');
                } else {
                    grunt.fail.fatal(error);
                }
                callback(error, body);
            });
        }

        var downloadResources = function(obj, path, callback) {
                var urls = [];
                _.forIn(obj, function(value, key) {
                    var name = getRepoName(key);
                    urls.push({
                        name: name,
                        url: prefix + key + suffix + value + ext
                    });
                });
                grunt.log.writeln("URLS:", urls);

                async.forEachSeries(urls, function(obj, next) {
                    var zipPath = path + obj.name + ext;
                    grunt.log.writeln("Downloading: " + zipPath);
                    curl(obj.url, zipPath, next);
                }, callback);
            }

            // If a version number is given we assume it is a tag and use this url
            // convention:
            // https://github.com/topcoat/topcoat/archive/0.1.0.zip
            //
            // TODO:
            // If no version is given we use the download api with this url convention:
            // https://api.github.com/repos/user/repo/zipball/dev
            //<commit_msg>Removing erroneous logs<commit_after>/*
 * grunt-topcoat
 *
 */

'use strict';

var fs = require('fs'),
    request = require('request');

module.exports = function(grunt) {

    // Please see the grunt documentation for more information regarding task
    // creation: https://github.com/gruntjs/grunt/blob/devel/docs/toc.md
    grunt.registerMultiTask('topcoat', 'Downloads specified repos for use in the TopDoat build process.', function() {
        var _ = grunt.util._,
            async = grunt.util.async,
            done = this.async(),
            spawn = grunt.util.spawn,
            file = grunt.file,
            options = this.options(),
            prefix = "https://github.com/",
            suffix = "/archive/",
            ext = ".zip",
            srcPath = options.srcPath || "src/",
            deps = options.repos,
            controls = deps.controls || {},
            skins = deps.skins || {},
            theme = deps.theme || {};

        var getRepoName = function(key) {
                if (key) return key.split('/')[1];
            };

        var curl = function(url, path, callback) {
            request.get({
                'url': url,
                'encoding': 'binary'
            },
            function(error, result, body) {
                if (!error) {
                    fs.writeFileSync(path, body, 'binary');
                } else {
                    grunt.fail.fatal(error);
                }
                callback(error, body);
            });
        }

        var downloadResources = function(obj, path, callback) {
                var urls = [];
                _.forIn(obj, function(value, key) {
                    var name = getRepoName(key);
                    urls.push({
                        name: name,
                        url: prefix + key + suffix + value + ext
                    });
                });

                async.forEachSeries(urls, function(obj, next) {
                    var zipPath = path + obj.name + ext;
                    grunt.log.writeln("Downloading: " + zipPath);
                    curl(obj.url, zipPath, next);
                }, callback);
            }

            // If a version number is given we assume it is a tag and use this url
            // convention:
            // https://github.com/topcoat/topcoat/archive/0.1.0.zip
            //
            // TODO:
            // If no version is given we use the download api with this url convention:
            // https://api.github.com/repos/user/repo/zipball/dev
            //
{'fraction_non_alphanumeric': 0.12378546443839876, 'fraction_numerical': 0.001554605518849592, 'mean_word_length': 1.28046078865751, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 8, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2708843', 'n_tokens_mistral': 1395, 'n_tokens_neox': 1319, 'n_words': 330}