Unnecessary helpers are deleted

This commit is contained in:
viktor 2017-12-26 17:52:13 +03:00
parent 428b79ceda
commit 0fb7905add
2 changed files with 0 additions and 56 deletions

View File

@ -1,41 +0,0 @@
const fs = require('fs');
const path = require('path');
const glob = require("glob");
const variables = require("./variables.js");
const findUsingLibraryFor = require("./find-libraries-usage.js");
function addLibraries(parentDir, inputFileContent, srcFiles, cb) {
let updatedFileContent = inputFileContent;
let usingLibrariesFound = 0;
findUsingLibraryFor(updatedFileContent, function(usingLibraries) {
for (let k = 0; k < usingLibraries.length; k++) {
let usingLibraryName = usingLibraries[k];
for (let j = 0; j < srcFiles.length; j++) {
let fileContent = fs.readFileSync(srcFiles[j], "utf8");
if (fileContent.indexOf("library " + usingLibraryName) > -1) {
if (!variables.importedSrcFiles.hasOwnProperty(srcFiles[j])) {
updatedFileContent = fileContent + updatedFileContent;
variables.importedSrcFiles[path.basename(srcFiles[j])] = fileContent;
srcFiles.splice(j,1);
usingLibrariesFound++;
}
break;
}
}
}
if (usingLibraries.length > usingLibrariesFound) {
if (parentDir.lastIndexOf("/") > -1) {
parentDir = parentDir.substring(0, parentDir.lastIndexOf("/"));
glob(parentDir + "/**/*.sol", function(err, srcFiles) {
addLibraries(parentDir, inputFileContent, srcFiles, cb);
});
return;
}
}
cb(updatedFileContent);
});
}
module.exports = addLibraries;

View File

@ -1,15 +0,0 @@
function findUsingLibraryFor(content, cb) {
const subStr = "using ";
let usingLibraries = [];
let regex = new RegExp(subStr,"gi");
while ( (result = regex.exec(content)) ) {
let startUsingLibraryFor = result.index;
let endUsingLibraryFor = startUsingLibraryFor + content.substr(startUsingLibraryFor).indexOf(";") + 1;
let dependencyPath = content.substring(startUsingLibraryFor, endUsingLibraryFor);
dependencyPath = dependencyPath.split(subStr)[1].split("for")[0].replace(/\s/g,'');
usingLibraries.indexOf(dependencyPath) === -1 ? usingLibraries.push(dependencyPath) : console.log("This item already exists");
}
cb(usingLibraries);
}
module.exports = findUsingLibraryFor;