pull/638/head
yann300 4 years ago
parent 23139d43eb
commit 40484a34a3
  1. 5
      apps/remix-ide/src/app/panels/terminal.js
  2. 36
      libs/remixd/src/bin/remixd.ts
  3. 34
      libs/remixd/src/services/gitClient.ts
  4. 4
      libs/remixd/src/websocket.ts

@ -107,7 +107,9 @@ class Terminal extends Plugin {
this.on('git', 'log', (result) => {
this.commands.html.apply(this.commands, yo`<pre>${result}</pre>`)
})
this.on('git', 'error', (result) => {
this.commands.html.apply(this.commands, yo`<pre>${result}</pre>`)
})
}
onDeactivation () {
@ -116,6 +118,7 @@ class Terminal extends Plugin {
this.off('scriptRunner', 'warn')
this.off('scriptRunner', 'error')
this.off('git', 'log')
this.off('git', 'error')
}
logHtml (html) {

@ -8,6 +8,23 @@ import * as fs from 'fs-extra'
import * as path from 'path'
import * as program from 'commander'
const services = {
git: () => new servicesList.GitClient(),
folder: () => new servicesList.Sharedfolder()
}
const ports = {
git: 65521,
folder: 65520
}
const killCallBack: Array<Function> = []
function startService<S extends 'git' | 'folder'> (service: S, callback: (ws: WS, sharedFolderClient: servicesList.Sharedfolder) => void) {
const socket = new WebSocket(ports[service], { remixIdeUrl: program.remixIde }, () => services[service]())
socket.start(callback)
killCallBack.push(socket.close.bind(socket))
}
(async () => {
program
.usage('-s <shared folder>')
@ -19,7 +36,6 @@ import * as program from 'commander'
console.log('\nExample:\n\n remixd -s ./ --remix-ide http://localhost:8080')
}).parse(process.argv)
// eslint-disable-next-line
const killCallBack: Array<Function> = []
if (!program.remixIde) {
console.log('\x1b[33m%s\x1b[0m', '[WARN] You can only connect to remixd from one of the supported origins.')
@ -38,23 +54,6 @@ import * as program from 'commander'
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.')
console.log('\x1b[33m%s\x1b[0m', '[WARN] Symbolic links are not forwarded to Remix IDE\n')
try {
const services = {
git: () => new servicesList.GitClient(),
folder: () => new servicesList.Sharedfolder()
}
const ports = {
git: 65521,
folder: 65520
}
function startService<S extends 'git' | 'folder'>(service: S, callback: (ws: WS, sharedFolderClient: servicesList.Sharedfolder) => void) {
const socket = new WebSocket(ports[service], { remixIdeUrl: program.remixIde }, () =>services[service]());
socket.start(callback)
killCallBack.push(socket.close.bind(socket))
}
startService('folder', (ws: WS, sharedFolderClient: servicesList.Sharedfolder) => {
sharedFolderClient.setWebSocket(ws)
sharedFolderClient.setupNotifications(program.sharedFolder)
@ -65,7 +64,6 @@ import * as program from 'commander'
sharedFolderClient.setWebSocket(ws)
sharedFolderClient.sharedFolder(program.sharedFolder, program.readOnly || false)
})
} catch (error) {
throw new Error(error)
}

@ -18,32 +18,26 @@ export class GitClient extends PluginClient {
}
execute (cmd: string) {
assertCommand(cmd)
const options = { cwd: this.currentSharedFolder, shell: true }
const child = spawn(cmd, options)
let result = ''
let error = ''
return new Promise((resolve, reject) => {
child.stdout.on('data', (data) => {
result += data.toString()
})
child.stderr.on('data', (err) => {
error += err.toString()
})
child.on('close', (exitCode) => {
if (exitCode !== 0) {
reject(error)
} else {
resolve(result + error)
}
})
assertCommand(cmd)
const options = { cwd: this.currentSharedFolder, shell: true }
const child = spawn(cmd, options)
child.stdout.on('data', (data) => {
this.emit('log', data.toString())
})
child.stderr.on('data', (err) => {
this.emit('error', err.toString())
})
child.on('close', (exitCode) => {
if (exitCode !== 0) {
this.emit('error', 'exit with ' + exitCode)
}
})
}
}
/**
* Validate that command can be run by service
* @param cmd
* @param cmd
*/
function assertCommand (cmd) {
const regex = '^git\\s[^&|;]*$'

@ -1,6 +1,6 @@
import * as WS from 'ws'
import * as http from 'http'
import { WebsocketOpt, ServiceClient } from './types'
import { WebsocketOpt, ServiceClient } from './types' // eslint-disable-line
import { getDomain } from './utils'
import { createClient } from '@remixproject/plugin-ws'
export default class WebSocket {
@ -25,7 +25,7 @@ export default class WebSocket {
verifyClient: (info, done) => {
if (!originIsAllowed(info.origin, this)) {
done(false)
console.log(`${new Date()} connection from origin ${info.origin}`)
console.log(`${new Date()} connection from origin ${info.origin}`)
return
}
done(true)

Loading…
Cancel
Save