Commit ea9783db authored by ioedeveloper's avatar ioedeveloper

Setup typescript for remixd

parent 6ccf9992
#!/usr/bin/env node #!/usr/bin/env node
var Router = require('../src/router') const Router = require('../src/router')
var servicesList = require('../src/servicesList') const servicesList = require('../src/servicesList')
var program = require('commander') const program = require('commander')
const { buildWebsocketClient } = require('@remixproject/plugin-ws')
program program
.usage('-s <shared folder>') .usage('-s <shared folder>')
...@@ -14,21 +13,21 @@ program ...@@ -14,21 +13,21 @@ program
console.log('\nExample:\n\n remixd -s ./ --remix-ide http://localhost:8080') console.log('\nExample:\n\n remixd -s ./ --remix-ide http://localhost:8080')
}).parse(process.argv) }).parse(process.argv)
var killCallBack = [] const killCallBack: Array<Function> = []
if (!program.remixIde) { if (!program.remixIde) {
return console.log('\x1b[31m%s\x1b[0m', '[ERR] URL Remix IDE instance has to be provided.') console.log('\x1b[31m%s\x1b[0m', '[ERR] URL Remix IDE instance has to be provided.')
} }
console.log('\x1b[33m%s\x1b[0m', '[WARN] You may now only use IDE at ' + program.remixIde + ' to connect to that instance') console.log('\x1b[33m%s\x1b[0m', '[WARN] You may now only use IDE at ' + program.remixIde + ' to connect to that instance')
if (program.sharedFolder) { if (program.sharedFolder) {
console.log('\x1b[33m%s\x1b[0m', '[WARN] Any application that runs on your computer can potentially read from and write to all files in the directory.') console.log('\x1b[33m%s\x1b[0m', '[WARN] Any application that runs on your computer can potentially read from and write to all files in the directory.')
console.log('\x1b[33m%s\x1b[0m', '[WARN] Symbolic links are not forwarded to Remix IDE\n') console.log('\x1b[33m%s\x1b[0m', '[WARN] Symbolic links are not forwarded to Remix IDE\n')
var sharedFolderrouter = new Router(65520, servicesList['sharedfolder'], { remixIdeUrl: program.remixIde }, (webSocket) => { const sharedFolderrouter = new Router(65520, servicesList['sharedfolder'], { remixIdeUrl: program.remixIde }, (webSocket: WebSocket) => {
servicesList['sharedfolder'].setWebSocket(webSocket) servicesList['sharedfolder'].setWebSocket(webSocket)
servicesList['sharedfolder'].setupNotifications(program.sharedFolder) servicesList['sharedfolder'].setupNotifications(program.sharedFolder)
servicesList['sharedfolder'].sharedFolder(program.sharedFolder, program.readOnly || false) servicesList['sharedfolder'].sharedFolder(program.sharedFolder, program.readOnly || false)
buildWebsocketClient(webSocket.connection, new servicesList['sharedfolder']()) // buildWebsocketClient(webSocket.connection, new servicesList['sharedfolder']())
}) })
killCallBack.push(sharedFolderrouter.start()) killCallBack.push(sharedFolderrouter.start())
} }
......
#!/usr/bin/env node
declare const Router: any;
declare const servicesList: any;
declare const program: any;
declare const killCallBack: Array<Function>;
declare function kill(): void;
#!/usr/bin/env node
"use strict";
var Router = require('../src/router');
var servicesList = require('../src/servicesList');
var program = require('commander');
program
.usage('-s <shared folder>')
.description('Provide a two-way connection between the local computer and Remix IDE')
.option('--remix-ide <url>', 'URL of remix instance allowed to connect to this web sockect connection')
.option('-s, --shared-folder <path>', 'Folder to share with Remix IDE')
.option('--read-only', 'Treat shared folder as read-only (experimental)')
.on('--help', function () {
console.log('\nExample:\n\n remixd -s ./ --remix-ide http://localhost:8080');
}).parse(process.argv);
var killCallBack = [];
if (!program.remixIde) {
console.log('\x1b[31m%s\x1b[0m', '[ERR] URL Remix IDE instance has to be provided.');
}
console.log('\x1b[33m%s\x1b[0m', '[WARN] You may now only use IDE at ' + program.remixIde + ' to connect to that instance');
if (program.sharedFolder) {
console.log('\x1b[33m%s\x1b[0m', '[WARN] Any application that runs on your computer can potentially read from and write to all files in the directory.');
console.log('\x1b[33m%s\x1b[0m', '[WARN] Symbolic links are not forwarded to Remix IDE\n');
var sharedFolderrouter = new Router(65520, servicesList['sharedfolder'], { remixIdeUrl: program.remixIde }, function (webSocket) {
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());
}
// kill
function kill() {
for (var k in killCallBack) {
try {
killCallBack[k]();
}
catch (e) {
console.log(e);
}
}
}
process.on('SIGINT', kill); // catch ctrl-c
process.on('SIGTERM', kill); // catch kill
process.on('exit', kill);
{
"watch": ["./src"],
"ext": "ts",
"exec": "npm run build"
}
\ No newline at end of file
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -2,15 +2,16 @@ ...@@ -2,15 +2,16 @@
"name": "remixd", "name": "remixd",
"version": "0.1.8-alpha.16", "version": "0.1.8-alpha.16",
"description": "remix server: allow accessing file system from remix.ethereum.org and start a dev environment (see help section)", "description": "remix server: allow accessing file system from remix.ethereum.org and start a dev environment (see help section)",
"main": "./src/index.js", "main": "./lib/src/index.js",
"bin": { "bin": {
"remixd": "./bin/remixd" "remixd": "./lib/bin/remixd"
}, },
"scripts": { "scripts": {
"test": "echo \"Error: no test specified\"", "test": "echo \"Error: no test specified\"",
"start": "./bin/remixd", "start": "./lib/bin/remixd",
"npip": "npip", "npip": "npip",
"lint": "eslint ./src" "lint": "eslint ./src",
"build": "tsc -p ./"
}, },
"repository": { "repository": {
"type": "git", "type": "git",
...@@ -44,11 +45,16 @@ ...@@ -44,11 +45,16 @@
} }
}, },
"devDependencies": { "devDependencies": {
"@types/node": "^14.0.5",
"@types/websocket": "^1.0.0",
"eslint": "6.8.0", "eslint": "6.8.0",
"eslint-config-standard": "14.1.1", "eslint-config-standard": "14.1.1",
"eslint-plugin-import": "2.20.2", "eslint-plugin-import": "2.20.2",
"eslint-plugin-node": "11.1.0", "eslint-plugin-node": "11.1.0",
"eslint-plugin-promise": "4.2.1", "eslint-plugin-promise": "4.2.1",
"eslint-plugin-standard": "4.0.1" "eslint-plugin-standard": "4.0.1",
"nodemon": "^2.0.4",
"ts-node": "^8.10.1",
"typescript": "^3.9.3"
} }
} }
...@@ -4,30 +4,30 @@ var fs = require('fs-extra') ...@@ -4,30 +4,30 @@ var fs = require('fs-extra')
var chokidar = require('chokidar') var chokidar = require('chokidar')
const { PluginClient } = require('@remixproject/plugin') const { PluginClient } = require('@remixproject/plugin')
class SharedFolder extends PluginClient { Object.create(PluginClient, {
trackDownStreamUpdate = {} trackDownStreamUpdate: {},
websocket = null websocket: null,
alreadyNotified = {} alreadyNotified: {},
setWebSocket (websocket) { setWebSocket: function (websocket) {
this.websocket = websocket this.websocket = websocket
} },
sharedFolder (currentSharedFolder, readOnly) { sharedFolder: function (currentSharedFolder, readOnly) {
this.currentSharedFolder = currentSharedFolder this.currentSharedFolder = currentSharedFolder
this.readOnly = readOnly this.readOnly = readOnly
if (this.websocket.connection) this.websocket.send(message('rootFolderChanged', {})) if (this.websocket.connection) this.websocket.send(message('rootFolderChanged', {}))
} },
list (args, cb) { list: function (args, cb) {
try { try {
cb(null, utils.walkSync(this.currentSharedFolder, {}, this.currentSharedFolder)) cb(null, utils.walkSync(this.currentSharedFolder, {}, this.currentSharedFolder))
} catch (e) { } catch (e) {
cb(e.message) cb(e.message)
} }
} },
resolveDirectory (args, cb) { resolveDirectory: function (args, cb) {
try { try {
var path = utils.absolutePath(args.path, this.currentSharedFolder) var path = utils.absolutePath(args.path, this.currentSharedFolder)
if (this.websocket && !this.alreadyNotified[path]) { if (this.websocket && !this.alreadyNotified[path]) {
...@@ -38,13 +38,13 @@ class SharedFolder extends PluginClient { ...@@ -38,13 +38,13 @@ class SharedFolder extends PluginClient {
} catch (e) { } catch (e) {
cb(e.message) cb(e.message)
} }
} },
folderIsReadOnly (args, cb) { folderIsReadOnly: function (args, cb) {
return cb(null, this.readOnly) return cb(null, this.readOnly)
} },
get (args, cb) { get: function (args, cb) {
var path = utils.absolutePath(args.path, this.currentSharedFolder) var path = utils.absolutePath(args.path, this.currentSharedFolder)
if (!fs.existsSync(path)) { if (!fs.existsSync(path)) {
return cb('File not found ' + path) return cb('File not found ' + path)
...@@ -61,15 +61,15 @@ class SharedFolder extends PluginClient { ...@@ -61,15 +61,15 @@ class SharedFolder extends PluginClient {
}) })
} }
}) })
} },
exists (args, cb) { exists: function (args, cb) {
const path = utils.absolutePath(args.path, this.currentSharedFolder) const path = utils.absolutePath(args.path, this.currentSharedFolder)
cb(null, fs.existsSync(path)) cb(null, fs.existsSync(path))
} },
set (args, cb) { set: function (args, cb) {
if (this.readOnly) return cb('Cannot write file: read-only mode selected') if (this.readOnly) return cb('Cannot write file: read-only mode selected')
const isFolder = args.path.endsWith('/') const isFolder = args.path.endsWith('/')
var path = utils.absolutePath(args.path, this.currentSharedFolder) var path = utils.absolutePath(args.path, this.currentSharedFolder)
...@@ -89,9 +89,9 @@ class SharedFolder extends PluginClient { ...@@ -89,9 +89,9 @@ class SharedFolder extends PluginClient {
}) })
}).catch(e => cb(e)) }).catch(e => cb(e))
} }
} },
rename (args, cb) { rename: function (args, cb) {
if (this.readOnly) return cb('Cannot rename file: read-only mode selected') if (this.readOnly) return cb('Cannot rename file: read-only mode selected')
var oldpath = utils.absolutePath(args.oldPath, this.currentSharedFolder) var oldpath = utils.absolutePath(args.oldPath, this.currentSharedFolder)
if (!fs.existsSync(oldpath)) { if (!fs.existsSync(oldpath)) {
...@@ -103,9 +103,9 @@ class SharedFolder extends PluginClient { ...@@ -103,9 +103,9 @@ class SharedFolder extends PluginClient {
if (error) console.log(error) if (error) console.log(error)
cb(error, data) cb(error, data)
}) })
} },
remove (args, cb) { remove: function (args, cb) {
if (this.readOnly) return cb('Cannot remove file: read-only mode selected') if (this.readOnly) return cb('Cannot remove file: read-only mode selected')
var path = utils.absolutePath(args.path, this.currentSharedFolder) var path = utils.absolutePath(args.path, this.currentSharedFolder)
if (!fs.existsSync(path)) { if (!fs.existsSync(path)) {
...@@ -119,24 +119,36 @@ class SharedFolder extends PluginClient { ...@@ -119,24 +119,36 @@ class SharedFolder extends PluginClient {
} }
cb(error, true) cb(error, true)
}) })
} },
isDirectory (args, cb) { isDirectory: function (args, cb) {
const path = utils.absolutePath(args.path, this.currentSharedFolder) const path = utils.absolutePath(args.path, this.currentSharedFolder)
cb(null, fs.statSync(path).isDirectory()) cb(null, fs.statSync(path).isDirectory())
} },
isFile (args, cb) { isFile: function (args, cb) {
const path = utils.absolutePath(args.path, this.currentSharedFolder) const path = utils.absolutePath(args.path, this.currentSharedFolder)
cb(null, fs.statSync(path).isFile()) cb(null, fs.statSync(path).isFile())
} },
setupNotifications (path) { setupNotifications: function (path) {
if (!isRealPath(path)) return if (!isRealPath(path)) return
var watcher = chokidar.watch(path, { depth: 0, ignorePermissionErrors: true }) var watcher = chokidar.watch(path, { depth: 0, ignorePermissionErrors: true })
console.log('setup notifications for ' + path) 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) => { watcher.on('change', (f, curr, prev) => {
if (this.trackDownStreamUpdate[f]) { if (this.trackDownStreamUpdate[f]) {
delete this.trackDownStreamUpdate[f] delete this.trackDownStreamUpdate[f]
...@@ -151,8 +163,7 @@ class SharedFolder extends PluginClient { ...@@ -151,8 +163,7 @@ class SharedFolder extends PluginClient {
if (this.websocket.connection) this.websocket.send(message('removed', { path: utils.relativePath(f, this.currentSharedFolder), isFolder: true })) if (this.websocket.connection) this.websocket.send(message('removed', { path: utils.relativePath(f, this.currentSharedFolder), isFolder: true }))
}) })
} }
})
}
function isRealPath (path, cb) { function isRealPath (path, cb) {
var realPath = fs.realpathSync(path) var realPath = fs.realpathSync(path)
...@@ -168,5 +179,3 @@ function isRealPath (path, cb) { ...@@ -168,5 +179,3 @@ function isRealPath (path, cb) {
function message (name, value) { function message (name, value) {
return JSON.stringify({ type: 'notification', scope: 'sharedfolder', name: name, value: value }) return JSON.stringify({ type: 'notification', scope: 'sharedfolder', name: name, value: value })
} }
\ No newline at end of file
module.exports = SharedFolder
{
"compilerOptions": {
/* Basic Options */
"target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
"declaration": true, /* Generates corresponding '.d.ts' file. */
"outDir": "./lib",
"strict": true, /* Enable all strict type-checking options. */
"strictPropertyInitialization": false, /* Enable strict checking of property initialization in classes. */
/* Experimental Options */
"experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
"emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
},
"exclude": ["./lib"]
}
\ No newline at end of file
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