UNPKG

ui-migration-stats

Version:
1 lines 3.75 kB
'use strict';function _defineProperty(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true})}else{obj[key]=value}return obj}var dirTree=require('directory-tree');var fs=require('fs');var CONSTANTS=require('../stats-constants.js');var CONFIG_KEYS=CONSTANTS.CONFIG_KEYS;var STATS_KEYS=CONSTANTS.STATS_KEYS;var COMMON_KEYS=CONSTANTS.COMMON_KEYS;var getChildren=function getChildren(parent,currentChildren,includeOnlyRegExp){var should_include=true;if(includeOnlyRegExp&&!ifIncludeRegExpMatches(includeOnlyRegExp,parent.path)){should_include=false}if(parent.type===COMMON_KEYS.DIRECTORY){if(should_include){var _currentChildren$chil;currentChildren.children.push((_currentChildren$chil={},_defineProperty(_currentChildren$chil,COMMON_KEYS.PATH,parent.path),_defineProperty(_currentChildren$chil,COMMON_KEYS.LENGTH,parent.children.length),_currentChildren$chil))}parent.children.forEach(function(child){getChildren(child,currentChildren,includeOnlyRegExp)})}else{if(should_include){var _currentChildren$file;currentChildren.files.push((_currentChildren$file={},_defineProperty(_currentChildren$file,COMMON_KEYS.PATH,parent.path),_defineProperty(_currentChildren$file,COMMON_KEYS.EXTENSION,parent.extension.replace('.','')),_currentChildren$file))}}return currentChildren};var getFolderTree=function getFolderTree(path,options,callback){return dirTree(path,options,function(item){callback(item)})};var getPercentage=function getPercentage(firstValue,secondValue,total){return Math.round((firstValue+secondValue)*100/total)};var ifIncludeRegExpMatches=function ifIncludeRegExpMatches(includeOnlyRegExp,path){if(includeOnlyRegExp.test(path)){return true}return false};var ifModuleNameIncludes=function ifModuleNameIncludes(moduleName,modulesList){for(var i=0;i<modulesList.length;i++){if(moduleName.includes(modulesList[i])){return true}}return false};var ifPathExists=function ifPathExists(path){if(!fs.existsSync(path)){return false}return true};var makeDir=function makeDir(path){if(!ifPathExists(path)){fs.mkdirSync(path);return true}return false};var print=function print(text){console.log(text);return};var sortByKeyFunctionBuilder=function sortByKeyFunctionBuilder(key){return function(first,second){if(first[key]<second[key]){return 1}if(first[key]>second[key]){return-1}return 0}};var statsBuilder=function statsBuilder(framework,frameworkConfig,includeSubdirectories){var _framework;var stats=_defineProperty({},framework,(_framework={},_defineProperty(_framework,STATS_KEYS.NAME,frameworkConfig[CONFIG_KEYS.NAME]),_defineProperty(_framework,STATS_KEYS.SRC_PATH,frameworkConfig[CONFIG_KEYS.SRC][CONFIG_KEYS.PATH]),_defineProperty(_framework,STATS_KEYS.SRC_FILETYPES,frameworkConfig[CONFIG_KEYS.SRC][CONFIG_KEYS.FILETYPES]),_defineProperty(_framework,STATS_KEYS.TEST_PATH,frameworkConfig[CONFIG_KEYS.TEST][CONFIG_KEYS.PATH]),_defineProperty(_framework,STATS_KEYS.TEST_FILETYPES,frameworkConfig[CONFIG_KEYS.TEST][CONFIG_KEYS.FILETYPES]),_defineProperty(_framework,STATS_KEYS.SRC_FILES,0),_defineProperty(_framework,STATS_KEYS.TEST_FILES,0),_defineProperty(_framework,STATS_KEYS.PERCENTAGE_FILES,0),_framework));if(includeSubdirectories){var _Object$assign;Object.assign(stats[framework],(_Object$assign={},_defineProperty(_Object$assign,STATS_KEYS.SRC_SUBDIRECTORY,[]),_defineProperty(_Object$assign,STATS_KEYS.TEST_SUBDIRECTORY,[]),_Object$assign))}return stats};module.exports={getChildren:getChildren,getFolderTree:getFolderTree,getPercentage:getPercentage,ifIncludeRegExpMatches:ifIncludeRegExpMatches,ifModuleNameIncludes:ifModuleNameIncludes,ifPathExists:ifPathExists,makeDir:makeDir,print:print,sortByKeyFunctionBuilder:sortByKeyFunctionBuilder,statsBuilder:statsBuilder};