git return value insead of logging

pull/638/head
yann300 4 years ago
parent 5c58b4895f
commit a789fa7f9a
  1. 14
      apps/remix-ide/src/app/panels/terminal.js
  2. 30
      libs/remixd/src/services/gitClient.ts

@ -104,12 +104,6 @@ class Terminal extends Plugin {
this.on('scriptRunner', 'error', (msg) => { this.on('scriptRunner', 'error', (msg) => {
this.commands.error.apply(this.commands, msg.data) this.commands.error.apply(this.commands, msg.data)
}) })
this.on('git', 'log', (result) => {
this.commands.html(yo`<pre>${result}</pre>`)
})
this.on('git', 'error', (result) => {
this.commands.html(yo`<pre>${result}</pre>`)
})
} }
onDeactivation () { onDeactivation () {
@ -117,8 +111,6 @@ class Terminal extends Plugin {
this.off('scriptRunner', 'info') this.off('scriptRunner', 'info')
this.off('scriptRunner', 'warn') this.off('scriptRunner', 'warn')
this.off('scriptRunner', 'error') this.off('scriptRunner', 'error')
this.off('git', 'log')
this.off('git', 'error')
} }
logHtml (html) { logHtml (html) {
@ -755,11 +747,13 @@ class Terminal extends Plugin {
} }
} }
try { try {
let result
if (script.trim().startsWith('git')) { if (script.trim().startsWith('git')) {
await this.call('git', 'execute', script) result = await this.call('git', 'execute', script)
} else { } else {
await this.call('scriptRunner', 'execute', script) result = await this.call('scriptRunner', 'execute', script)
} }
if (result) self.commands.html(yo`<pre>${result}</pre>`)
done() done()
} catch (error) { } catch (error) {
done(error.message || error) done(error.message || error)

@ -18,20 +18,22 @@ export class GitClient extends PluginClient {
} }
execute (cmd: string) { execute (cmd: string) {
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 result = ''
let error = '' let error = ''
child.stdout.on('data', (data) => { return new Promise((resolve, reject) => {
result += data.toString() child.stdout.on('data', (data) => {
}) result += data.toString()
child.stderr.on('data', (err) => { })
error += err.toString() child.stderr.on('data', (err) => {
}) error += err.toString()
child.on('close', () => { })
if (error !== '') this.emit('error', error) child.on('close', () => {
else this.emit('log', result) if (error) reject(error)
else resolve(result)
})
}) })
} }
} }

Loading…
Cancel
Save