|
|
|
@ -3,7 +3,7 @@ import { PluginClient } from '@remixproject/plugin' |
|
|
|
|
import * as chokidar from 'chokidar' |
|
|
|
|
import * as utils from '../utils' |
|
|
|
|
import * as fs from 'fs-extra' |
|
|
|
|
import { basename, join } from 'path' |
|
|
|
|
import { join } from 'path' |
|
|
|
|
const { spawn } = require('child_process') // eslint-disable-line
|
|
|
|
|
|
|
|
|
|
export class HardhatClient extends PluginClient { |
|
|
|
@ -63,6 +63,7 @@ export class HardhatClient extends PluginClient { |
|
|
|
|
private async processArtifact() { |
|
|
|
|
// resolving the files
|
|
|
|
|
const folderFiles = await fs.readdir(this.buildPath) |
|
|
|
|
const targetsSynced = [] |
|
|
|
|
// name of folders are file names
|
|
|
|
|
for (const file of folderFiles) { // ["artifacts/contracts/Greeter.sol/"]
|
|
|
|
|
const contractFilePath = join(this.buildPath, file) |
|
|
|
@ -87,14 +88,18 @@ export class HardhatClient extends PluginClient { |
|
|
|
|
const jsonStd = JSON.parse(contentStd) |
|
|
|
|
compilationResult.target = jsonStd.sourceName |
|
|
|
|
|
|
|
|
|
// this is the full compilation result
|
|
|
|
|
console.log('Processing Hardhat artifact for file: ', file) |
|
|
|
|
targetsSynced.push(compilationResult.target) |
|
|
|
|
const path = join(contractFilePath, jsonDbg.buildInfo) |
|
|
|
|
const content = await fs.readFile(path, { encoding: 'utf-8' }) |
|
|
|
|
|
|
|
|
|
await this.feedContractArtifactFile(content, compilationResult) |
|
|
|
|
} |
|
|
|
|
if (compilationResult.target) { |
|
|
|
|
// we are only interested in the contracts that are in the target of the compilation
|
|
|
|
|
compilationResult.output = { |
|
|
|
|
...compilationResult.output, |
|
|
|
|
contracts: { [compilationResult.target]: compilationResult.output.contracts[compilationResult.target] } |
|
|
|
|
} |
|
|
|
|
this.emit('compilationFinished', compilationResult.target, { sources: compilationResult.input }, 'soljson', compilationResult.output, compilationResult.solcVersion) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -104,6 +109,11 @@ export class HardhatClient extends PluginClient { |
|
|
|
|
this.call('terminal', 'log', 'receiving compilation result from Hardhat') |
|
|
|
|
this.warnLog = true |
|
|
|
|
} |
|
|
|
|
if (targetsSynced.length) { |
|
|
|
|
console.log(`Processing artifacts for files: ${[...new Set(targetsSynced)].join(', ')}`) |
|
|
|
|
// @ts-ignore
|
|
|
|
|
this.call('terminal', 'log', `synced with Hardhat: ${[...new Set(targetsSynced)].join(', ')}`) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
listenOnHardhatCompilation() { |
|
|
|
@ -122,8 +132,6 @@ export class HardhatClient extends PluginClient { |
|
|
|
|
async sync() { |
|
|
|
|
console.log('syncing from Hardhat') |
|
|
|
|
this.processArtifact() |
|
|
|
|
// @ts-ignore
|
|
|
|
|
this.call('terminal', 'log', 'synced with Hardhat') |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
async feedContractArtifactFile(artifactContent, compilationResultPart) { |
|
|
|
|