Skip to content

Commit 25b83af

Browse files
authored
Merge pull request #638 from ethereum/addgitService
Add git service in remixd & use it from the terminal
2 parents 09ce1a6 + 7d1fe50 commit 25b83af

File tree

14 files changed

+137
-30
lines changed

14 files changed

+137
-30
lines changed

apps/remix-ide-e2e/src/tests/remixd.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,17 @@ module.exports = {
6969
.clickLaunchIcon('solidity')
7070
.setSolidityCompilerVersion('soljson-v0.6.2+commit.bacdbe57.js') // open-zeppelin moved to pragma ^0.6.0
7171
.testContracts('test_import_node_modules_with_github_import.sol', sources[4]['browser/test_import_node_modules_with_github_import.sol'], ['ERC20', 'test11'])
72+
},
73+
74+
'Run git status': function (browser) {
75+
browser
76+
.executeScript('git status')
77+
.pause(3000)
78+
.journalLastChildIncludes('On branch ')
79+
},
80+
81+
'Close Remixd': function (browser) {
82+
browser
7283
.clickLaunchIcon('pluginManager')
7384
.scrollAndClick('#pluginManager article[id="remixPluginManagerListItem_remixd"] button')
7485
.end()

apps/remix-ide/src/app.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,8 @@ Please make a backup of your contracts and start using http://remix.ethereum.org
390390
debug,
391391
analysis,
392392
test,
393-
filePanel.remixdHandle
393+
filePanel.remixdHandle,
394+
filePanel.gitHandle
394395
])
395396

