Skip to content

Commit

Permalink
include shell script to abort if dep not installed. closes #2
Browse files Browse the repository at this point in the history
  • Loading branch information
Ammar committed Feb 14, 2017
1 parent fce10d0 commit 42cde6c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
15 changes: 14 additions & 1 deletion lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ config.default_commands = {
kill_node: 'pgrep -n node | xargs kill -INT',
process_node_logs: `node --prof-process ./isolate-*`,
clean_up: `rm ./isolate-* ${config.default_dir}/${config.default_output} ${config.default_dir}/${config.default_profiling}`,
mac_path: 'if [ `uname` == "Darwin" ]; then source ~/.profile; fi'
mac_path: 'if [ `uname` == "Darwin" ]; then source ~/.profile; fi',
checks: ''
};

config.clock = {
Expand All @@ -38,3 +39,15 @@ config.loadtest = {
'auth': '-A'
}
};

config.functions = {
check_deps: function checkDependency (dep) {
const map = {
'ab': 'apt-get install apache2-utils',
'loadtest': 'npm install',
'gtime': 'brew install gnu-time'
}

return `command -v ${dep} >/dev/null 2>&1 || { echo >&2 "${dep} not installed. Please run ${map[dep]} to install, then try again. Exiting ... "; exit 1; }`;
}
}
8 changes: 6 additions & 2 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@ const config = require('./config'),

const utils = module.exports = exports = {};

// If not on Linux, fallback to `loadtest` and `gtime` programs for running tests
if (process.platform !== 'linux') {
// Platform specific dependencies
if (process.platform === 'linux') {
config.default_commands.checks = config.functions.check_deps('ab');
} else {
config.loadtest.program = 'loadtest';
config.clock.program = 'gtime --verbose';
config.default_commands.checks = [config.functions.check_deps('loadtest'), config.functions.check_deps('gtime')].join('\n');
}

/**
Expand Down Expand Up @@ -61,6 +64,7 @@ utils.mkdirIfNecessary = function () {

// path setup + file cleanup + before-hooks
cmds.push(`${config.default_commands.mac_path}`);
cmds.push(`${config.default_commands.checks}`);
cmds.push(`${config.default_commands.clean_up}`);
cmds.push(...app.beforeTasks);
cmds.push('\n');
Expand Down

0 comments on commit 42cde6c

Please sign in to comment.