Unverified Commit 5c74bc34 authored by yann300's avatar yann300 Committed by GitHub

Merge pull request #115 from ethereum/remixd-websocket

Setup notifications remixd websocket plugin
parents 853e4a29 91e2f231
......@@ -31,6 +31,7 @@ if (program.sharedFolder) {
websocketHandler.start((ws: WS) => {
sharedFolderClient.setWebSocket(ws)
sharedFolderClient.setupNotifications(program.sharedFolder)
sharedFolderClient.sharedFolder(program.sharedFolder, program.readOnly || false)
})
killCallBack.push(websocketHandler.close.bind(websocketHandler))
......@@ -41,7 +42,7 @@ if (program.sharedFolder) {
// kill
function kill () {
for (var k in killCallBack) {
for (const k in killCallBack) {
try {
killCallBack[k]()
} catch (e) {
......
......@@ -139,6 +139,15 @@
"integrity": "sha512-OCutwjDZ4aFS6PB1UZ988C4YgwlBHJd6wCeQqaLdmadZ/7e+w79+hbMUFC1QXDNCmdyoRfAFdm0RypzwR+Qpag==",
"dev": true
},
"@types/fs-extra": {
"version": "9.0.1",
"resolved": "https://registry.npmjs.org/@types/fs-extra/-/fs-extra-9.0.1.tgz",
"integrity": "sha512-B42Sxuaz09MhC3DDeW5kubRcQ5by4iuVQ0cRRWM2lggLzAa/KVom0Aft/208NgMvNQQZ86s5rVcqDdn/SH0/mg==",
"dev": true,
"requires": {
"@types/node": "*"
}
},
"@types/json-schema": {
"version": "7.0.5",
"resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.5.tgz",
......
......@@ -11,7 +11,7 @@
"test": "echo \"Error: no test specified\"",
"start": "./lib/bin/remixd.js",
"npip": "npip",
"lint": "eslint ./src --ext .ts",
"lint": "eslint ./src ./bin --ext .ts",
"build": "tsc -p ./ && chmod +x ./lib/bin/remixd.js",
"dev": "nodemon"
},
......@@ -34,12 +34,11 @@
"dependencies": {
"@remixproject/plugin": "0.3.0-alpha.3",
"@remixproject/plugin-ws": "0.3.0-alpha.1",
"chalk": "^4.0.0",
"chokidar": "^2.0.2",
"commander": "^2.20.3",
"fs-extra": "^3.0.1",
"isbinaryfile": "^3.0.2",
"ws": "^7.3.0"
"ws": "^7.3.0",
"chokidar": "^2.1.8",
"fs-extra": "^3.0.1"
},
"python": {
"execPath": "python3",
......@@ -48,6 +47,7 @@
}
},
"devDependencies": {
"@types/fs-extra": "^9.0.1",
"@types/node": "^14.0.5",
"@types/ws": "^7.2.4",
"@typescript-eslint/eslint-plugin": "^3.2.0",
......
'use strict'
import { RemixdClient as sharedFolder } from './services/remixdClient'
import Websocket from './websocket'
import * as utils from './utils'
module.exports = {
Router: require('./router'),
utils: require('./utils'),
Websocket,
utils,
services: {
sharedFolder: require('./services/sharedFolder')
sharedFolder
}
}
import { PluginClient } from '@remixproject/plugin'
import { SharedFolderArgs, TrackDownStreamUpdate, WS, Filelist, ResolveDirectory, FileContent } from '../../types'
import * as utils from '../utils'
import * as chokidar from 'chokidar'
import * as fs from 'fs-extra'
const isbinaryfile = require('isbinaryfile')
const fs = require('fs-extra')
export class RemixdClient extends PluginClient {
methods: ['folderIsReadOnly', 'resolveDirectory', 'get', 'exists', 'isFile', 'set', 'list', 'isDirectory']
......@@ -193,6 +194,39 @@ export class RemixdClient extends PluginClient {
throw new Error(error)
}
}
setupNotifications (path: string): void {
const absPath = utils.absolutePath('./', path)
if (!isRealPath(absPath)) return
const watcher = chokidar.watch(path, { depth: 0, ignorePermissionErrors: true })
console.log('setup notifications for ' + path)
/* we can't listen on created file / folder
watcher.on('add', (f, stat) => {
isbinaryfile(f, (error, isBinary) => {
if (error) console.log(error)
console.log('add', f)
this.emit('created', { path: utils.relativePath(f, this.currentSharedFolder), isReadOnly: isBinary, isFolder: false })
})
})
watcher.on('addDir', (f, stat) => {
this.emit('created', { path: utils.relativePath(f, this.currentSharedFolder), isReadOnly: false, isFolder: true })
})
*/
watcher.on('change', (f: string) => {
if (this.trackDownStreamUpdate[f]) {
delete this.trackDownStreamUpdate[f]
return
}
this.emit('changed', utils.relativePath(f, this.currentSharedFolder))
})
watcher.on('unlink', (f: string) => {
this.emit('removed', utils.relativePath(f, this.currentSharedFolder), false)
})
watcher.on('unlinkDir', (f: string) => {
this.emit('removed', utils.relativePath(f, this.currentSharedFolder), true)
})
}
}
function isRealPath (path: string): boolean {
......
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