396397
try {
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { WebsocketPlugin } from '@remixproject/engine-web'
2+
import * as packageJson from '../../../../../package.json'
3+
4+
const profile = {
5+
name: 'git',
6+
displayName: 'Git',
7+
url: 'ws://127.0.0.1:65521',
8+
methods: ['execute'],
9+
description: 'Using Remixd daemon, allow to access git API',
10+
kind: 'other',
11+
version: packageJson.version
12+
}
13+
14+
export class GitHandle extends WebsocketPlugin {
15+
constructor () {
16+
super(profile)
17+
}
18+
}

apps/remix-ide/src/app/files/remixd-handle.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ export class RemixdHandle extends WebsocketPlugin {
4040
deactivate () {
4141
this.fileSystemExplorer.hide()
4242
if (super.socket) super.deactivate()
43+
this.call('manager', 'deactivatePlugin', 'git')
4344
this.locahostProvider.close((error) => {
4445
if (error) console.log(error)
4546
})
@@ -51,7 +52,8 @@ export class RemixdHandle extends WebsocketPlugin {
5152
}
5253

5354
async canceled () {
54-
this.appManager.ensureDeactivated('remixd')
55+
this.call('manager', 'deactivatePlugin', 'remixd')
56+
this.call('manager', 'deactivatePlugin', 'git')
5557
}
5658

5759
/**
@@ -82,6 +84,7 @@ export class RemixdHandle extends WebsocketPlugin {
8284
}
8385
}, 3000)
8486
this.locahostProvider.init(_ => this.fileSystemExplorer.ensureRoot())
87+
this.call('manager', 'activatePlugin', 'git')
8588
}
8689
}
8790
if (this.locahostProvider.isConnected()) {

apps/remix-ide/src/app/panels/file-panel.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ var yo = require('yo-yo')
55
var EventManager = require('../../lib/events')
66
var FileExplorer = require('../files/file-explorer')
77
var { RemixdHandle } = require('../files/remixd-handle.js')
8+
var { GitHandle } = require('../files/git-handle.js')
89
var globalRegistry = require('../../global/registry')
910
var css = require('./styles/file-panel-styles')
1011

@@ -60,6 +61,7 @@ module.exports = class Filepanel extends ViewPlugin {
6061
var fileSystemExplorer = createProvider('localhost')
6162

6263
self.remixdHandle = new RemixdHandle(fileSystemExplorer, self._deps.fileProviders.localhost, appManager)
64+
self.gitHandle = new GitHandle()
6365

6466
const explorers = yo`
6567
<div>

apps/remix-ide/src/app/panels/styles/terminal-styles.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ var css = csjs`
5454
padding : 1ch;
5555
margin-top : 2ch;
5656
}
57+
.block > pre {
58+
max-height : 200px;
59+
}
5760
.cli {
5861
line-height : 1.7em;
5962
font-family : monospace;

apps/remix-ide/src/app/panels/terminal.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,8 @@ class Terminal extends Plugin {
485485
return self._view.el
486486

487487
function wrapScript (script) {
488-
if (script.startsWith('remix.')) return script
488+
const isKnownScript = ['remix.', 'git'].some(prefix => script.trim().startsWith(prefix))
489+
if (isKnownScript) return script
489490
return `
490491
try {
491492
const ret = ${script};
@@ -746,10 +747,16 @@ class Terminal extends Plugin {
746747
}
747748
}
748749
try {
749-
await this.call('scriptRunner', 'execute', script)
750+
let result
751+
if (script.trim().startsWith('git')) {
752+
result = await this.call('git', 'execute', script)
753+
} else {
754+
result = await this.call('scriptRunner', 'execute', script)
755+
}
756+
if (result) self.commands.html(yo`<pre>${result}</pre>`)
750757
done()
751758
} catch (error) {
752-
done(error.message)
759+
done(error.message || error)
753760
}
754761
}
755762
}

apps/remix-ide/src/app/ui/auto-complete-popup.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ class AutoCompletePopup {
3131
self._elementsToShow = 4
3232
self._selectedElement = 0
3333
this.extraCommands = []
34-
this.extendAutocompletion()
3534
}
3635

3736
render () {

apps/remix-ide/src/remixAppManager.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const requiredModules = [ // services + layout views + system views
1111
'terminal', 'settings', 'pluginManager']
1212

1313
export function isNative (name) {
14-
const nativePlugins = ['vyper', 'workshops', 'debugger']
14+
const nativePlugins = ['vyper', 'workshops', 'debugger', 'remixd']
1515
return nativePlugins.includes(name) || requiredModules.includes(name)
1616
}
1717

@@ -34,7 +34,7 @@ export class RemixAppManager extends PluginManager {
3434

3535
async canDeactivatePlugin (from, to) {
3636
if (requiredModules.includes(to.name)) return false
37-
return from.name === 'manager'
37+
return isNative(from.name)
3838
}
3939

4040
async canCall (from, to, method, message) {
@@ -70,11 +70,6 @@ export class RemixAppManager extends PluginManager {
7070
this.event.emit('deactivate', plugin)
7171
}
7272

73-
async ensureDeactivated (apiName) {
74-
await this.deactivatePlugin(apiName)
75-
this.event.emit('ensureDeactivated', apiName)
76-
}
77-
7873
isRequired (name) {
7974
return requiredModules.includes(name)
8075
}

libs/remixd/src/bin/remixd.ts

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,23 @@ import * as fs from 'fs-extra'
88
import * as path from 'path'
99
import * as program from 'commander'
1010

11+
const services = {
12+
git: () => new servicesList.GitClient(),
13+
folder: () => new servicesList.Sharedfolder()
14+
}
15+
16+
const ports = {
17+
git: 65521,
18+
folder: 65520
19+
}
20+
21+
const killCallBack: Array<Function> = []
22+
function startService<S extends 'git' | 'folder'> (service: S, callback: (ws: WS, sharedFolderClient: servicesList.Sharedfolder) => void) {
23+
const socket = new WebSocket(ports[service], { remixIdeUrl: program.remixIde }, () => services[service]())
24+
socket.start(callback)
25+
killCallBack.push(socket.close.bind(socket))
26+
}
27+
1128
(async () => {
1229
program
1330
.usage('-s <shared folder>')
@@ -19,7 +36,6 @@ import * as program from 'commander'
1936
console.log('\nExample:\n\n remixd -s ./ --remix-ide http://localhost:8080')
2037
}).parse(process.argv)
2138
// eslint-disable-next-line
22-
const killCallBack: Array<Function> = []
2339

2440
if (!program.remixIde) {
2541
console.log('\x1b[33m%s\x1b[0m', '[WARN] You can only connect to remixd from one of the supported origins.')
@@ -38,15 +54,16 @@ import * as program from 'commander'
3854
console.log('\x1b[33m%s\x1b[0m', '[WARN] Any application that runs on your computer can potentially read from and write to all files in the directory.')
3955
console.log('\x1b[33m%s\x1b[0m', '[WARN] Symbolic links are not forwarded to Remix IDE\n')
4056
try {
41-
const sharedFolderClient = new servicesList.Sharedfolder()
42-
const websocketHandler = new WebSocket(65520, { remixIdeUrl: program.remixIde }, sharedFolderClient)
43-
44-
websocketHandler.start((ws: WS) => {
57+
startService('folder', (ws: WS, sharedFolderClient: servicesList.Sharedfolder) => {
4558
sharedFolderClient.setWebSocket(ws)
4659
sharedFolderClient.setupNotifications(program.sharedFolder)
4760
sharedFolderClient.sharedFolder(program.sharedFolder, program.readOnly || false)
4861
})
49-
killCallBack.push(websocketHandler.close.bind(websocketHandler))
62+
63+
startService('git', (ws: WS, sharedFolderClient: servicesList.Sharedfolder) => {
64+
sharedFolderClient.setWebSocket(ws)
65+
sharedFolderClient.sharedFolder(program.sharedFolder, program.readOnly || false)
66+
})
5067
} catch (error) {
5168
throw new Error(error)
5269
}

0 commit comments

Comments
 (0)