Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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 || {});
- }
- );
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement