Skip to content

Commit

Permalink
FEAT: dashboard option added
Browse files Browse the repository at this point in the history
  • Loading branch information
royriojas committed Feb 3, 2017
1 parent 27f141e commit a25a923
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .cache/.cache_15qy1o4
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"/Users/roy/royws/shell-executor/source/src/process.js":{"size":26,"mtime":1483338490000,"hashOfConfig":"suduii","results":{"filePath":"/Users/roy/royws/shell-executor/source/src/process.js","messages":[],"errorCount":0,"warningCount":0}},"/Users/roy/royws/shell-executor/source/bin/cli.js":{"size":182,"mtime":1484751608000,"hashOfConfig":"suduii","results":{"filePath":"/Users/roy/royws/shell-executor/source/bin/cli.js","messages":[],"errorCount":0,"warningCount":0}},"/Users/roy/royws/shell-executor/source/src/options.js":{"size":676,"mtime":1484751608000,"hashOfConfig":"suduii","results":{"filePath":"/Users/roy/royws/shell-executor/source/src/options.js","messages":[],"errorCount":0,"warningCount":0}},"/Users/roy/royws/shell-executor/source/time-manager.js":{"size":390,"mtime":1484751608000,"hashOfConfig":"suduii","results":{"filePath":"/Users/roy/royws/shell-executor/source/time-manager.js","messages":[],"errorCount":0,"warningCount":0}},"/Users/roy/royws/shell-executor/source/index.js":{"size":2879,"mtime":1484751986000,"hashOfConfig":"suduii","results":{"filePath":"/Users/roy/royws/shell-executor/source/index.js","messages":[],"errorCount":0,"warningCount":0}},"/Users/roy/royws/shell-executor/source/src/main.js":{"size":3272,"mtime":1484752318000,"hashOfConfig":"suduii","results":{"filePath":"/Users/roy/royws/shell-executor/source/src/main.js","messages":[],"errorCount":0,"warningCount":0}},"/Users/roy/royws/shell-executor/specs/index.spec.js":{"size":1072,"mtime":1484752145000,"hashOfConfig":"suduii","results":{"filePath":"/Users/roy/royws/shell-executor/specs/index.spec.js","messages":[],"errorCount":0,"warningCount":0}}}
{"/Users/roy/royws/shell-executor/source/src/process.js":{"size":26,"mtime":1483338490000,"hashOfConfig":"suduii","results":{"filePath":"/Users/roy/royws/shell-executor/source/src/process.js","messages":[],"errorCount":0,"warningCount":0}},"/Users/roy/royws/shell-executor/source/bin/cli.js":{"size":199,"mtime":1484752574000,"hashOfConfig":"suduii","results":{"filePath":"/Users/roy/royws/shell-executor/source/bin/cli.js","messages":[],"errorCount":0,"warningCount":0}},"/Users/roy/royws/shell-executor/source/src/options.js":{"size":849,"mtime":1486104641000,"hashOfConfig":"suduii","results":{"filePath":"/Users/roy/royws/shell-executor/source/src/options.js","messages":[],"errorCount":0,"warningCount":0}},"/Users/roy/royws/shell-executor/source/time-manager.js":{"size":390,"mtime":1484751608000,"hashOfConfig":"suduii","results":{"filePath":"/Users/roy/royws/shell-executor/source/time-manager.js","messages":[],"errorCount":0,"warningCount":0}},"/Users/roy/royws/shell-executor/source/index.js":{"size":2879,"mtime":1484751986000,"hashOfConfig":"suduii","results":{"filePath":"/Users/roy/royws/shell-executor/source/index.js","messages":[],"errorCount":0,"warningCount":0}},"/Users/roy/royws/shell-executor/specs/index.spec.js":{"size":1019,"mtime":1486103628000,"hashOfConfig":"suduii","results":{"filePath":"/Users/roy/royws/shell-executor/specs/index.spec.js","messages":[],"errorCount":0,"warningCount":0}},"/Users/roy/royws/shell-executor/source/src/grid.js":{"size":1195,"mtime":1486106523000,"hashOfConfig":"suduii","results":{"filePath":"/Users/roy/royws/shell-executor/source/src/grid.js","messages":[],"errorCount":0,"warningCount":0,"output":"import blessed from 'blessed';\nimport contrib from 'blessed-contrib';\nimport spawn from 'spawnly';\n\nexport const getGridAndScreen = () => {\n const screen = blessed.screen();\n const grid = new contrib.grid({ rows: 12, cols: 12, screen }); // eslint-disable-line\n\n return {\n screen,\n grid,\n };\n};\n\nconst getPositionByIndex = (index) => {\n const positions = [\n { row: 0, col: 0 },\n { row: 0, col: 4 },\n { row: 0, col: 8 },\n { row: 6, col: 0 },\n { row: 6, col: 4 },\n { row: 6, col: 8 },\n ];\n\n return positions[index];\n};\n\nexport const setProcessLogToGrid = (cmd, grid, index) => {\n const { row, col } = getPositionByIndex(index);\n\n const log = grid.set(row, col, 4, 6, contrib.log, {\n fg: 'green',\n selectedFg: 'green',\n label: cmd.substr(0, 40),\n });\n\n const addListener = (stream) => {\n if (!stream.readable) return;\n stream.on('data', chunk =>\n log.log(chunk.toString()),\n );\n };\n\n return {\n start: () => {\n const cp = spawn(cmd, { stdio: 'pipe' });\n\n addListener(cp.stdout);\n addListener(cp.stderr);\n\n cp.on('close', (exitCode) => {\n log.log(`process exit with code ${ exitCode }`);\n });\n },\n };\n};\n"}},"/Users/roy/royws/shell-executor/source/src/main.js":{"size":3747,"mtime":1486106600000,"hashOfConfig":"suduii","results":{"filePath":"/Users/roy/royws/shell-executor/source/src/main.js","messages":[],"errorCount":0,"warningCount":0}}}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"build": "babel source/ -d dist/"
},
"bin": {
"sx": "./dist/bin/cli.js",
"shell-exec": "./dist/bin/cli.js"
},
"repository": {
Expand Down
56 changes: 56 additions & 0 deletions source/src/grid.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import blessed from 'blessed';
import contrib from 'blessed-contrib';
import spawn from 'spawnly';

export const getGridAndScreen = () => {
const screen = blessed.screen();
const grid = new contrib.grid({ rows: 12, cols: 12, screen }); // eslint-disable-line

return {
screen,
grid,
};
};

const getPositionByIndex = (index) => {
const positions = [
{ row: 0, col: 0 },
{ row: 0, col: 4 },
{ row: 0, col: 8 },
{ row: 6, col: 0 },
{ row: 6, col: 4 },
{ row: 6, col: 8 },
];

return positions[index];
};

export const setProcessLogToGrid = (cmd, grid, index) => {
const { row, col } = getPositionByIndex(index);

const log = grid.set(row, col, 6, 4, contrib.log, {
fg: 'green',
selectedFg: 'green',
label: cmd.substr(0, 40),
});

const addListener = (stream) => {
if (!stream.readable) return;
stream.on('data', chunk =>
log.log(chunk.toString()),
);
};

return {
start: () => {
const cp = spawn(cmd, { stdio: 'pipe' });

addListener(cp.stdout);
addListener(cp.stderr);

cp.on('close', (exitCode) => {
log.log(`process exit with code ${ exitCode }`);
});
},
};
};
35 changes: 27 additions & 8 deletions source/src/main.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { getGridAndScreen, setProcessLogToGrid } from './grid';

const exec = require('child_process').exec;
const path = require('path');
const nodeProcess = require('./process');
Expand Down Expand Up @@ -30,7 +32,19 @@ const printFailed = entries =>
return seq;
}, '\n');


