Merge pull request #115 from ethereum/remixd-websocket

Setup notifications remixd websocket plugin
pull/3094/head
yann300 4 years ago committed by GitHub
commit 88ab62bde8
  1. 3
      bin/remixd.ts
  2. 9
      package-lock.json
  3. 10
      package.json
  4. 9
      src/index.ts
  5. 36
      src/services/remixdClient.ts

@ -31,6 +31,7 @@ if (program.sharedFolder) {
websocketHandler.start((ws: WS) => { websocketHandler.start((ws: WS) => {
sharedFolderClient.setWebSocket(ws) sharedFolderClient.setWebSocket(ws)
sharedFolderClient.setupNotifications(program.sharedFolder)
sharedFolderClient.sharedFolder(program.sharedFolder, program.readOnly || false) sharedFolderClient.sharedFolder(program.sharedFolder, program.readOnly || false)
}) })
killCallBack.push(websocketHandler.close.bind(websocketHandler)) killCallBack.push(websocketHandler.close.bind(websocketHandler))
@ -41,7 +42,7 @@ if (program.sharedFolder) {
// kill // kill
function kill () { function kill () {
for (var k in killCallBack) { for (const k in killCallBack) {
try { try {
killCallBack[k]() killCallBack[k]()
} catch (e) { } catch (e) {

9
package-lock.json generated

@ -139,6 +139,15 @@
"integrity": "sha512-OCutwjDZ4aFS6PB1UZ988C4YgwlBHJd6wCeQqaLdmadZ/7e+w79+hbMUFC1QXDNCmdyoRfAFdm0RypzwR+Qpag==", "integrity": "sha512-OCutwjDZ4aFS6PB1UZ988C4YgwlBHJd6wCeQqaLdmadZ/7e+w79+hbMUFC1QXDNCmdyoRfAFdm0RypzwR+Qpag==",
"dev": true "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": { "@types/json-schema": {
"version": "7.0.5", "version": "7.0.5",
"resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.5.tgz", "resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.5.tgz",

@ -11,7 +11,7 @@
"test": "echo \"Error: no test specified\"", "test": "echo \"Error: no test specified\"",
"start": "./lib/bin/remixd.js", "start": "./lib/bin/remixd.js",
"npip": "npip", "npip": "npip",
"lint": "eslint ./src --ext .ts", "lint": "eslint ./src ./bin --ext .ts",
"build": "tsc -p ./ && chmod +x ./lib/bin/remixd.js", "build": "tsc -p ./ && chmod +x ./lib/bin/remixd.js",
"dev": "nodemon" "dev": "nodemon"
}, },
@ -34,12 +34,11 @@
"dependencies": { "dependencies": {
"@remixproject/plugin": "0.3.0-alpha.3", "@remixproject/plugin": "0.3.0-alpha.3",
"@remixproject/plugin-ws": "0.3.0-alpha.1", "@remixproject/plugin-ws": "0.3.0-alpha.1",
"chalk": "^4.0.0",
"chokidar": "^2.0.2",
"commander": "^2.20.3", "commander": "^2.20.3",
"fs-extra": "^3.0.1",
"isbinaryfile": "^3.0.2", "isbinaryfile": "^3.0.2",
"ws": "^7.3.0" "ws": "^7.3.0",
"chokidar": "^2.1.8",
"fs-extra": "^3.0.1"
}, },
"python": { "python": {
"execPath": "python3", "execPath": "python3",
@ -48,6 +47,7 @@
} }
}, },
"devDependencies": { "devDependencies": {
"@types/fs-extra": "^9.0.1",
"@types/node": "^14.0.5", "@types/node": "^14.0.5",
"@types/ws": "^7.2.4", "@types/ws": "^7.2.4",
"@typescript-eslint/eslint-plugin": "^3.2.0", "@typescript-eslint/eslint-plugin": "^3.2.0",

@ -1,9 +1,12 @@
'use strict' 'use strict'
import { RemixdClient as sharedFolder } from './services/remixdClient'
import Websocket from './websocket'
import * as utils from './utils'
module.exports = { module.exports = {
Router: require('./router'), Websocket,
utils: require('./utils'), utils,
services: { services: {
sharedFolder: require('./services/sharedFolder') sharedFolder
} }
} }

@ -1,9 +1,10 @@
import { PluginClient } from '@remixproject/plugin' import { PluginClient } from '@remixproject/plugin'
import { SharedFolderArgs, TrackDownStreamUpdate, WS, Filelist, ResolveDirectory, FileContent } from '../../types' import { SharedFolderArgs, TrackDownStreamUpdate, WS, Filelist, ResolveDirectory, FileContent } from '../../types'
import * as utils from '../utils' import * as utils from '../utils'
import * as chokidar from 'chokidar'
import * as fs from 'fs-extra'
const isbinaryfile = require('isbinaryfile') const isbinaryfile = require('isbinaryfile')
const fs = require('fs-extra')
export class RemixdClient extends PluginClient { export class RemixdClient extends PluginClient {
methods: ['folderIsReadOnly', 'resolveDirectory', 'get', 'exists', 'isFile', 'set', 'list', 'isDirectory'] methods: ['folderIsReadOnly', 'resolveDirectory', 'get', 'exists', 'isFile', 'set', 'list', 'isDirectory']
@ -193,6 +194,39 @@ export class RemixdClient extends PluginClient {
throw new Error(error) 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 { function isRealPath (path: string): boolean {

Loading…
Cancel
Save