-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Add git service in remixd & use it from the terminal #638
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
73ca6be to
002c405
Compare
7b11e96 to
dd4e761
Compare
e3ebc65 to
441b4b0
Compare
| super(profile) | ||
| } | ||
|
|
||
| deactivate () { |
There was a problem hiding this comment.
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: [], |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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'], |
There was a problem hiding this comment.
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) => { |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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[^&|;]*$' |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
libs/remixd/src/websocket.ts
Outdated
| 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 + '') |
There was a problem hiding this comment.
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}`)|
E2E looks good. |
c10759d to
7c5c860
Compare
| } | ||
| }, 3000) | ||
| this.locahostProvider.init(_ => this.fileSystemExplorer.ensureRoot()) | ||
| this.appManager.ensureActivated('git') |
There was a problem hiding this comment.
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') |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
0c314a5 to
eb64ab6
Compare
421672e to
189981d
Compare
189981d to
7d1fe50
Compare
fix #592
based on remix-project-org/remixd#99