Skip to content

Commit b0a9e8f

Browse files
committed
refactor file structure
1 parent 1f821f9 commit b0a9e8f

File tree

9 files changed

+83
-67
lines changed

9 files changed

+83
-67
lines changed

bin/main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const os = require('os');
1111
const path = require('path');
1212

1313
const { InteractiveSolidityShell, SolidityStatement } = require('../src/handler');
14-
const { convert, multilineInput } = require('../src/utils');
14+
const { convert, multilineInput } = require('../src/cli/utils');
1515

1616
const CONFIG_HOME = path.join(os.homedir(), '.solidity-shell');
1717
const CONFIG_FILE = '.config';

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"solidity-shell": "bin/main.js"
88
},
99
"scripts": {
10-
"updateCompilerList": "node scripts/UpdateCompilerList.js > src/solcVersions.js"
10+
"updateCompilerList": "node scripts/UpdateCompilerList.js > src/compiler/solcVersions.js"
1111
},
1212
"author": {
1313
"name": "tintinweb",

scripts/updateCompilerList.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* @author github.com/tintinweb
55
* @license MIT
66
* */
7-
const { getSolcJsCompilerList } = require('../src/remoteCompiler');
7+
const { getSolcJsCompilerList } = require('../src/compiler/remoteCompiler');
88

99

1010
getSolcJsCompilerList({nightly:false}).then(compilers => {

src/cli/utils.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
'use strict'
2+
/**
3+
* @author github.com/tintinweb
4+
* @license MIT
5+
* */
6+
7+
function convert(str){
8+
switch(str){
9+
case '': return undefined;
10+
case 'true': return true;
11+
case 'false': return false;
12+
}
13+
try {
14+
let num = parseInt(str);
15+
if(!isNaN(num)) return num;
16+
} catch {}
17+
18+
return str;
19+
}
20+
21+
function multilineInput(command){
22+
while (true) {
23+
24+
let numBrOpen = command.split('{').length - 1;
25+
let numBrClose = command.split('}').length - 1;
26+
27+
if (numBrOpen === numBrClose) {
28+
break;
29+
}
30+
31+
const rl = require('readline-sync');
32+
command += '\n' + rl.question("... ").trim()
33+
}
34+
return command;
35+
}
36+
37+
module.exports = {
38+
convert,
39+
multilineInput,
40+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
//autogenerated with # npm run updateCompilerList
88
module.exports.solcVersions = [
9+
"v0.8.11+commit.d7f03943",
910
"v0.8.10+commit.fc410830",
1011
"v0.8.9+commit.e5eed63a",
1112
"v0.8.8+commit.dddeac2f",

src/compiler/utils.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
'use strict'
2+
/**
3+
* @author github.com/tintinweb
4+
* @license MIT
5+
* */
6+
7+
const fs = require('fs');
8+
9+
function readFileCallback(sourcePath, options) {
10+
options = options || {};
11+
if(sourcePath.startsWith("https://")){
12+
if(options.allowHttp){
13+
14+
}
15+
}
16+
else {
17+
const prefixes = [options.basePath ? options.basePath : ""].concat(
18+
options.includePath ? options.includePath : []
19+
);
20+
for (const prefix of prefixes) {
21+
const prefixedSourcePath = (prefix ? prefix + '/' : "") + sourcePath;
22+
if (fs.existsSync(prefixedSourcePath)) {
23+
try {
24+
return { 'contents': fs.readFileSync(prefixedSourcePath).toString('utf8') }
25+
} catch (e) {
26+
return { error: 'Error reading ' + prefixedSourcePath + ': ' + e };
27+
}
28+
}
29+
}
30+
}
31+
return { error: 'File not found inside the base path or any of the include paths.' }
32+
}
33+
34+
module.exports = {
35+
readFileCallback
36+
}

src/handler.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
/** IMPORT */
77
const Web3 = require('web3')
88
const solc = require('solc')
9-
const { getRemoteCompiler } = require('./remoteCompiler.js')
10-
const {readFileCallback} = require('./utils.js')
9+
const { getRemoteCompiler } = require('./compiler/remoteCompiler.js')
10+
const {readFileCallback} = require('./compiler/utils.js')
1111
const path = require('path');
1212

1313
/** CONST */
@@ -278,7 +278,7 @@ contract ${this.settings.templateContractName} {
278278
input.settings.outputSelection['*']['*'] = ['abi', 'evm.bytecode']
279279

280280
function readFileCallbackLambda(sourcePath) {
281-
return readFileCallback(sourcePath, {basePath: process.cwd(), includePath: [path.join(process.cwd(),"./node_modules/")]});
281+
return readFileCallback(sourcePath, {basePath: process.cwd(), includePath: [path.join(process.cwd(),"node_modules")]});
282282
}
283283

284284
const callbacks = { 'import': readFileCallbackLambda };

src/utils.js

Lines changed: 0 additions & 61 deletions
This file was deleted.

0 commit comments

Comments
 (0)