#!/usr/bin/env node var Router = require('../src/router') var servicesList = require('../src/servicesList') var program = require('commander') var startmistGeth = require('../src/services/startMistGeth') var startFrontend = require('../src/services/startFrontend') var vyper = require('../src/services/vyper') var fs = require('fs-extra') program .usage('-s ') .description('Provide a two-way connection between the local computer and Remix IDE') .option('--remix-ide ', 'URL of remix instance allowed to connect to this web sockect connection') .option('-s, --shared-folder ', 'Folder to share with Remix IDE') .option('--read-only', 'Treat shared folder as read-only (experimental)') .option('--vyper', 'Run a local vyper compiler') .option('-m, --mist', 'start mist') .option('-g, --geth', 'start geth') .option('-p, --dev-path ', 'Folder used by mist/geth to start the development instance') .option('-f, --frontend ', 'Folder that should be served by remixd') .option('-p, --frontend-port ', 'Http port used by the frontend (default 8082)') .option('-a, --auto-mine', 'mine pending transactions') .option('-r, --rpc ', 'start rpc server. Values are CORS domain') .option('-rp, --rpc-port', 'rpc server port (default 8545)') .on('--help', function(){ console.log('\nExample:\n\n remixd --dev-path /home/devchains/chain1 --mist --geth --frontend /home/frontend --frontend-port 8084 --auto-mine') }).parse(process.argv) var killCallBack = [] if (program.vyper) { console.log('starting vyper compiler') vyper() } if (!program.remixIde) { return 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.devPath) { if (fs.existsSync(program.devPath)) { killCallBack.push(startmistGeth(program.devPath, program.mist, program.geth, program.autoMine, program.rpc, program.rpcPort)) } else { console.log('\x1b[31m%s\x1b[0m', '[ERR] can\'t start mist/geth. ' + program.devPath + ' does not exist') } } if (program.frontend) { if (!program.frontendPort) program.frontendPort = 8082 if (fs.existsSync(program.frontend)) { killCallBack.push(startFrontend(program.frontend, program.frontendPort)) } else { console.log('\x1b[31m%s\x1b[0m', '[ERR] can\'t start frontend. ' + program.frontend + ' does not exist') } } 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] Symbolinc links are not forwarded to Remix IDE\n') var sharedFolderrouter = new Router(65520, servicesList['sharedfolder'], { remixIdeUrl: program.remixIde }, (webSocket) => { servicesList['sharedfolder'].setWebSocket(webSocket) servicesList['sharedfolder'].setupNotifications(program.sharedFolder) servicesList['sharedfolder'].sharedFolder(program.sharedFolder, program.readOnly || false) }) 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)