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 6b26b26 commit c3c008f
Show file tree
Hide file tree
Showing 12 changed files with 79 additions and 14 deletions.
5 changes: 4 additions & 1 deletion HELP.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ Cloud Commander supports command line parameters:
| `--open` | open web browser when server started
| `--one-panel-mode` | set one panel mode
`--config-dialog` | enable config dialog
`--console` | enable console
| `--no-server` | do not start server
| `--no-auth` | disable authorization
| `--no-online` | load scripts from local server
Expand All @@ -85,6 +86,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 @@ -233,7 +235,8 @@ Here is description of options:
"prefix" : "", /* url prefix */
"progress" : true, /* show progress of file operations */
"onePanelMode" : false, /* set one panel mode */
"configDialog" : true /* enable config dialog */
"configDialog" : true, /* enable config dialog */
"console" : true /* enable console */
}
```

Expand Down
3 changes: 3 additions & 0 deletions bin/cloudcmd.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,7 @@
"prefix": "",
"progress": true,
"onePanelMode": false,
"configDialog": true
"configDialog": true,
"console": true
}

4 changes: 3 additions & 1 deletion json/help.json
Original file line number Diff line number Diff line change
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 @@ -23,5 +24,6 @@
"--no-minify ": "disable minification",
"--no-progress ": "do not show progress of file operations",
"--no-one-panel-mode ": "unset one panel mode",
"--no-config-dialog ": "disable config dialog"
"--no-config-dialog ": "disable config dialog",
"--no-console ": "disable console"
}
2 changes: 0 additions & 2 deletions lib/client/key.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
2 changes: 2 additions & 0 deletions man/cloudcmd.1
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ programs in browser from any computer, mobile or tablet device.
--open open web browser when server started
--one-panel-mode set one panel mode
--config-dialog enable config dialog
--console enable console
--no-auth disable authorization
--no-server do not start server
--no-online load scripts from local server
Expand All @@ -47,6 +48,7 @@ programs in browser from any computer, mobile or tablet device.
--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

.SH RESOURCES AND DOCUMENTATION

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
37 changes: 37 additions & 0 deletions test/console.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
'use strict';

const test = require('tape');
const io = require('socket.io-client');

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

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 c3c008f

Please sign in to comment.