<commit_before>define(function(require, exports, module) {
  'use strict';
  var TSCORE = require("tscore");
  console.log("Loading: extension.manager.js");

  var bowerFileName = "bower.json";
  
  function getExtFolderPath() {
    var extPath = "ext";
    if (isWeb) {
      return extPath;
    }
    if (isCordova) {
      return cordova.file.applicationDirectory + "www/ext/";
      //return location.href.replace(/index.html/gi, extPath);
    }
    if (isChrome) {
      //TODO: chrome fail to read resource://
      return chrome.extension.getURL(extPath); 
    }
    if (isWin) {
      var extRealPath = location.href.replace(/file:\/\/\//gi, "").replace(/index.html/gi, extPath);
      return extRealPath;
    }
    return location.href.replace(/file:\/\//gi, "").replace(/index.html/gi, extPath);
  }

  function loadBowerData(filePath) {
    var resolvePath = (isCordova) ? cordova.file.applicationDirectory : null;
    
    var promise = new Promise(function(resolve, reject) {
      TSCORE.IO.getFileContentPromise(filePath, "text", resolvePath).then(function(data) {
        try {
          var bowerData = JSON.parse(data);
          console.log('Extension descriptor loaded: ' + filePath);
          resolve(bowerData);
        } catch (e) {
          resolve();
        }
      }).catch(function(error) {
        console.error("Error reading " + filePath);
        resolve();
      });
    });
    return promise;
  }

  function loadExtensionData() {
    var extFolderPath = getExtFolderPath();
    //TODO: mozilla loads bower data incorrectly
    if (isFirefox) {
      return Promise.resolve();
    }

    var promise = new Promise(function(resolve, reject) {
      var extensions = [];
      TSCORE.IO.listDirectoryPromise(extFolderPath).then(function(dirList) {
        var readBowerFileWorkers = [];
        for (var i in dirList) {
          var dirItem = dirList[i];
          if (!dirItem.isFile) {
            var filePath = dirItem.path + TSCORE.dirSeparator + bowerFileName;
            readBowerFileWorkers.push(loadBowerData(filePath));
          }
        }
        Promise.all(readBowerFileWorkers).then(function(bowerObjects) {
          bowerObjects.forEach(function(bowerObject) {
            if (bowerObject) {
              extensions.push(bowerObject);
            }
          });
          TSCORE.Config.setExtensions(extensions);
          resolve();
        }).catch(function(err) {
          console.warn("reading of at least one bower.json file failed: " + err);
          resolve();
        });
      }).catch(function(err) {
        console.warn("loadExtensionData failed with error: " + err);
        resolve();
      });
    });

    return promise;
  }

  /*function updatePerspectiveData(perspectiveBowerObject) {
    var perspectives = TSCORE.Config.getActivatedPerspectives();
    perspectives.forEach(function(perspective) {
      if (perspective.id === perspectiveBowerObject.id) {

      }
    });
    TSCORE.Config.setActivatedPerspectives(perspectives);
  }*/

  exports.loadExtensionData = loadExtensionData;
});<commit_msg>cleaning up<commit_after>/* Copyright (c) 2013-2016 The TagSpaces Authors.
 * Use of this source code is governed by the MIT license which can be found in the LICENSE.txt file. */

define(function(require, exports, module) {
  'use strict';
  var TSCORE = require("tscore");
  console.log("Loading: extension.manager.js");

  var bowerFileName = "bower.json";
  
  function getExtFolderPath() {
    var extPath = "ext";
    if (isWeb) {
      return extPath;
    }
    if (isCordova) {
      return cordova.file.applicationDirectory + "www/ext/";
      //return location.href.replace(/index.html/gi, extPath);
    }
    if (isChrome) {
      //TODO: chrome fail to read resource://
      return chrome.extension.getURL(extPath); 
    }
    if (isWin) {
      var extRealPath = location.href.replace(/file:\/\/\//gi, "").replace(/index.html/gi, extPath);
      return extRealPath;
    }
    return location.href.replace(/file:\/\//gi, "").replace(/index.html/gi, extPath);
  }

  function loadBowerData(filePath) {
    var resolvePath = (isCordova) ? cordova.file.applicationDirectory : null;
    
    var promise = new Promise(function(resolve, reject) {
      TSCORE.IO.getFileContentPromise(filePath, "text", resolvePath).then(function(data) {
        try {
          var bowerData = JSON.parse(data);
          console.log('Extension descriptor loaded: ' + filePath);
          resolve(bowerData);
        } catch (e) {
          resolve();
        }
      }).catch(function(error) {
        console.error("Error reading " + filePath);
        resolve();
      });
    });
    return promise;
  }

  function loadExtensionData() {
    var extFolderPath = getExtFolderPath();
    //TODO: mozilla loads bower data incorrectly
    if (isFirefox) {
      return Promise.resolve();
    }

    var promise = new Promise(function(resolve, reject) {
      var extensions = [];
      TSCORE.IO.listDirectoryPromise(extFolderPath).then(function(dirList) {
        var readBowerFileWorkers = [];
        for (var i in dirList) {
          var dirItem = dirList[i];
          if (!dirItem.isFile) {
            var filePath = dirItem.path + TSCORE.dirSeparator + bowerFileName;
            readBowerFileWorkers.push(loadBowerData(filePath));
          }
        }
        Promise.all(readBowerFileWorkers).then(function(bowerObjects) {
          bowerObjects.forEach(function(bowerObject) {
            if (bowerObject) {
              extensions.push(bowerObject);
            }
          });
          TSCORE.Config.setExtensions(extensions);
          resolve();
        }).catch(function(err) {
          console.warn("reading of at least one bower.json file failed: " + err);
          resolve();
        });
      }).catch(function(err) {
        console.warn("loadExtensionData failed with error: " + err);
        resolve();
      });
    });

    return promise;
  }

  exports.loadExtensionData = loadExtensionData;
});
{'fraction_non_alphanumeric': 0.13047825362439594, 'fraction_numerical': 0.0013331111481419764, 'mean_word_length': 2.4794202898550726, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '6483876', 'n_tokens_mistral': 1790, 'n_tokens_neox': 1757, 'n_words': 351}