UNPKG

2.23 kBJavaScriptView Raw
1#!/usr/bin/env node
2"use strict";
3Object.defineProperty(exports, "__esModule", { value: true });
4var websocket_1 = require("../src/websocket");
5var servicesList = require("../src/serviceList");
6var program = require('commander');
7program
8 .usage('-s <shared folder>')
9 .description('Provide a two-way connection between the local computer and Remix IDE')
10 .option('--remix-ide <url>', 'URL of remix instance allowed to connect to this web sockect connection')
11 .option('-s, --shared-folder <path>', 'Folder to share with Remix IDE')
12 .option('--read-only', 'Treat shared folder as read-only (experimental)')
13 .on('--help', function () {
14 console.log('\nExample:\n\n remixd -s ./ --remix-ide http://localhost:8080');
15}).parse(process.argv);
16var killCallBack = [];
17if (!program.remixIde) {
18 console.log('\x1b[31m%s\x1b[0m', '[ERR] URL Remix IDE instance has to be provided.');
19}
20console.log('\x1b[33m%s\x1b[0m', '[WARN] You may now only use IDE at ' + program.remixIde + ' to connect to that instance');
21if (program.sharedFolder) {
22 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.');
23 console.log('\x1b[33m%s\x1b[0m', '[WARN] Symbolic links are not forwarded to Remix IDE\n');
24 try {
25 var sharedFolderClient_1 = new servicesList['sharedfolder']();
26 var websocketHandler = new websocket_1.default(65520, { remixIdeUrl: program.remixIde }, sharedFolderClient_1);
27 websocketHandler.start(function (ws) {
28 sharedFolderClient_1.setWebSocket(ws);
29 sharedFolderClient_1.setupNotifications(program.sharedFolder);
30 sharedFolderClient_1.sharedFolder(program.sharedFolder, program.readOnly || false);
31 });
32 killCallBack.push(websocketHandler.close.bind(websocketHandler));
33 }
34 catch (error) {
35 throw new Error(error);
36 }
37}
38// kill
39function kill() {
40 for (var k in killCallBack) {
41 try {
42 killCallBack[k]();
43 }
44 catch (e) {
45 console.log(e);
46 }
47 }
48}
49process.on('SIGINT', kill); // catch ctrl-c
50process.on('SIGTERM', kill); // catch kill
51process.on('exit', kill);