Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Commit

Permalink
Rework compile loading to reflect new workflow compile output
Browse files Browse the repository at this point in the history
  • Loading branch information
fainashalts committed Sep 23, 2020
1 parent 01dcabf commit de3d745
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions packages/db/src/loaders/schema/artifactsLoader.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { TruffleDB } from "@truffle/db/db";
import { WorkflowCompile } from "@truffle/workflow-compile";
import { ContractObject } from "@truffle/contract-schema/spec";
import * as fse from "fs-extra";
import path from "path";
import Config from "@truffle/config";
Expand All @@ -15,6 +13,11 @@ import {
AssignProjectNames,
ResolveProjectName
} from "@truffle/db/loaders/resources/projects";
import {
WorkflowCompileResult,
CompiledContract
} from "@truffle/compile-common/src/types";
import WorkflowCompile from "@truffle/workflow-compile";

type NetworkLinkObject = {
[name: string]: string;
Expand Down Expand Up @@ -84,24 +87,26 @@ export class ArtifactsLoader {
}

async load(): Promise<void> {
const result = await WorkflowCompile.compile(this.config);
const result: WorkflowCompileResult = await WorkflowCompile.compile(
this.config
);

const { project, compilations } = await this.db.loadCompilations(result);

//map contracts and contract instances to compiler
await Promise.all(
compilations.map(async ({ id }) => {
compilations.map(async ({ id }, index) => {
const {
data: {
workspace: {
compilation: { compiler, processedSources }
compilation: { processedSources }
}
}
} = await this.db.query(GetCompilation, { id });

const networks = await this.loadNetworks(
project.id,
result.compilations[compiler.name].contracts,
result.compilations[index].contracts,
this.config["artifacts_directory"],
this.config["contracts_directory"]
);
Expand All @@ -110,10 +115,11 @@ export class ArtifactsLoader {
.map(processedSource => processedSource.contracts)
.flat();

const contracts = result.compilations[
compiler.name
].contracts.map(({ contractName }) =>
processedSourceContracts.find(({ name }) => name === contractName)
let contracts = [];
result.compilations[index].contracts.map(({ contractName }) =>
contracts.push(
processedSourceContracts.find(({ name }) => name === contractName)
)
);

if (networks[0].length) {
Expand Down Expand Up @@ -164,7 +170,7 @@ export class ArtifactsLoader {

async loadNetworks(
projectId: string,
contracts: Array<ContractObject>,
contracts: Array<CompiledContract>,
artifacts: string,
workingDirectory: string
) {
Expand Down

0 comments on commit de3d745

Please sign in to comment.