Modified app bootstrap and types

pull/3094/head
ioedeveloper 5 years ago
parent f995d09098
commit f15109ebae
  1. 18
      bin/remixd.ts
  2. 3
      src/serviceList.ts
  3. 14
      src/services/remixdClient.ts
  4. 9
      src/utils.ts
  5. 9
      src/websocket.ts
  6. 22
      types/index.ts

@ -1,6 +1,7 @@
#!/usr/bin/env node #!/usr/bin/env node
import WebSocket from '../src/websocket' import WebSocket from '../src/websocket'
import RemixdClient from '../src/services/remixdClient' import * as servicesList from '../src/serviceList'
const program = require('commander') const program = require('commander')
program program
@ -23,10 +24,19 @@ console.log('\x1b[33m%s\x1b[0m', '[WARN] You may now only use IDE at ' + program
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')
const websocketHandler = new WebSocket(65520, { remixIdeUrl: program.remixIde }, new RemixdClient()) try {
const websocketHandler = new WebSocket(65520, { remixIdeUrl: program.remixIde }, servicesList['sharedfolder'])
websocketHandler.start(() => {
const remixdClient = new servicesList['sharedfolder']()
websocketHandler.start() remixdClient.setWebSocket(websocketHandler)
killCallBack.push(websocketHandler.close.bind(websocketHandler)) remixdClient.sharedFolder(program.sharedFolder, program.readOnly || false)
})
killCallBack.push(websocketHandler.close.bind(websocketHandler))
} catch(error) {
throw new Error(error)
}
} }
// kill // kill

@ -0,0 +1,3 @@
import { RemixdClient as sharedfolder } from './services/remixdClient'
export { sharedfolder }

@ -1,12 +1,12 @@
import WebSocket from '../websocket' import WebSocket from '../websocket'
import { PluginClient } from '@remixproject/plugin' import { PluginClient } from '@remixproject/plugin'
import { SharedFolderArgs, TrackDownStreamUpdate } from '../../types' import { SharedFolderArgs, TrackDownStreamUpdate } from '../../types'
import * as utils from '../utils'
const utils = require('../utils')
const isbinaryfile = require('isbinaryfile') const isbinaryfile = require('isbinaryfile')
const fs = require('fs-extra') const fs = require('fs-extra')
export default class RemixdClient extends PluginClient { export class RemixdClient extends PluginClient {
methods: ['folderIsReadOnly', 'resolveDirectory'] methods: ['folderIsReadOnly', 'resolveDirectory']
trackDownStreamUpdate: TrackDownStreamUpdate trackDownStreamUpdate: TrackDownStreamUpdate
websocket: WebSocket | null websocket: WebSocket | null
@ -30,14 +30,18 @@ export default class RemixdClient extends PluginClient {
} }
} }
resolveDirectory (args: SharedFolderArgs, cb: Function) { resolveDirectory (args: SharedFolderArgs) {
console.log('args: ', args)
console.log('called resolveDirectory!') console.log('called resolveDirectory!')
try { try {
console.log('called try resolveDirectory!')
const path = utils.absolutePath(args.path, this.currentSharedFolder) const path = utils.absolutePath(args.path, this.currentSharedFolder)
cb(null, utils.resolveDirectory(path, this.currentSharedFolder)) const result = utils.resolveDirectory(path, this.currentSharedFolder)
console.log('result: ', result)
} catch (e) { } catch (e) {
cb(e.message) console.log('called catch resolveDirectory!')
throw new Error(e)
} }
} }

@ -5,13 +5,6 @@ const path = require('path')
const isbinaryfile = require('isbinaryfile') const isbinaryfile = require('isbinaryfile')
const pathModule = require('path') const pathModule = require('path')
module.exports = {
absolutePath: absolutePath,
relativePath: relativePath,
walkSync: walkSync,
resolveDirectory: resolveDirectory
}
/** /**
* returns the absolute path of the given @arg path * returns the absolute path of the given @arg path
* *
@ -79,3 +72,5 @@ function resolveDirectory (dir: string, sharedFolder: string): ResolveDirectory
}) })
return ret return ret
} }
export { absolutePath, relativePath, walkSync, resolveDirectory }

@ -1,15 +1,15 @@
import * as WS from 'ws' import * as WS from 'ws'
import * as http from 'http' import * as http from 'http'
import RemixdClient from './services/remixdClient' import { WebsocketOpt, SharedFolder } from '../types'
import { WebsocketOpt } from '../types'
const { buildWebsocketClient } = require('@remixproject/plugin-ws') const { buildWebsocketClient } = require('@remixproject/plugin-ws')
export default class WebSocket { export default class WebSocket {
server: http.Server server: http.Server
wsServer: WS.Server wsServer: WS.Server
connection: WS
constructor (public port: number, public opt: WebsocketOpt, public remixdClient: RemixdClient) {} constructor (public port: number, public opt: WebsocketOpt, public remixdClient: SharedFolder) {}
start (callback?: Function) { start (callback?: Function) {
const obj = this const obj = this
@ -36,8 +36,9 @@ export default class WebSocket {
} }
}) })
this.wsServer.on('connection', function connection(ws, request) { this.wsServer.on('connection', function connection(ws, request) {
const client = buildWebsocketClient(ws, obj.remixdClient) const client = buildWebsocketClient(ws, new obj.remixdClient())
obj.connection = ws
if(callback) callback(client) if(callback) callback(client)
}) })
} }

@ -1,10 +1,14 @@
import * as ServiceList from '../src/serviceList'
type ServiceListKeys = keyof typeof ServiceList;
export type SharedFolder = typeof ServiceList[ServiceListKeys]
export type WebsocketOpt = { export type WebsocketOpt = {
remixIdeUrl: string remixIdeUrl: string
} }
export type SharedFolderArgs = { export type FolderArgs = {
path: string, path: string
[key: string]: string | number | boolean
} }
export type KeyPairString = { export type KeyPairString = {
@ -17,14 +21,6 @@ export type ResolveDirectory = {
} }
} }
export type WebsocketProfile = { export type TrackDownStreamUpdate = KeyPairString
name: string
methods?: string[]
permission?: boolean
hash?: string
redirect?: {
[key: string]: string
}
}
export type TrackDownStreamUpdate = KeyPairString export type SharedFolderArgs = FolderArgs & KeyPairString
Loading…
Cancel
Save