Skip to content

Conversation

@yann300
Copy link
Contributor

@yann300 yann300 commented Nov 26, 2020

@yann300 yann300 requested a review from ioedeveloper November 26, 2020 12:48
@yann300 yann300 force-pushed the addgitService branch 5 times, most recently from 73ca6be to 002c405 Compare November 26, 2020 14:52
@yann300 yann300 force-pushed the addgitService branch 5 times, most recently from 7b11e96 to dd4e761 Compare November 27, 2020 11:14
@yann300 yann300 removed the WIP label Nov 27, 2020
@yann300 yann300 force-pushed the addgitService branch 2 times, most recently from e3ebc65 to 441b4b0 Compare November 27, 2020 12:18
super(profile)
}

deactivate () {
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove deactivate & activate if you only forward to extended class

displayName: 'Git',
url: 'ws://127.0.0.1:65521',
methods: ['command'],
events: [],
Copy link
Contributor

Choose a reason for hiding this comment

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

events is deprecated. You can remove it


function wrapScript (script) {
if (script.startsWith('remix.')) return script
if (script.trim().startsWith('remix.') || script.trim().startsWith('git')) return script
Copy link
Contributor

Choose a reason for hiding this comment

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

Create a variable to make it easier to read:

const isRemix = script.trim().startsWith('remix.')
const isGit = script.trim().startsWith('git')
if (isRemix || isGit) return script;

or

const isKnownScript = ['remix.', 'git'].some(prefix => script.trim().startWith(prefix))
if (isKnownScript) return script

}
try {
await this.call('scriptRunner', 'execute', script)
if (script.trim().indexOf('git') === 0) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Keep the same logic everywhere. Use startWith instead of indexOf() (except if you need the index for later, which is not the case here).

name: 'git',
displayName: 'Git',
url: 'ws://127.0.0.1:65521',
methods: ['command'],
Copy link
Contributor

Choose a reason for hiding this comment

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

Why command while the scriptRunner method is execute ? I think it makes it difficult for developers to follow up with the naming.
I would recommend to define a kind "terminal" or whatever with the right interface.

}

command (cmd: string) {
return new Promise((resolve, reject) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

I would recommend to put the Promise closer to its used :

assertCommand(cmd, gitRegex)
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 += data.toString())
  child.on('close', (exitCode) => exitCode !== 0 ? reject(error) : resolve(result))
})

You don't need to try / catch here everything that throw will be handled by the caller

* @param cmd
* @param regex
*/
function validateCommand (cmd, regex) {
Copy link
Contributor

Choose a reason for hiding this comment

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

rename assertCommand and remove the regex parameter, except if you see a reason where it could be different than the one at the top of the file.

import * as WS from 'ws' // eslint-disable-line
import { PluginClient } from '@remixproject/plugin'
const { spawn } = require('child_process')
const gitRegex = '^git\\s[^&|;]*$'
Copy link
Contributor

Choose a reason for hiding this comment

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

Put the regex in the assertion function directly.

import * as WS from 'ws'
import * as http from 'http'
import { WebsocketOpt, SharedFolderClient } from './types' // eslint-disable-line
import { WebsocketOpt, ServiceClient } from './types' // eslint-disable-line
Copy link
Contributor

Choose a reason for hiding this comment

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

any reason why you need to disable line ? I'm not sure you need to do that anymore.

this.server.listen(this.port, loopback, function () {
console.log((new Date()) + ' remixd is listening on ' + loopback + ':65520')
this.server.listen(this.port, loopback, () => {
console.log((new Date()) + ' remixd is listening on ' + loopback + ':' + this.port + '')
Copy link
Contributor

Choose a reason for hiding this comment

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

I would looks a little bit cleaner with a string template I think :

console.log(`${new Date()} remixd is listening on ${loopback}:${this.port}`)

@ioedeveloper
Copy link
Collaborator

E2E looks good.

}
}, 3000)
this.locahostProvider.init(_ => this.fileSystemExplorer.ensureRoot())
this.appManager.ensureActivated('git')
Copy link
Contributor

Choose a reason for hiding this comment

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

This has been removed in #651. Why not running this.call('manager', 'activatePlugin', 'git') ?
Or even let the engine lazily activate the git plugin on first call

deactivate () {
this.fileSystemExplorer.hide()
if (super.socket) super.deactivate()
this.appManager.ensureDeactivated('git')
Copy link
Contributor

Choose a reason for hiding this comment

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

Any reason why not using this.call('manager', 'deactivatePlugin', 'git') ?
Use call through the engine when possible instead of direct call to a plugin.

test,
filePanel.remixdHandle
filePanel.remixdHandle,
filePanel.gitHandle
Copy link
Contributor

Choose a reason for hiding this comment

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

as a Plugin I would recommend putting Git at the root of the project and access its methods only through remix-plugin API

Copy link
Contributor Author

Choose a reason for hiding this comment

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

will plan this changes later on. This will anyway go in during the react refactoring.

var fileSystemExplorer = createProvider('localhost')

self.remixdHandle = new RemixdHandle(fileSystemExplorer, self._deps.fileProviders.localhost, appManager)
self.gitHandle = new GitHandle()
Copy link
Contributor

Choose a reason for hiding this comment

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

I would recommend to put GitHandle at the root of the project and not in the FilePanel property

const result = await this.call('git', 'command', script)
self.commands.html(yo`<pre>${result}</pre>`)
} else {
await this.call('scriptRunner', 'execute', script)
Copy link
Contributor

Choose a reason for hiding this comment

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

You can increase the timeout of the scriptRunner plugin and return the value. It doesn't prevent you to listen on log events if you need

})
child.on('close', () => {
if (error !== '') this.emit('error', error)
else this.emit('log', result)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think returning a value was a better way to handle it.

@yann300 yann300 force-pushed the addgitService branch 2 times, most recently from 421672e to 189981d Compare December 7, 2020 15:03
@yann300 yann300 merged commit 25b83af into master Dec 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Use remixd to forward command from the remix terminal to the host.

4 participants