allow running js from the CLI

pull/5370/head
yann300 4 years ago
parent cf298e9b59
commit c6f4562f72
  1. 16
      apps/remix-ide/src/app/panels/terminal.js

@ -475,6 +475,20 @@ class Terminal extends Plugin {
return self._view.el return self._view.el
function wrapScript (script) {
return `
try {
const ret = ${script};
if (ret instanceof Promise) {
ret.then((result) => { console.log(result) }).catch((error) => { console.log(error) })
} else {
console.log(ret)
}
} catch (e) {
console.log(error)
}
`
}
function change (event) { function change (event) {
if (self._components.autoCompletePopup.handleAutoComplete( if (self._components.autoCompletePopup.handleAutoComplete(
event, event,
@ -494,7 +508,7 @@ class Terminal extends Plugin {
self._view.input.innerText = '\n' self._view.input.innerText = '\n'
if (script.length) { if (script.length) {
self._cmdHistory.unshift(script) self._cmdHistory.unshift(script)
self.commands.script(script) self.commands.script(wrapScript(script))
} }
self._components.autoCompletePopup.removeAutoComplete() self._components.autoCompletePopup.removeAutoComplete()
} }

Loading…
Cancel
Save