@@ -14,7 +14,7 @@ var smtsolver = require('./smtsolver.js');
14
14
process . removeAllListeners ( 'uncaughtException' ) ;
15
15
var commander = require ( 'commander' ) ;
16
16
17
- var program = new commander . Command ( ) ;
17
+ const program = new commander . Command ( ) ;
18
18
program . name ( 'solcjs' ) ;
19
19
program . version ( solc . version ( ) ) ;
20
20
program
@@ -26,18 +26,19 @@ program
26
26
. option ( '--base-path <path>' , 'Automatically resolve all imports inside the given path.' )
27
27
. option ( '-o, --output-dir <output-directory>' , 'Output directory for the contracts.' ) ;
28
28
program . parse ( process . argv ) ;
29
+ const options = program . opts ( ) ;
29
30
30
31
var files = program . args ;
31
- var destination = program . outputDir || '.'
32
+ var destination = options . outputDir || '.'
32
33
33
34
function abort ( msg ) {
34
35
console . error ( msg || 'Error occured' ) ;
35
36
process . exit ( 1 ) ;
36
37
}
37
38
38
39
function readFileCallback ( sourcePath ) {
39
- if ( program . basePath )
40
- sourcePath = program . basePath + '/' + sourcePath ;
40
+ if ( options . basePath )
41
+ sourcePath = options . basePath + '/' + sourcePath ;
41
42
if ( fs . existsSync ( sourcePath ) ) {
42
43
try {
43
44
return { 'contents' : fs . readFileSync ( sourcePath ) . toString ( 'utf8' ) }
@@ -57,7 +58,7 @@ function withUnixPathSeparators(filePath) {
57
58
}
58
59
59
60
function stripBasePath ( sourcePath ) {
60
- const absoluteBasePath = ( program . basePath ? path . resolve ( program . basePath ) : path . resolve ( '.' ) ) ;
61
+ const absoluteBasePath = ( options . basePath ? path . resolve ( options . basePath ) : path . resolve ( '.' ) ) ;
61
62
62
63
// Compared to base path stripping logic in solc this is much simpler because path.resolve()
63
64
// handles symlinks correctly (does not resolve them except in work dir) and strips .. segments
@@ -76,10 +77,10 @@ function stripBasePath(sourcePath) {
76
77
}
77
78
78
79
var callbacks = undefined
79
- if ( program . basePath || ! program . standardJson )
80
+ if ( options . basePath || ! options . standardJson )
80
81
callbacks = { 'import' : readFileCallback } ;
81
82
82
- if ( program . standardJson ) {
83
+ if ( options . standardJson ) {
83
84
var input = fs . readFileSync ( process . stdin . fd ) . toString ( 'utf8' ) ;
84
85
var output = solc . compile ( input , callbacks ) ;
85
86
@@ -112,7 +113,7 @@ if (program.standardJson) {
112
113
process . exit ( 1 ) ;
113
114
}
114
115
115
- if ( ! ( program . bin || program . abi ) ) {
116
+ if ( ! ( options . bin || options . abi ) ) {
116
117
abort ( 'Invalid option selected, must specify either --bin or --abi' ) ;
117
118
}
118
119
@@ -130,7 +131,7 @@ var output = JSON.parse(solc.compile(JSON.stringify({
130
131
language : 'Solidity' ,
131
132
settings : {
132
133
optimizer : {
133
- enabled : program . optimize
134
+ enabled : options . optimize
134
135
} ,
135
136
outputSelection : {
136
137
'*' : {
@@ -173,11 +174,11 @@ for (var fileName in output.contracts) {
173
174
var contractFileName = fileName + ':' + contractName ;
174
175
contractFileName = contractFileName . replace ( / [: ./ \\ ] / g, '_' ) ;
175
176
176
- if ( program . bin ) {
177
+ if ( options . bin ) {
177
178
writeFile ( contractFileName + '.bin' , output . contracts [ fileName ] [ contractName ] . evm . bytecode . object ) ;
178
179
}
179
180
180
- if ( program . abi ) {
181
+ if ( options . abi ) {
181
182
writeFile ( contractFileName + '.abi' , JSON . stringify ( output . contracts [ fileName ] [ contractName ] . abi ) ) ;
182
183
}
183
184
}
0 commit comments