module.exports = {
_executeCommandsInDashboard(program, cmds) {

const { grid, screen } = getGridAndScreen();

cmds.forEach((cmd, index) => {
const command = setProcessLogToGrid(cmd, grid, index);
command.start();
});

screen.render();
},
_execute(program, cmds) {
const cmdManager = manager.create(); // eslint-disable-line

Expand Down Expand Up @@ -108,22 +122,27 @@ module.exports = {
});
},
async run(program) {

const cmds = program.opts._;
const { opts, error, showHelp } = program;
const cmds = opts._;

if (cmds.length === 0) {
program.error('please provide some commands to execute');
program.showHelp();
error('please provide some commands to execute');
showHelp();
return;
}

try {
await addNPMBinToPath();
} catch ({ error, stderr }) {
program.error('received error', error);
stderr && program.error(stderr);
} catch ({ error: err, stderr }) {
error('received error', err);
stderr && error(stderr);
process.exit(1); // eslint-disable-line
}

this._execute(program, cmds);
if (opts.dashboard) {
this._executeCommandsInDashboard(program, cmds);
} else {
this._execute(program, cmds);
}
},
};
6 changes: 6 additions & 0 deletions source/src/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ module.exports = {
{
heading: 'Options',
},
{
option: 'dashboard',
alias: 'd',
type: 'Boolean',
description: 'Show the processes in a nice dashboard if space allows it',
},
{
option: 'bail',
alias: 'b',
Expand Down
3 changes: 1 addition & 2 deletions specs/index.spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const cmdManager = require('../source/index');
import cmdManager from '../source/index';

describe('index', () => {
// var proxyquire = require( 'proxyquire' );

describe('create', () => {
it('should return an instance of a cmdManager', () => {
Expand Down

0 comments on commit a25a923

Please sign in to comment.