Changed sharedFolder into ES6 class

pull/3094/head
ioedeveloper 5 years ago
parent fb93b1511c
commit d29a5c65da
  1. 2
      bin/remixd
  2. 3131
      package-lock.json
  3. 7
      package.json
  4. 74
      src/services/sharedFolder.js

@ -2,6 +2,7 @@
var Router = require('../src/router')
var servicesList = require('../src/servicesList')
var program = require('commander')
const { buildWebsocketClient } = require('@remixproject/plugin-ws')
program
.usage('-s <shared folder>')
@ -27,6 +28,7 @@ if (program.sharedFolder) {
servicesList['sharedfolder'].setWebSocket(webSocket)
servicesList['sharedfolder'].setupNotifications(program.sharedFolder)
servicesList['sharedfolder'].sharedFolder(program.sharedFolder, program.readOnly || false)
buildWebsocketClient(webSocket.connection, new servicesList['sharedfolder']())
})
killCallBack.push(sharedFolderrouter.start())
}

3131
package-lock.json generated

File diff suppressed because it is too large Load Diff

@ -29,15 +29,12 @@
},
"homepage": "https://github.com/ethereum/remixd#readme",
"dependencies": {
"@remixproject/plugin": "^0.1.18",
"@remixproject/plugin-ws": "^0.2.0-alpha.1",
"chokidar": "^2.0.2",
"commander": "^2.9.0",
"fs-extra": "^3.0.1",
"isbinaryfile": "^3.0.2",
"lerna": "^2.9.0",
"nopy": "^0.2.6",
"serve": "7.0.0",
"stdout": "0.0.3",
"watch": "^1.0.2",
"websocket": "^1.0.24"
},
"python": {

@ -2,31 +2,32 @@ var utils = require('../utils')
var isbinaryfile = require('isbinaryfile')
var fs = require('fs-extra')
var chokidar = require('chokidar')
const { PluginClient } = require('@remixproject/plugin')
module.exports = {
trackDownStreamUpdate: {},
websocket: null,
alreadyNotified: {},
class SharedFolder extends PluginClient {
trackDownStreamUpdate = {}
websocket = null
alreadyNotified = {}
setWebSocket: function (websocket) {
setWebSocket (websocket) {
this.websocket = websocket
},
}
sharedFolder: function (currentSharedFolder, readOnly) {
sharedFolder (currentSharedFolder, readOnly) {
this.currentSharedFolder = currentSharedFolder
this.readOnly = readOnly
if (this.websocket.connection) this.websocket.send(message('rootFolderChanged', {}))
},
}
list: function (args, cb) {
list (args, cb) {
try {
cb(null, utils.walkSync(this.currentSharedFolder, {}, this.currentSharedFolder))
} catch (e) {
cb(e.message)
}
},
}
resolveDirectory: function (args, cb) {
resolveDirectory (args, cb) {
try {
var path = utils.absolutePath(args.path, this.currentSharedFolder)
if (this.websocket && !this.alreadyNotified[path]) {
@ -37,13 +38,13 @@ module.exports = {
} catch (e) {
cb(e.message)
}
},
}
folderIsReadOnly: function (args, cb) {
folderIsReadOnly (args, cb) {
return cb(null, this.readOnly)
},
}
get: function (args, cb) {
get (args, cb) {
var path = utils.absolutePath(args.path, this.currentSharedFolder)
if (!fs.existsSync(path)) {
return cb('File not found ' + path)
@ -60,15 +61,15 @@ module.exports = {
})
}
})
},
}
exists: function (args, cb) {
exists (args, cb) {
const path = utils.absolutePath(args.path, this.currentSharedFolder)
cb(null, fs.existsSync(path))
},
}
set: function (args, cb) {
set (args, cb) {
if (this.readOnly) return cb('Cannot write file: read-only mode selected')
const isFolder = args.path.endsWith('/')
var path = utils.absolutePath(args.path, this.currentSharedFolder)
@ -88,9 +89,9 @@ module.exports = {
})
}).catch(e => cb(e))
}
},
}
rename: function (args, cb) {
rename (args, cb) {
if (this.readOnly) return cb('Cannot rename file: read-only mode selected')
var oldpath = utils.absolutePath(args.oldPath, this.currentSharedFolder)
if (!fs.existsSync(oldpath)) {
@ -102,9 +103,9 @@ module.exports = {
if (error) console.log(error)
cb(error, data)
})
},
}
remove: function (args, cb) {
remove (args, cb) {
if (this.readOnly) return cb('Cannot remove file: read-only mode selected')
var path = utils.absolutePath(args.path, this.currentSharedFolder)
if (!fs.existsSync(path)) {
@ -118,36 +119,24 @@ module.exports = {
}
cb(error, true)
})
},
}
isDirectory: function (args, cb) {
isDirectory (args, cb) {
const path = utils.absolutePath(args.path, this.currentSharedFolder)
cb(null, fs.statSync(path).isDirectory())
},
}
isFile: function (args, cb) {
isFile (args, cb) {
const path = utils.absolutePath(args.path, this.currentSharedFolder)
cb(null, fs.statSync(path).isFile())
},
}
setupNotifications: function (path) {
setupNotifications (path) {
if (!isRealPath(path)) return
var 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)
if (this.websocket.connection) this.websocket.send(message('created', { path: utils.relativePath(f, this.currentSharedFolder), isReadOnly: isBinary, isFolder: false }))
})
})
watcher.on('addDir', (f, stat) => {
if (this.websocket.connection) this.websocket.send(message('created', { path: utils.relativePath(f, this.currentSharedFolder), isReadOnly: false, isFolder: true }))
})
*/
watcher.on('change', (f, curr, prev) => {
if (this.trackDownStreamUpdate[f]) {
delete this.trackDownStreamUpdate[f]
@ -162,6 +151,7 @@ module.exports = {
if (this.websocket.connection) this.websocket.send(message('removed', { path: utils.relativePath(f, this.currentSharedFolder), isFolder: true }))
})
}
}
function isRealPath (path, cb) {
@ -178,3 +168,5 @@ function isRealPath (path, cb) {
function message (name, value) {
return JSON.stringify({ type: 'notification', scope: 'sharedfolder', name: name, value: value })
}
module.exports = SharedFolder

Loading…
Cancel
Save