improve script executor

auto_exec_v2
yann300 3 years ago
parent 1153444101
commit d2612ebed5
  1. 38
      apps/remix-ide/src/app/tabs/intelligent-script-executor.js
  2. 60
      apps/remix-ide/src/app/tabs/intelligent-script-executor.ts

@ -1,38 +0,0 @@
import { Plugin } from '@remixproject/engine'
import * as packageJson from '../../../../../package.json'
export const profile = {
name: 'intelligentScriptExecutor',
displayName: 'Intelligent Script Executor',
description: 'after each compilation, run the script defined in Natspec.',
methods: [],
version: packageJson.version,
kind: 'none'
}
export class IntelligentScriptExecutor extends Plugin {
constructor () {
super(profile)
}
onActivation () {
let listen = false
setTimeout(() => {
listen = true
}, 500)
this.on('compilerMetadata', 'artefactsUpdated', async (fileName, contract) => {
if (!listen) return
if (contract.object && contract.object.devdoc['custom:dev-run-script']) {
const text = contract.object.devdoc['custom:dev-run-script']
await this.call('terminal', 'log', `running ${text} ...`)
const content = await this.call('fileManager', 'readFile', text)
await this.call('udapp', 'clearAllInstances')
await this.call('scriptRunner', 'execute', content)
}
})
}
onDeactivation () {
this.off('solidity', 'compilationFinished')
}
}

@ -0,0 +1,60 @@
import { Plugin } from '@remixproject/engine'
import * as packageJson from '../../../../../package.json'
export const profile = {
name: 'intelligentScriptExecutor',
displayName: 'Intelligent Script Executor',
description: 'after each compilation, run the script defined in Natspec.',
methods: [],
version: packageJson.version,
kind: 'none'
}
type listener = (event: KeyboardEvent) => void
export class IntelligentScriptExecutor extends Plugin {
executionListener: listener
targetFileName: string
constructor () {
super(profile)
this.executionListener = async (e) => {
// ctrl+e or command+e
const file = await this.call('fileManager', 'file')
if ((e.metaKey || e.ctrlKey) && e.keyCode === 69 && file !== '') {
if (file.endsWith('.sol')) {
e.preventDefault()
this.targetFileName = file
await this.call('solidity', 'compile', file)
} else if (file.endsWith('.js')) {
e.preventDefault()
this.runScript(file)
}
}
}
}
async runScript (fileName) {
await this.call('terminal', 'log', `running ${fileName} ...`)
const content = await this.call('fileManager', 'readFile', fileName)
await this.call('udapp', 'clearAllInstances')
await this.call('scriptRunner', 'execute', content)
}
onActivation () {
window.document.addEventListener('keydown', this.executionListener)
this.on('compilerMetadata', 'artefactsUpdated', async (fileName, contract) => {
if (this.targetFileName === contract.file && contract.object && contract.object.devdoc['custom:dev-run-script']) {
const file = contract.object.devdoc['custom:dev-run-script']
if (file) this.runScript(file)
}
this.targetFileName = null
})
}
onDeactivation () {
window.document.removeEventListener('keydown', this.executionListener)
this.off('compilerMetadata', 'artefactsUpdated')
}
}
Loading…
Cancel
Save