Commit 40484a34 authored by yann300's avatar yann300

standard

parent 23139d43
...@@ -107,7 +107,9 @@ class Terminal extends Plugin { ...@@ -107,7 +107,9 @@ class Terminal extends Plugin {
this.on('git', 'log', (result) => { this.on('git', 'log', (result) => {
this.commands.html.apply(this.commands, yo`<pre>${result}</pre>`) 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 () { onDeactivation () {
...@@ -116,6 +118,7 @@ class Terminal extends Plugin { ...@@ -116,6 +118,7 @@ class Terminal extends Plugin {
this.off('scriptRunner', 'warn') this.off('scriptRunner', 'warn')
this.off('scriptRunner', 'error') this.off('scriptRunner', 'error')
this.off('git', 'log') this.off('git', 'log')
this.off('git', 'error')
} }
logHtml (html) { logHtml (html) {
......
...@@ -8,6 +8,23 @@ import * as fs from 'fs-extra' ...@@ -8,6 +8,23 @@ import * as fs from 'fs-extra'
import * as path from 'path' import * as path from 'path'
import * as program from 'commander' 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 () => { (async () => {
program program
.usage('-s <shared folder>') .usage('-s <shared folder>')
...@@ -19,7 +36,6 @@ import * as program from 'commander' ...@@ -19,7 +36,6 @@ import * as program from 'commander'
console.log('\nExample:\n\n remixd -s ./ --remix-ide http://localhost:8080') console.log('\nExample:\n\n remixd -s ./ --remix-ide http://localhost:8080')
}).parse(process.argv) }).parse(process.argv)
// eslint-disable-next-line // eslint-disable-next-line
const killCallBack: Array<Function> = []
if (!program.remixIde) { if (!program.remixIde) {
console.log('\x1b[33m%s\x1b[0m', '[WARN] You can only connect to remixd from one of the supported origins.') 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' ...@@ -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] 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') console.log('\x1b[33m%s\x1b[0m', '[WARN] Symbolic links are not forwarded to Remix IDE\n')
try { 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) => { startService('folder', (ws: WS, sharedFolderClient: servicesList.Sharedfolder) => {
sharedFolderClient.setWebSocket(ws) sharedFolderClient.setWebSocket(ws)
sharedFolderClient.setupNotifications(program.sharedFolder) sharedFolderClient.setupNotifications(program.sharedFolder)
...@@ -65,7 +64,6 @@ import * as program from 'commander' ...@@ -65,7 +64,6 @@ import * as program from 'commander'
sharedFolderClient.setWebSocket(ws) sharedFolderClient.setWebSocket(ws)
sharedFolderClient.sharedFolder(program.sharedFolder, program.readOnly || false) sharedFolderClient.sharedFolder(program.sharedFolder, program.readOnly || false)
}) })
} catch (error) { } catch (error) {
throw new Error(error) throw new Error(error)
} }
......
...@@ -21,23 +21,17 @@ export class GitClient extends PluginClient { ...@@ -21,23 +21,17 @@ export class GitClient extends PluginClient {
assertCommand(cmd) assertCommand(cmd)
const options = { cwd: this.currentSharedFolder, shell: true } const options = { cwd: this.currentSharedFolder, shell: true }
const child = spawn(cmd, options) const child = spawn(cmd, options)
let result = ''
let error = ''
return new Promise((resolve, reject) => {
child.stdout.on('data', (data) => { child.stdout.on('data', (data) => {
result += data.toString() this.emit('log', data.toString())
}) })
child.stderr.on('data', (err) => { child.stderr.on('data', (err) => {
error += err.toString() this.emit('error', err.toString())
}) })
child.on('close', (exitCode) => { child.on('close', (exitCode) => {
if (exitCode !== 0) { if (exitCode !== 0) {
reject(error) this.emit('error', 'exit with ' + exitCode)
} else {
resolve(result + error)
} }
}) })
})
} }
} }
......
import * as WS from 'ws' import * as WS from 'ws'
import * as http from 'http' import * as http from 'http'
import { WebsocketOpt, ServiceClient } from './types' import { WebsocketOpt, ServiceClient } from './types' // eslint-disable-line
import { getDomain } from './utils' import { getDomain } from './utils'
import { createClient } from '@remixproject/plugin-ws' import { createClient } from '@remixproject/plugin-ws'
export default class WebSocket { export default class WebSocket {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment