@@ -38,7 +38,9 @@ program
38
38
. option ( '--abi' , 'ABI of the contracts.' )
39
39
. option ( '--standard-json' , 'Turn on Standard JSON Input / Output mode.' )
40
40
. option ( '--base-path <path>' , 'Automatically resolve all imports inside the given path.' )
41
- . option ( '-o, --output-dir <output-directory>' , 'Output directory for the contracts.' ) ;
41
+ . option ( '-o, --output-dir <output-directory>' , 'Output directory for the contracts.' )
42
+ . option ( '-p, --pretty-json' , 'Pretty-print all JSON output.' , false )
43
+ . option ( '-v, --verbose' , 'More detailed console output.' , false ) ;
42
44
43
45
program . parse ( process . argv ) ;
44
46
const options = program . opts ( ) ;
@@ -91,18 +93,30 @@ function stripBasePath(sourcePath) {
91
93
return withUnixPathSeparators ( relativeSourcePath ) ;
92
94
}
93
95
96
+ function toFormattedJson ( input ) {
97
+ return JSON . stringify ( input , null , program . prettyJson ? 4 : 0 ) ;
98
+ }
99
+
100
+ function reformatJsonIfRequested ( inputJson ) {
101
+ return ( program . prettyJson ? toFormattedJson ( JSON . parse ( inputJson ) ) : inputJson ) ;
102
+ }
103
+
94
104
var callbacks = undefined
95
105
if ( options . basePath || ! options . standardJson )
96
106
callbacks = { 'import' : readFileCallback } ;
97
107
98
108
if ( options . standardJson ) {
99
109
var input = fs . readFileSync ( process . stdin . fd ) . toString ( 'utf8' ) ;
100
- var output = solc . compile ( input , callbacks ) ;
110
+ if ( program . verbose )
111
+ console . log ( '>>> Compiling:\n' + reformatJsonIfRequested ( input ) + "\n" )
112
+ var output = reformatJsonIfRequested ( solc . compile ( input , callbacks ) ) ;
101
113
102
114
try {
103
115
var inputJSON = smtchecker . handleSMTQueries ( JSON . parse ( input ) , JSON . parse ( output ) , smtsolver . smtSolver ) ;
104
116
if ( inputJSON ) {
105
- output = solc . compile ( JSON . stringify ( inputJSON ) , callbacks ) ;
117
+ if ( program . verbose )
118
+ console . log ( '>>> Retrying compilation with SMT:\n' + toFormattedJson ( inputJSON ) + "\n" )
119
+ output = reformatJsonIfRequested ( solc . compile ( JSON . stringify ( inputJSON ) , callbacks ) ) ;
106
120
}
107
121
}
108
122
catch ( e ) {
@@ -118,9 +132,11 @@ if (options.standardJson) {
118
132
outputJSON . errors = [ ]
119
133
}
120
134
outputJSON . errors . push ( addError ) ;
121
- output = JSON . stringify ( outputJSON ) ;
135
+ output = toFormattedJson ( outputJSON ) ;
122
136
}
123
137
138
+ if ( program . verbose )
139
+ console . log ( '>>> Compilation result:' )
124
140
console . log ( output ) ;
125
141
process . exit ( 0 ) ;
126
142
} else if ( files . length === 0 ) {
@@ -142,7 +158,7 @@ for (var i = 0; i < files.length; i++) {
142
158
}
143
159
}
144
160
145
- var output = JSON . parse ( solc . compile ( JSON . stringify ( {
161
+ const cliInput = {
146
162
language : 'Solidity' ,
147
163
settings : {
148
164
optimizer : {
@@ -156,7 +172,10 @@ var output = JSON.parse(solc.compile(JSON.stringify({
156
172
}
157
173
} ,
158
174
sources : sources
159
- } ) , callbacks ) ) ;
175
+ } ;
176
+ if ( program . verbose )
177
+ console . log ( '>>> Compiling:\n' + toFormattedJson ( cliInput ) + "\n" )
178
+ var output = JSON . parse ( solc . compile ( JSON . stringify ( cliInput ) , callbacks ) ) ;
160
179
161
180
let hasError = false ;
162
181
@@ -195,7 +214,7 @@ for (var fileName in output.contracts) {
195
214
}
196
215
197
216
if ( options . abi ) {
198
- writeFile ( contractFileName + '.abi' , JSON . stringify ( output . contracts [ fileName ] [ contractName ] . abi ) ) ;
217
+ writeFile ( contractFileName + '.abi' , toFormattedJson ( output . contracts [ fileName ] [ contractName ] . abi ) ) ;
199
218
}
200
219
}
201
220
}
0 commit comments