|
|
|
@ -12,10 +12,11 @@ export class HardhatClient extends PluginClient { |
|
|
|
|
currentSharedFolder: string |
|
|
|
|
watcher: chokidar.FSWatcher |
|
|
|
|
warnLog: boolean |
|
|
|
|
buildPath: string |
|
|
|
|
|
|
|
|
|
constructor (private readOnly = false) { |
|
|
|
|
super() |
|
|
|
|
this.methods = ['compile'] |
|
|
|
|
this.methods = ['compile', 'sync'] |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
setWebSocket (websocket: WS): void { |
|
|
|
@ -28,6 +29,7 @@ export class HardhatClient extends PluginClient { |
|
|
|
|
|
|
|
|
|
sharedFolder (currentSharedFolder: string): void { |
|
|
|
|
this.currentSharedFolder = currentSharedFolder |
|
|
|
|
this.buildPath = utils.absolutePath('artifacts/build-info', this.currentSharedFolder) |
|
|
|
|
this.listenOnHardhatCompilation() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -58,11 +60,8 @@ export class HardhatClient extends PluginClient { |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
listenOnHardhatCompilation () { |
|
|
|
|
try { |
|
|
|
|
const buildPath = utils.absolutePath('artifacts/build-info', this.currentSharedFolder) |
|
|
|
|
this.watcher = chokidar.watch(buildPath, { depth: 0, ignorePermissionErrors: true, ignoreInitial: true }) |
|
|
|
|
|
|
|
|
|
private async processArtifact () { |
|
|
|
|
const folderFiles = await fs.readdir(this.buildPath) |
|
|
|
|
const compilationResult = { |
|
|
|
|
input: {}, |
|
|
|
|
output: { |
|
|
|
@ -71,13 +70,11 @@ export class HardhatClient extends PluginClient { |
|
|
|
|
}, |
|
|
|
|
solcVersion: null |
|
|
|
|
} |
|
|
|
|
const processArtifact = async () => { |
|
|
|
|
const folderFiles = await fs.readdir(buildPath) |
|
|
|
|
// name of folders are file names
|
|
|
|
|
for (const file of folderFiles) { |
|
|
|
|
if (file.endsWith('.json')) { |
|
|
|
|
console.log('processing hardhat artifact', file) |
|
|
|
|
const path = join(buildPath, file) |
|
|
|
|
const path = join(this.buildPath, file) |
|
|
|
|
const content = await fs.readFile(path, { encoding: 'utf-8' }) |
|
|
|
|
await this.feedContractArtifactFile(content, compilationResult) |
|
|
|
|
} |
|
|
|
@ -90,15 +87,26 @@ export class HardhatClient extends PluginClient { |
|
|
|
|
this.emit('compilationFinished', '', { sources: compilationResult.input }, 'soljson', compilationResult.output, compilationResult.solcVersion)
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
this.watcher.on('change', () => processArtifact()) |
|
|
|
|
this.watcher.on('add', () => processArtifact()) |
|
|
|
|
listenOnHardhatCompilation () { |
|
|
|
|
try { |
|
|
|
|
this.watcher = chokidar.watch(this.buildPath, { depth: 0, ignorePermissionErrors: true, ignoreInitial: true }) |
|
|
|
|
|
|
|
|
|
this.watcher.on('change', () => this.processArtifact()) |
|
|
|
|
this.watcher.on('add', () => this.processArtifact()) |
|
|
|
|
// process the artifact on activation
|
|
|
|
|
processArtifact() |
|
|
|
|
this.processArtifact() |
|
|
|
|
} catch (e) { |
|
|
|
|
console.log(e) |
|
|
|
|
}
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
async sync () { |
|
|
|
|
console.log('syncing from hardhat') |
|
|
|
|
this.processArtifact() |
|
|
|
|
// @ts-ignore
|
|
|
|
|
this.call('terminal', 'log', 'synced with hardhat') |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
async feedContractArtifactFile (artifactContent, compilationResultPart) { |
|
|
|
|
const contentJSON = JSON.parse(artifactContent) |
|
|
|
|
compilationResultPart.solcVersion = contentJSON.solcVersion |
|
|
|
|