<commit_before>var fs = require('fs');
var request = require('request');
var AdmZip = require('adm-zip');
var message = require('./../utils/message');
var cordova = require('./../utils/cordova');
var util = require('./../utils/util');
var download = require('./../utils/download');

module.exports = {
    run : function (){
      var self = this;
      if(commands._.length == 3){
        var url = commands._[2];
        if(!url){
            message.console(message.getMessage("NAME_NOT_FOUND_ADD_ICONS"))
        } else {
          message.console(message.getMessage("START_ADD_ICONS_APP"))
          var name = url.split('/')[url.split('/').length-1];
          name = name.replace(/[^A-Z0-9]/ig, "");
          var fileName = PATH_ICONS+name;
          if(!util.fileExists(fileName+".css")){
            request(url, function (error, response, body) {
              if (!error && response.statusCode == 200) {
                var link = self.getLinkDownload(body);
                download.get(link, function (res){
                  if(res.isValid){
                    res.data.name = name;
                    self.addIcons(res.data, function (res){
                      if(res.isValid){
                        self.generateIconsView(name, function(res){
                          if(res.isValid){
                            message.console(message.getMessage("ADD_ICONS_SUCESS"))
                          }
                        });
                      }
                    })
                  }
                })
              } else {
                message.console(message.getMessage("ADD_ICONS_FAILED"))
              }
            })
          } else {
            message.console(message.getMessage("ICONS_EXISTS_THIS_NAME"))
          }
        }
      } else {
        message.console(message.getMessage("PARAMS_INCORRECT_ADD_ICONS"))
      }
    },
    getLinkDownload: function (html){
      var link = html.split("btn-download-pack")[0];
      link = link.split("href=\"")[link.split("href=\"").length-1];
      link = link.split("\"")[0];
      return link;
    },
    addIcons: function(pack, callback){
      var self = this;
      var result = {isValid:false, msg:""};
      var pathFrom = pack.path;
      var pathTo = pathFrom;
      var pathSplit = pathTo.split("/");
      pathSplit[pathSplit.length-1] = pack.name;
      pack.pathTo = pathSplit.join("/");

      var zip = new AdmZip(pack.path);
      try {
          zip.extractAllTo(pack.pathTo, true);
          var directory = util.getDirectories(pack.pathTo)[0];
          pack.pathDirectory = pack.pathTo + "/" + directory;
          self.renameAndMoveTtf(pack, function(res){
            if(res.isValid){
              self.replaceAndAddCss(pack, function(res){
                callback(res);
                util.deleteFiles([pack.path, pack.pathTo], function(res){});
              });
            }
          });
      } catch (e) {
        message.console(message.getMessage("ADD_ICONS_FAILED"))
        callback(result);
      }
    },
    renameAndMoveTtf: function(pack, callback){
      var result = {isValid:false, msg:""};
      var font = pack.pathDirectory+"/font/Flaticon.ttf";
      var fontNew = PATH_ICONS+pack.name+".ttf";
      util.createIfNotExistDirectory(PATH_ICONS);
      fs.rename(font, fontNew, function(err) {
          if (err) {
            message.console(message.getMessage("ADD_ICONS_FAILED"))
            if(commands.log){
              console.log(err);
              callback(result);
            }<commit_msg>log commands<commit_after>var fs = require('fs');
var request = require('request');
var AdmZip = require('adm-zip');
var message = require('./../utils/message');
var cordova = require('./../utils/cordova');
var util = require('./../utils/util');
var download = require('./../utils/download');

module.exports = {
    run : function (){
      var self = this;
      if(commands._.length == 3){
        var url = commands._[2];
        if(!url){
            message.console(message.getMessage("NAME_NOT_FOUND_ADD_ICONS"))
        } else {
          message.console(message.getMessage("START_ADD_ICONS_APP"))
          var name = url.split('/')[url.split('/').length-1];
          name = name.replace(/[^A-Z0-9]/ig, "");
          var fileName = PATH_ICONS+name;
          if(!util.fileExists(fileName+".css")){
            request(url, function (error, response, body) {
              if (!error && response.statusCode == 200) {
                var link = self.getLinkDownload(body);
                download.get(link, function (res){
                  if(res.isValid){
                    res.data.name = name;
                    self.addIcons(res.data, function (res){
                      if(res.isValid){
                        self.generateIconsView(name, function(res){
                          if(res.isValid){
                            message.console(message.getMessage("ADD_ICONS_SUCESS"))
                          }
                        });
                      }
                    })
                  }
                })
              } else {
                message.console(message.getMessage("ADD_ICONS_FAILED"));
                if(commands.log){
                  console.log(error);
                }
              }
            })
          } else {
            message.console(message.getMessage("ICONS_EXISTS_THIS_NAME"))
          }
        }
      } else {
        message.console(message.getMessage("PARAMS_INCORRECT_ADD_ICONS"))
      }
    },
    getLinkDownload: function (html){
      var link = html.split("btn-download-pack")[0];
      link = link.split("href=\"")[link.split("href=\"").length-1];
      link = link.split("\"")[0];
      return link;
    },
    addIcons: function(pack, callback){
      var self = this;
      var result = {isValid:false, msg:""};
      var pathFrom = pack.path;
      var pathTo = pathFrom;
      var pathSplit = pathTo.split("/");
      pathSplit[pathSplit.length-1] = pack.name;
      pack.pathTo = pathSplit.join("/");

      var zip = new AdmZip(pack.path);
      try {
          zip.extractAllTo(pack.pathTo, true);
          var directory = util.getDirectories(pack.pathTo)[0];
          pack.pathDirectory = pack.pathTo + "/" + directory;
          self.renameAndMoveTtf(pack, function(res){
            if(res.isValid){
              self.replaceAndAddCss(pack, function(res){
                callback(res);
                util.deleteFiles([pack.path, pack.pathTo], function(res){});
              });
            }
          });
      } catch (e) {
        message.console(message.getMessage("ADD_ICONS_FAILED"));
        callback(result);
        if(commands.log){
          console.log(e);
        }
      }
    },
    renameAndMoveTtf: function(pack, callback){
      var result = {isValid:false, msg:""};
      var font = pack.pathDirectory+"/font/Flaticon.ttf";
      var fontNew = PATH_ICONS+pack.name+".ttf";
      util.createIfNotExistDirectory(PATH_ICONS);
      fs.rename(font, fontNew, function(err) {
          if (err) {
            message.console(message.getMessage("ADD_ICONS_FAILED"));
            if(commands.log){
              console.log(err);
              callback(result);
            }
{'fraction_non_alphanumeric': 0.14650648991991164, 'fraction_numerical': 0.0035901684617508974, 'mean_word_length': 1.7394099848714069, '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': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '341435', 'n_tokens_mistral': 2095, 'n_tokens_neox': 2050, 'n_words': 327}