-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Profiles are stored in a directory
- Loading branch information
Showing
7 changed files
with
170 additions
and
150 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
const clc = require("cli-color"); | ||
|
||
module.exports.parseData = (contract, part) => { | ||
let contractName = clc.cyanBright(contract.name); | ||
if(contract.type == 'LibraryStatement') | ||
contractName = contractName + clc.white(' -lib'); | ||
|
||
let funcName = null; | ||
if(part.type == 'ConstructorDeclaration') | ||
funcName = 'constructor'; | ||
else if(part.type == 'FunctionDeclaration'){ | ||
funcName = part.name || ''; | ||
} | ||
|
||
let params = []; | ||
if(part.params) { | ||
part.params.forEach(function(param) { | ||
if(param.storage_location) | ||
params.push(param.literal.literal + ' ' + clc.cyan(param.storage_location)); | ||
else | ||
params.push(param.literal.literal); | ||
}); | ||
funcName += '(' + params.join(',') + ')'; | ||
} | ||
else { | ||
//Check fallback | ||
if(!funcName && !part.name && !part.params && !part.returnParams) | ||
funcName = '()' + clc.white(' -fallback'); | ||
else | ||
funcName += '()'; | ||
} | ||
|
||
// Default is public | ||
let visibility = clc.magentaBright("public"); | ||
let viewOrPure = ''; | ||
let returns = []; | ||
let custom = []; | ||
|
||
if(part.modifiers) { | ||
part.modifiers.forEach(function(mod) { | ||
switch(mod.name) { | ||
case "public": | ||
break; | ||
case "private": | ||
visibility = clc.redBright("private"); | ||
break; | ||
case "internal": | ||
visibility = clc.red("internal"); | ||
break; | ||
case "external": | ||
visibility = clc.magenta("external"); | ||
break; | ||
case "view": | ||
viewOrPure = clc.yellow("view"); | ||
break; | ||
case "pure": | ||
viewOrPure = clc.yellowBright("pure"); | ||
break; | ||
default: | ||
custom.push(mod.name); | ||
} | ||
}); | ||
} | ||
if(part.returnParams) { | ||
part.returnParams.params.forEach(function(param) { | ||
if(param.storage_location) | ||
returns.push(param.literal.literal + ' ' + clc.cyan(param.storage_location)); | ||
else | ||
returns.push(param.literal.literal); | ||
}); | ||
} | ||
|
||
return { | ||
contractName: contractName, | ||
functionName: clc.blueBright(funcName), | ||
visibility : visibility, | ||
viewOrPure : viewOrPure, | ||
returns : clc.white(returns), | ||
modifiers : clc.white(custom) | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
const path = require('path'), | ||
fs = require('fs'); | ||
|
||
var regEx = { | ||
pragma : /(pragma solidity (.+?);)/g, | ||
import : /import ['"](.+?)['"];/g | ||
}; | ||
|
||
var processedFiles = []; | ||
|
||
var processFile = async(file) => { | ||
|
||
if (processedFiles.indexOf(file) !== -1) | ||
return; | ||
|
||
processedFiles.push(file); | ||
let result = ''; | ||
|
||
let contents = fs.readFileSync(file, { encoding: 'utf-8' }); | ||
contents = contents.replace(regEx.pragma, '').trim(); | ||
let imports = await processImports(file, contents); | ||
|
||
for (let i = 0; i < imports.length; i++) { | ||
result += imports[i] + '\n\n'; | ||
} | ||
contents = contents.replace(regEx.import, '').trim(); | ||
result += contents; | ||
return result; | ||
} | ||
|
||
var processImports = async (file, content) => { | ||
let group=''; | ||
let result = []; | ||
regEx.import.exec(''); // Resetting state of RegEx | ||
while (group = regEx.import.exec(content)) { | ||
let _importFile = group[1]; | ||
let filePath = path.join(path.dirname(file), _importFile); | ||
filePath = path.normalize(filePath); | ||
let fileContents = await processFile(filePath); | ||
if (fileContents) { | ||
result.push(fileContents); | ||
} | ||
} | ||
return result; | ||
|
||
} | ||
|
||
var getPragma = async(path) => { | ||
let contents = fs.readFileSync(path, { encoding: 'utf-8' }); | ||
let group = regEx.pragma.exec(contents); | ||
return group && group[1]; | ||
} | ||
|
||
module.exports.process = processFile; | ||
module.exports.getPragma = getPragma; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,9 @@ | ||
const path = require('path'), | ||
fs = require('fs'); | ||
|
||
var regEx = { | ||
pragma : /(pragma solidity (.+?);)/g, | ||
import : /import ['"](.+?)['"];/g | ||
}; | ||
|
||
var processedFiles = []; | ||
|
||
var processFile = async(file) => { | ||
|
||
if (processedFiles.indexOf(file) !== -1) | ||
return; | ||
|
||
processedFiles.push(file); | ||
let result = ''; | ||
|
||
let contents = fs.readFileSync(file, { encoding: 'utf-8' }); | ||
contents = contents.replace(regEx.pragma, '').trim(); | ||
let imports = await processImports(file, contents); | ||
|
||
for (let i = 0; i < imports.length; i++) { | ||
result += imports[i] + '\n\n'; | ||
} | ||
contents = contents.replace(regEx.import, '').trim(); | ||
result += contents; | ||
return result; | ||
} | ||
|
||
var processImports = async (file, content) => { | ||
let group=''; | ||
let result = []; | ||
regEx.import.exec(''); // Resetting state of RegEx | ||
while (group = regEx.import.exec(content)) { | ||
let _importFile = group[1]; | ||
let filePath = path.join(path.dirname(file), _importFile); | ||
filePath = path.normalize(filePath); | ||
let fileContents = await processFile(filePath); | ||
if (fileContents) { | ||
result.push(fileContents); | ||
} | ||
} | ||
return result; | ||
|
||
} | ||
|
||
var getPragma = async(path) => { | ||
let contents = fs.readFileSync(path, { encoding: 'utf-8' }); | ||
let group = regEx.pragma.exec(contents); | ||
return group && group[1]; | ||
} | ||
|
||
module.exports.processFile = processFile; | ||
module.exports.getPragma = getPragma; | ||
const data = require('./data'), | ||
file = require('./file'), | ||
profile = require('./profile'); | ||
|
||
module.exports = { | ||
data, | ||
file, | ||
profile | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
const path = require('path'), | ||
fs = require('fs'); | ||
|
||
|
||
module.exports.store = (data, contractName) => { | ||
if(!fs.existsSync(path.join(process.cwd(), '/profiles'))) | ||
fs.mkdirSync(path.join(process.cwd(), '/profiles')); | ||
let fileData = data.replace( | ||
/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g, ''); // clearing color formatting | ||
|
||
fs.writeFileSync(path.join(process.cwd(), 'profiles', contractName + '_Profile.txt'), fileData); | ||
} |