From c6f4562f7220244b07cf170ec45481546d1bdb55 Mon Sep 17 00:00:00 2001 From: yann300 Date: Tue, 15 Sep 2020 12:38:14 +0200 Subject: [PATCH] allow running js from the CLI --- apps/remix-ide/src/app/panels/terminal.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/apps/remix-ide/src/app/panels/terminal.js b/apps/remix-ide/src/app/panels/terminal.js index 70ec084784..c3c38876d2 100644 --- a/apps/remix-ide/src/app/panels/terminal.js +++ b/apps/remix-ide/src/app/panels/terminal.js @@ -475,6 +475,20 @@ class Terminal extends Plugin { 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) { if (self._components.autoCompletePopup.handleAutoComplete( event, @@ -494,7 +508,7 @@ class Terminal extends Plugin { self._view.input.innerText = '\n' if (script.length) { self._cmdHistory.unshift(script) - self.commands.script(script) + self.commands.script(wrapScript(script)) } self._components.autoCompletePopup.removeAutoComplete() }