Restored setupNotifications for remixd

pull/454/head
ioedeveloper 4 years ago
parent e376b2ed67
commit 202198a32e
  1. 3
      bin/remixd.ts
  2. 9
      package-lock.json
  3. 10
      package.json
  4. 3
      src/index.ts
  5. 34
      src/services/remixdClient.ts

@ -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) {

9
package-lock.json generated

@ -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",

@ -1,9 +1,8 @@
'use strict'
module.exports = {
Router: require('./router'),
utils: require('./utils'),
services: {
sharedFolder: require('./services/sharedFolder')
sharedFolder: require('./services/remixdClient')
}
}

@ -1,9 +1,10 @@
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,37 @@ export class RemixdClient extends PluginClient {
throw new Error(error)
}
}
setupNotifications (path: string): void {
if (!isRealPath(path)) 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', { path: utils.relativePath(f, this.currentSharedFolder), isFolder: false })
})
watcher.on('unlinkDir', (f: string) => {
this.emit('removed', { path: utils.relativePath(f, this.currentSharedFolder), isFolder: true })
})
}
}
function isRealPath (path: string): boolean {

Loading…
Cancel
Save