listen on artefactsUpdated instead

auto_exec_v2
yann300 3 years ago
parent 0e17ead810
commit 53fd624176
  1. 26
      apps/remix-ide/src/app/tabs/intelligent-script-executor.js
  2. 2
      libs/remix-core-plugin/src/lib/compiler-metadata.ts

@ -16,20 +16,18 @@ export class IntelligentScriptExecutor extends Plugin {
} }
onActivation () { onActivation () {
this.on('solidity', 'compilationFinished', async (file, source, languageVersion, data, input, version) => { let listen = false
const currentFile = await this.call('fileManager', 'file') setTimeout(() => {
if (data && data.sources[currentFile] && listen = true
data.sources[currentFile].ast && data.sources[currentFile].ast.nodes && data.sources[currentFile].ast.nodes.length) { }, 500)
const nodes = data.sources[currentFile].ast.nodes this.on('compilerMetadata', 'artefactsUpdated', async (fileName, contract) => {
for (let node of nodes) { if (!listen) return
if (node.documentation && node.documentation.text && node.documentation.text.startsWith('@custom:dev-run-script')) { if (contract.object && contract.object.devdoc['custom:dev-run-script']) {
const text = node.documentation.text.replace('@custom:dev-run-script', '').trim() const text = contract.object.devdoc['custom:dev-run-script']
await this.call('terminal', 'log', `running ${text} ...`) await this.call('terminal', 'log', `running ${text} ...`)
const content = await this.call('fileManager', 'readFile', text) const content = await this.call('fileManager', 'readFile', text)
await this.call('udapp', 'clearAllInstances') await this.call('udapp', 'clearAllInstances')
await this.call('scriptRunner', 'execute', content) await this.call('scriptRunner', 'execute', content)
}
}
} }
}) })
} }

@ -42,7 +42,6 @@ export class CompilerMetadata extends Plugin {
await this._setArtefacts(content, contract, path) await this._setArtefacts(content, contract, path)
})() })()
}) })
this.emit('artefactsUpdated')
}) })
} }
@ -105,6 +104,7 @@ export class CompilerMetadata extends Plugin {
abi: contract.object.abi abi: contract.object.abi
} }
await this.call('fileManager', 'writeFile', fileName, JSON.stringify(data, null, '\t')) await this.call('fileManager', 'writeFile', fileName, JSON.stringify(data, null, '\t'))
this.emit('artefactsUpdated', fileName, contract)
} }
_syncContext (contract, metadata) { _syncContext (contract, metadata) {

Loading…
Cancel
Save