Created
September 6, 2019 19:56
-
-
Save michaelsbradleyjr/4f73d360b44043de38e03e15fe82a963 to your computer and use it in GitHub Desktop.
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
private compile_contracts(contractFiles: any[], cb: Callback<any>) { | |
if (contractFiles.length === 0) { | |
return cb(null, {}); | |
} | |
async.waterfall( | |
[ | |
(next: Callback<any[]>) => { | |
this.plugins.runActionsForEvent( | |
"compiler:contracts:compile:before", | |
contractFiles, | |
(err?: Error | null, files: any[] = []) => { | |
if (err) { | |
return next(err); | |
} | |
next( | |
null, | |
files.map((file: any) => | |
file instanceof File | |
? file | |
: new File({ | |
originalPath: file.path, | |
path: file.path, | |
resolver: (callback: Callback<any>) => { | |
fs.readFile(file.path, { encoding: "utf-8" }, callback); | |
}, | |
type: Types.dappFile | |
}) | |
) | |
); | |
} | |
); | |
}, | |
(files: any[], next: Callback<any>) => { | |
const compiledObject: { [index: string]: any } = {}; | |
const compilerOptions = { | |
isCoverage: this.isCoverage | |
}; | |
async.eachObject( | |
this.getAvailableCompilers(), | |
(extension: string, compilers: any, nextObj: any) => { | |
const matchingFiles = files.filter(this.filesMatchingExtension(extension)); | |
if (matchingFiles.length === 0) { | |
return nextObj(); | |
} | |
async.someLimit( | |
compilers, | |
1, | |
(compiler: any, someCb: Callback<boolean>) => { | |
compiler.call(compiler, matchingFiles, compilerOptions, (err: any, compileResult: any) => { | |
if (err) { | |
return someCb(err); | |
} | |
if (compileResult === false) { | |
// Compiler not compatible, trying the next one | |
return someCb(null, false); | |
} | |
Object.assign(compiledObject, compileResult); | |
someCb(null, true); | |
}); | |
}, | |
(err: Error, result: boolean) => { | |
if (err) { | |
return nextObj(err); | |
} | |
if (!result) { | |
// No compiler was compatible | |
return nextObj( | |
new Error(__("No installed compiler was compatible with your version of %s files", extension)) | |
); | |
} | |
nextObj(); | |
} | |
); | |
}, | |
(err?: Error | null) => { | |
if (err) { | |
return next(err); | |
} | |
files | |
.filter((f: any) => !f.compiled) | |
.forEach((file: any) => { | |
this.logger.warn( | |
__("%s doesn't have a compatible contract compiler. Maybe a plugin exists for it.", file.path) | |
); | |
}); | |
next(null, compiledObject); | |
} | |
); | |
}, | |
(compiledObject: any, next: Callback<any>) => { | |
this.plugins.runActionsForEvent( | |
"compiler:contracts:compile:after", | |
compiledObject, | |
(err?: Error | null, compiledObj: any = {}) => { | |
if (err) { | |
return next(err); | |
} | |
next(null, compiledObj); | |
} | |
); | |
} | |
], | |
(err?: Error | null, compiledObject?: any) => { | |
if (err) { | |
return cb(err); | |
} | |
cb(null, compiledObject || {}); | |
} | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment