Skip to content
2 changes: 1 addition & 1 deletion apps/remix-ide-e2e/src/tests/compiler_api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ module.exports = {
.addFile('test_jsCompile.js', { content: jsCompile })
.executeScript('remix.exeCurrent()')
.pause(5000)
.journalChildIncludes(`version: '0.6.8+commit.0bbfe453'`)
.journalChildIncludes(`"languageversion": "0.6.8+commit.0bbfe453"`)
},

'Should update the compiler configuration with "setCompilerConfig" API': function (browser: NightwatchBrowser) {
Expand Down
13 changes: 0 additions & 13 deletions apps/remix-ide-e2e/src/tests/terminal.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,24 +35,11 @@ module.exports = {
browser
.waitForElementVisible('*[data-id="terminalCli"]')
.executeScript('remix.help()')
.journalChildIncludes('remix.call(message: {name, key, payload})')
.journalChildIncludes('remix.getFile(path)')
.journalChildIncludes('remix.debug(hash)')
.journalChildIncludes('remix.loadgist(id)')
.journalChildIncludes('remix.loadurl(url)')
.journalChildIncludes('remix.setproviderurl(url)')
.journalChildIncludes('remix.execute(filepath)')
.journalChildIncludes('remix.exeCurrent()')
.journalChildIncludes('remix.help()')
.journalChildIncludes('remix.debugHelp()')
},

'Should execute remix.debugHelp() command': function (browser: NightwatchBrowser) {
browser
.waitForElementVisible('*[data-id="terminalCli"]')
.executeScript('remix.debugHelp()')
.journalChildIncludes('Here are some examples of scripts that can be run (using remix.exeCurrent() or directly from the console)')
.journalChildIncludes('Please see https://www.npmjs.com/package/remix-debug for more informations')
},

'Async/Await Script': function (browser: NightwatchBrowser) {
Expand Down
10 changes: 9 additions & 1 deletion apps/remix-ide/src/app/files/file-explorer.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const globalRegistry = require('../../global/registry')
const queryParams = new QueryParams()
let MENU_HANDLE

function fileExplorer (localRegistry, files, menuItems) {
function fileExplorer (localRegistry, files, menuItems, plugin) {
var self = this
this.events = new EventManager()
// file provider backend
Expand Down Expand Up @@ -292,6 +292,14 @@ function fileExplorer (localRegistry, files, menuItems) {
() => {}
)
}
if (key.endsWith('.js')) {
actions['Run Script'] = async () => {
provider.get(key, (error, content) => {
if (error) return console.log(error)
plugin.call('scriptRunner', 'execute', content)
})
}
}
}
MENU_HANDLE = contextMenu(event, actions)
})
Expand Down
2 changes: 1 addition & 1 deletion apps/remix-ide/src/app/panels/file-panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ module.exports = class Filepanel extends ViewPlugin {
}

function createProvider (key, menuItems) {
return new FileExplorer(self._components.registry, self._deps.fileProviders[key], menuItems)
return new FileExplorer(self._components.registry, self._deps.fileProviders[key], menuItems, self)
}

var fileExplorer = createProvider('browser', ['createNewFile', 'publishToGist', canUpload ? 'uploadFile' : ''])
Expand Down
74 changes: 34 additions & 40 deletions apps/remix-ide/src/app/panels/terminal.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,9 @@ import * as packageJson from '../../../../../package.json'
var yo = require('yo-yo')
var javascriptserialize = require('javascript-serialize')
var jsbeautify = require('js-beautify')
var ethers = require('ethers')
var type = require('component-type')
var vm = require('vm')
var EventManager = require('../../lib/events')
var Web3 = require('web3')
var swarmgw = require('swarmgw')()

var CommandInterpreterAPI = require('../../lib/cmdInterpreterAPI')
var AutoCompletePopup = require('../ui/auto-complete-popup')
Expand Down Expand Up @@ -77,7 +74,6 @@ class Terminal extends Plugin {
self.registerCommand('error', self._blocksRenderer('error'), { activate: true })
self.registerCommand('script', function execute (args, scopedCommands, append) {
var script = String(args[0])
scopedCommands.log(`> ${script}`)
self._shell(script, scopedCommands, function (error, output) {
if (error) scopedCommands.error(error)
else if (output) scopedCommands.log(output)
Expand All @@ -91,9 +87,6 @@ class Terminal extends Plugin {
self.registerFilter('error', basicFilter)
self.registerFilter('script', basicFilter)

self._jsSandboxContext = {}
self._jsSandboxRegistered = {}

if (opts.shell) self._shell = opts.shell // ???
register(self)
}
Expand Down Expand Up @@ -453,18 +446,24 @@ class Terminal extends Plugin {
<div><div> - Welcome to Remix ${packageJson.version} - </div><br>
<div>You can use this terminal for: </div>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use this terminal to:

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

( the last word should not be for but should be to)

<ul class=${css2.ul}>
<li>Checking transactions details and start debugging.</li>
<li>Running JavaScript scripts. The following libraries are accessible:
<li>Check transactions details and start debugging.</li>
<li>Execute JavaScript scripts:
<br />
<i> - Directly input a script in the command line interface </i>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Input a script directly in the command line interface

<br />
<i> - Select a Javascript file in the file explorer and run \`remix.execute()\` in the command line interface </i>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Select a Javascript file in the file explorer and then run `remix.execute()` in the command line interface

<br />
<i> - Right click on a JavaScript file in the file explorer and click \`Run Script\` </i>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right click on a JavaScript file in the file explorer and then click `Run Script`

The following libraries are accessible:
<ul class=${css2.ul}>
<li><a target="_blank" href="https://web3js.readthedocs.io/en/1.0/">web3 version 1.0.0</a></li>
<li><a target="_blank" href="https://docs.ethers.io/ethers.js/html/">ethers.js</a> </li>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<li><a target="_blank" href="https://www.npmjs.com/package/swarmgw">swarmgw</a> </li>
<li>remix (run remix.help() for more info)</li>
</ul>
</li>
<li>Executing common command to interact with the Remix interface (see list of commands above). Note that these commands can also be included and run from a JavaScript script.</li>
<li>Use exports/.register(key, obj)/.remove(key)/.clear() to register and reuse object across script executions.</li>
</ul>

</div>
`

Expand All @@ -481,6 +480,21 @@ class Terminal extends Plugin {

return self._view.el

function wrapScript (script) {
if (script.startsWith('remix.')) return 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(e.message)
}
`
}
function change (event) {
if (self._components.autoCompletePopup.handleAutoComplete(
event,
Expand All @@ -500,7 +514,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()
}
Expand Down Expand Up @@ -624,14 +638,17 @@ class Terminal extends Plugin {
error: 'text-danger' }[mode] // defaults

if (mode) {
const filterUndefined = (el) => el !== undefined && el !== null
return function logger (args, scopedCommands, append) {
var types = args.map(type)
var values = javascriptserialize.apply(null, args).map(function (val, idx) {
var types = args.filter(filterUndefined).map(type)
var values = javascriptserialize.apply(null, args.filter(filterUndefined)).map(function (val, idx) {
if (typeof args[idx] === 'string') val = args[idx]
if (types[idx] === 'element') val = jsbeautify.html(val)
return val
})
append(yo`<span class="${mode}" >${values}</span>`)
if (values.length) {
append(yo`<span class="${mode}" >${values}</span>`)
}
}
} else {
throw new Error('mode is not supported')
Expand Down Expand Up @@ -707,9 +724,8 @@ class Terminal extends Plugin {
// for all the other case, we use the Code Executor plugin
var context = domTerminalFeatures(self, scopedCommands, self.blockchain)
try {
var cmds = vm.createContext(Object.assign(self._jsSandboxContext, context, self._jsSandboxRegistered))
var cmds = vm.createContext(context)
var result = vm.runInContext(script, cmds)
self._jsSandboxContext = Object.assign(cmds, context)
return done(null, result)
} catch (error) {
return done(error.message)
Expand All @@ -726,29 +742,7 @@ class Terminal extends Plugin {

function domTerminalFeatures (self, scopedCommands, blockchain) {
return {
swarmgw,
ethers,
remix: self._components.cmdInterpreter,
web3: new Web3(blockchain.web3().currentProvider),
console: {
log: function () { scopedCommands.log.apply(scopedCommands, arguments) },
info: function () { scopedCommands.info.apply(scopedCommands, arguments) },
warn: function () { scopedCommands.warn.apply(scopedCommands, arguments) },
error: function () { scopedCommands.error.apply(scopedCommands, arguments) }
},
setTimeout: (fn, time) => {
return setTimeout(() => { self._shell('(' + fn.toString() + ')()', scopedCommands, () => {}) }, time)
},
setInterval: (fn, time) => {
return setInterval(() => { self._shell('(' + fn.toString() + ')()', scopedCommands, () => {}) }, time)
},
clearTimeout: clearTimeout,
clearInterval: clearInterval,
exports: {
register: (key, obj) => { self._jsSandboxRegistered[key] = obj },
remove: (key) => { delete self._jsSandboxRegistered[key] },
clear: () => { self._jsSandboxRegistered = {} }
}
remix: self._components.cmdInterpreter
}
}

Expand Down
2 changes: 1 addition & 1 deletion apps/remix-ide/src/app/ui/auto-complete-popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ class AutoCompletePopup {
this.opts.appManager.event.on('activate', async (profile) => {
if (!profile.methods) return
profile.methods.forEach((method) => {
const key = `remix.call({name: '${profile.name}', key:'${method}', payload: []}).then((result) => { console.log(result) }).catch((error) => { console.log(error) })`
const key = `remix.call('${profile.name}', '${method}')`
const keyValue = {}
keyValue[key] = `call ${profile.name} - ${method}`
if (this.extraCommands.includes(keyValue)) return
Expand Down
Loading