Skip to content

Commit

Permalink
feature(cloudcmd) add ability to disable console with "--no-console" (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
coderaiser committed Nov 10, 2016
1 parent 9d3556e commit c8653eb
Show file tree
Hide file tree
Showing 11 changed files with 85 additions and 12 deletions.
2 changes: 2 additions & 0 deletions HELP.md
Expand Up @@ -85,6 +85,7 @@ Cloud Commander supports command line parameters:
| `--no-progress` | do not show progress of file operations
| `--no-one-panel-mode` | unset one panel mode
| `--no-config-dialog` | disable config dialog
| `--no-console` | disable console

If no parameters given Cloud Commander reads information from `~/.cloudcmd.json` and use
port from it (`8000` default). if port variables `PORT` or `VCAP_APP_PORT` isn't exist.
Expand Down Expand Up @@ -234,6 +235,7 @@ Here is description of options:
"progress" : true, /* show progress of file operations */
"onePanelMode" : false, /* set one panel mode */
"configDialog" : true /* enable config dialog */
"console" : true /* enable console */
}
```

Expand Down
3 changes: 3 additions & 0 deletions bin/cloudcmd.js
Expand Up @@ -32,6 +32,7 @@ var Info = require('../package'),
'open',
'minify',
'progress',
'console',
'config-dialog',
'one-panel-mode'
],
Expand All @@ -47,6 +48,7 @@ var Info = require('../package'),
root : config('root') || '/',
prefix : config('prefix') || '',
progress : config('progress'),
console : defaultTrue(config('console')),

'config-dialog': defaultTrue(config('configDialog')),
'one-panel-mode': config('onePanelMode'),
Expand Down Expand Up @@ -84,6 +86,7 @@ if (args.version) {
config('minify', args.minify);
config('username', args.username);
config('progress', args.progress);
config('console', args.console);
config('prefix', args.prefix);
config('root', args.root);
config('onePanelMode', args['one-panel-mode']);
Expand Down
4 changes: 3 additions & 1 deletion json/config.json
Expand Up @@ -21,5 +21,7 @@
"prefix": "",
"progress": true,
"onePanelMode": false,
"configDialog": true
"configDialog": true,
"console": true
}

2 changes: 2 additions & 0 deletions json/help.json
Expand Up @@ -15,6 +15,7 @@
"--progress ": "show progress of file operations",
"--one-panel-mode ": "set one panel mode",
"--config-dialog ": "enable config dialog",
"--console ": "enable console",
"--open ": "open web browser when server started",
"--no-server ": "do not start server",
"--no-auth ": "disable authorization",
Expand All @@ -24,4 +25,5 @@
"--no-progress ": "do not show progress of file operations",
"--no-one-panel-mode ": "unset one panel mode",
"--no-config-dialog ": "disable config dialog"
"--no-console ": "disable console"
}
2 changes: 0 additions & 2 deletions lib/client/key.js
Expand Up @@ -333,13 +333,11 @@ var CloudCmd, Util, DOM;
break;

case Key.TRA:
DOM.Images.show.load('top');
CloudCmd.Konsole.show();
event.preventDefault();
break;

case KEY.BRACKET_CLOSE:
DOM.Images.show.load('top');
CloudCmd.Konsole.show();
event.preventDefault();
break;
Expand Down
10 changes: 9 additions & 1 deletion lib/client/konsole.js
Expand Up @@ -110,7 +110,15 @@
Util.time(Name + ' load');
}

init();
DOM.Files.get('config', function(error, config) {
if (error)
return Dialog.alert(TITLE, error);

if (!config.console)
return;

init();
});
}

})(CloudCmd, Util, DOM);
12 changes: 6 additions & 6 deletions lib/cloudcmd.js
Expand Up @@ -108,12 +108,6 @@ function listen(prefix, socket) {

config.listen(socket, authCheck);

webconsole({
prefix: prefix + '/console',
socket: socket,
authCheck: authCheck
});

edward.listen(socket, {
size: size,
root: root,
Expand Down Expand Up @@ -152,6 +146,12 @@ function listen(prefix, socket) {
prefix: prefix + '/ishtar',
authCheck: authCheck
});

config('console') && webconsole({
prefix: prefix + '/console',
socket: socket,
authCheck: authCheck
});
}

function cloudcmd(prefix) {
Expand Down
9 changes: 7 additions & 2 deletions lib/server/route.js
Expand Up @@ -64,7 +64,8 @@ function indexProcessing(options) {
right = '',
keysPanel = '<div id="js-keyspanel" class="{{ className }}',
isOnePanel = config('onePanelMode'),
isConfig = config('configDialog'),
noConfig = !config('configDialog'),
noConsole = !config('console'),
data = options.data,
panel = options.panel;

Expand All @@ -85,10 +86,14 @@ function indexProcessing(options) {
.replace('icon-move', 'icon-move none')
.replace('icon-copy', 'icon-copy none');

if (!isConfig)
if (noConfig)
data = data
.replace('icon-config', 'icon-config none');

if (noConsole)
data = data
.replace('icon-console', 'icon-console none');

left = rendy(Template.panel, {
side : 'left',
content : panel,
Expand Down
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -140,6 +140,7 @@
"redrun": "^5.0.0",
"request": "^2.76.0",
"shortdate": "^1.0.1",
"socket.io-client": "^1.5.1",
"stylelint": "^7.0.2",
"stylelint-config-standard": "^14.0.0",
"tape": "^4.4.0",
Expand Down
4 changes: 4 additions & 0 deletions test/before.js
Expand Up @@ -4,6 +4,7 @@ const http = require('http');
const os = require('os');

const express = require('express');
const io = require('socket.io');
const writejson = require('writejson');
const readjson = require('readjson');

Expand All @@ -23,7 +24,10 @@ module.exports = (config, fn = config) => {
server.close();
};

const socket = io.listen(server);

app.use(cloudcmd({
socket,
config: assign(defaultConfig(), config)
}));

Expand Down
48 changes: 48 additions & 0 deletions test/console.js
@@ -0,0 +1,48 @@
'use strict';

const test = require('tape');
const promisify = require('es6-promisify');
const pullout = require('pullout');
const request = require('request');
const io = require('socket.io-client');

const before = require('./before');

const warp = (fn, ...a) => (...b) => fn(...b, ...a);

const _pullout = promisify(pullout);

const get = promisify((url, fn) => {
fn(null, request(url));
});

test('cloudcmd: console: enabled', (t) => {
const config = {console: true};

before(config,(port, after) => {
const socket = io(`http://localhost:${port}/console`)

socket.once('data', (data) => {
socket.close();
t.equal(data, 'client #1 console connected\n', 'should emit data event');
after();
t.end();
});
});
});

test('cloudcmd: console: disabled', (t) => {
const config = {console: false};

before(config,(port, after) => {
const socket = io(`http://localhost:${port}/console`);

socket.on('error', (error) => {
t.equal(error, 'Invalid namespace', 'should emit error');
socket.close();
after();
t.end();
});
});
});

0 comments on commit c8653eb

Please sign in to comment.