Setup typescript for remixd

remixd
ioedeveloper 5 years ago
parent 6ccf99926f
commit ea9783dba6
  1. 15
      bin/remixd.ts
  2. 6
      lib/remixd.d.ts
  3. 44
      lib/remixd.js
  4. 5
      nodemon.json
  5. 6924
      package-lock.json
  6. 16
      package.json
  7. 77
      src/services/sharedFolder.js
  8. 15
      tsconfig.json

@ -1,8 +1,7 @@
#!/usr/bin/env node
var Router = require('../src/router')
var servicesList = require('../src/servicesList')
var program = require('commander')
const { buildWebsocketClient } = require('@remixproject/plugin-ws')
const Router = require('../src/router')
const servicesList = require('../src/servicesList')
const program = require('commander')
program
.usage('-s <shared folder>')
@ -14,21 +13,21 @@ program
console.log('\nExample:\n\n remixd -s ./ --remix-ide http://localhost:8080')
}).parse(process.argv)
var killCallBack = []
const killCallBack: Array<Function> = []
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')
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 }, (webSocket) => {
const sharedFolderrouter = new Router(65520, servicesList['sharedfolder'], { remixIdeUrl: program.remixIde }, (webSocket: WebSocket) => {
servicesList['sharedfolder'].setWebSocket(webSocket)
servicesList['sharedfolder'].setupNotifications(program.sharedFolder)
servicesList['sharedfolder'].sharedFolder(program.sharedFolder, program.readOnly || false)
buildWebsocketClient(webSocket.connection, new servicesList['sharedfolder']())
// buildWebsocketClient(webSocket.connection, new servicesList['sharedfolder']())
})
killCallBack.push(sharedFolderrouter.start())
}

6
lib/remixd.d.ts vendored

@ -0,0 +1,6 @@
#!/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;

@ -0,0 +1,44 @@
#!/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);

@ -0,0 +1,5 @@
{
"watch": ["./src"],
"ext": "ts",
"exec": "npm run build"
}

6924
package-lock.json generated

File diff suppressed because it is too large Load Diff

@ -2,15 +2,16 @@
"name": "remixd",
"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)",
"main": "./src/index.js",
"main": "./lib/src/index.js",
"bin": {
"remixd": "./bin/remixd"
"remixd": "./lib/bin/remixd"
},
"scripts": {
"test": "echo \"Error: no test specified\"",
"start": "./bin/remixd",
"start": "./lib/bin/remixd",
"npip": "npip",
"lint": "eslint ./src"
"lint": "eslint ./src",
"build": "tsc -p ./"
},
"repository": {
"type": "git",
@ -44,11 +45,16 @@
}
},
"devDependencies": {
"@types/node": "^14.0.5",
"@types/websocket": "^1.0.0",
"eslint": "6.8.0",
"eslint-config-standard": "14.1.1",
"eslint-plugin-import": "2.20.2",
"eslint-plugin-node": "11.1.0",
"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')
var chokidar = require('chokidar')
const { PluginClient } = require('@remixproject/plugin')
class SharedFolder extends PluginClient {
trackDownStreamUpdate = {}
websocket = null
alreadyNotified = {}
Object.create(PluginClient, {
trackDownStreamUpdate: {},
websocket: null,
alreadyNotified: {},
setWebSocket (websocket) {
setWebSocket: function (websocket) {
this.websocket = websocket
}
},
sharedFolder (currentSharedFolder, readOnly) {
sharedFolder: function (currentSharedFolder, readOnly) {
this.currentSharedFolder = currentSharedFolder
this.readOnly = readOnly
if (this.websocket.connection) this.websocket.send(message('rootFolderChanged', {}))
}
},
list (args, cb) {
list: function (args, cb) {
try {
cb(null, utils.walkSync(this.currentSharedFolder, {}, this.currentSharedFolder))
} catch (e) {
cb(e.message)
}
}
},
resolveDirectory (args, cb) {
resolveDirectory: function (args, cb) {
try {
var path = utils.absolutePath(args.path, this.currentSharedFolder)
if (this.websocket && !this.alreadyNotified[path]) {
@ -38,13 +38,13 @@ class SharedFolder extends PluginClient {
} catch (e) {
cb(e.message)
}
}
},
folderIsReadOnly (args, cb) {
folderIsReadOnly: function (args, cb) {
return cb(null, this.readOnly)
}
},
get (args, cb) {
get: function (args, cb) {
var path = utils.absolutePath(args.path, this.currentSharedFolder)
if (!fs.existsSync(path)) {
return cb('File not found ' + path)
@ -61,15 +61,15 @@ class SharedFolder extends PluginClient {
})
}
})
}
},
exists (args, cb) {
exists: function (args, cb) {
const path = utils.absolutePath(args.path, this.currentSharedFolder)
cb(null, fs.existsSync(path))
}
},
set (args, cb) {
set: function (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)
@ -89,9 +89,9 @@ class SharedFolder extends PluginClient {
})
}).catch(e => cb(e))
}
}
},
rename (args, cb) {
rename: function (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)) {
@ -103,9 +103,9 @@ class SharedFolder extends PluginClient {
if (error) console.log(error)
cb(error, data)
})
}
},
remove (args, cb) {
remove: function (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)) {
@ -119,24 +119,36 @@ class SharedFolder extends PluginClient {
}
cb(error, true)
})
}
},
isDirectory (args, cb) {
isDirectory: function (args, cb) {
const path = utils.absolutePath(args.path, this.currentSharedFolder)
cb(null, fs.statSync(path).isDirectory())
}
},
isFile (args, cb) {
isFile: function (args, cb) {
const path = utils.absolutePath(args.path, this.currentSharedFolder)
cb(null, fs.statSync(path).isFile())
}
},
setupNotifications (path) {
setupNotifications: function (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]
@ -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 }))
})
}
}
})
function isRealPath (path, cb) {
var realPath = fs.realpathSync(path)
@ -167,6 +178,4 @@ function isRealPath (path, cb) {
function message (name, value) {
return JSON.stringify({ type: 'notification', scope: 'sharedfolder', name: name, value: value })
}
module.exports = SharedFolder
}

@ -0,0 +1,15 @@
{
"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"]
}
Loading…
Cancel
Save