set compilation target for foundry

pull/2956/head
yann300 2 years ago
parent 3e94815c39
commit 6fb563f051
  1. 28
      libs/remixd/src/services/foundryClient.ts

@ -16,7 +16,7 @@ export class FoundryClient extends PluginClient {
constructor (private readOnly = false) { constructor (private readOnly = false) {
super() super()
this.methods = ['compile'] this.methods = ['compile', 'sync']
} }
setWebSocket (websocket: WS): void { setWebSocket (websocket: WS): void {
@ -61,32 +61,33 @@ export class FoundryClient extends PluginClient {
} }
private async processArtifact () { private async processArtifact () {
const folderFiles = await fs.readdir(this.buildPath) const folderFiles = await fs.readdir(this.buildPath) // "out" folder
const compilationResult = {
input: {},
output: {
contracts: {},
sources: {}
},
solcVersion: null
}
// name of folders are file names // name of folders are file names
for (const file of folderFiles) { for (const file of folderFiles) {
await this.readContract(join(this.buildPath, file), compilationResult) const path = join(this.buildPath, file) // out/Counter.sol/
const compilationResult = {
input: {},
output: {
contracts: {},
sources: {}
},
solcVersion: null,
compilationTarget: null
}
await this.readContract(path, compilationResult)
this.emit('compilationFinished', compilationResult.compilationTarget, { sources: compilationResult.input } , 'soljson', compilationResult.output, compilationResult.solcVersion)
} }
if (!this.warnlog) { if (!this.warnlog) {
// @ts-ignore // @ts-ignore
this.call('terminal', 'log', 'receiving compilation result from foundry') this.call('terminal', 'log', 'receiving compilation result from foundry')
this.warnlog = true this.warnlog = true
} }
this.emit('compilationFinished', '', { sources: compilationResult.input } , 'soljson', compilationResult.output, compilationResult.solcVersion)
} }
listenOnFoundryCompilation () { listenOnFoundryCompilation () {
try { try {
this.watcher = chokidar.watch(this.buildPath, { depth: 3, ignorePermissionErrors: true, ignoreInitial: true }) this.watcher = chokidar.watch(this.buildPath, { depth: 3, ignorePermissionErrors: true, ignoreInitial: true })
this.watcher.on('change', async (f: string) => this.processArtifact()) this.watcher.on('change', async (f: string) => this.processArtifact())
this.watcher.on('add', async (f: string) => this.processArtifact()) this.watcher.on('add', async (f: string) => this.processArtifact())
// process the artifact on activation // process the artifact on activation
@ -121,6 +122,7 @@ export class FoundryClient extends PluginClient {
} }
} else { } else {
const contractName = basename(path).replace('.json', '') const contractName = basename(path).replace('.json', '')
compilationResultPart.compilationTarget = contentJSON.ast.absolutePath
// extract data // extract data
if (!compilationResultPart.output['sources'][contentJSON.ast.absolutePath]) compilationResultPart.output['sources'][contentJSON.ast.absolutePath] = {} if (!compilationResultPart.output['sources'][contentJSON.ast.absolutePath]) compilationResultPart.output['sources'][contentJSON.ast.absolutePath] = {}
compilationResultPart.output['sources'][contentJSON.ast.absolutePath] = { compilationResultPart.output['sources'][contentJSON.ast.absolutePath] = {

Loading…
Cancel
Save