#!/usr/bin/env node
|
|
|
|
var colors = require('colors');
|
|
var docopt = require('docopt');
|
|
var tend = require('../');
|
|
|
|
var doc = [
|
|
'Usage:',
|
|
' tend',
|
|
' tend <action>',
|
|
' tend [--restart] [--start] [--ignoreHidden] [--filter <filter>] [<dir> <command>]',
|
|
' tend (--help | --version)',
|
|
'',
|
|
'Options:',
|
|
' -h --help Show this help text',
|
|
' -v --version Show tend version information',
|
|
' -r --restart If <command> is still running when there is a change, stop and re-run it',
|
|
' -i --ignoreHidden Ignore changes to files which start with "."',
|
|
' -f --filter <filter> Use <filter> regular expression to filter which files trigger the command',
|
|
' -s --start Run <command> as soon as tend executes',
|
|
].join('\r\n');
|
|
|
|
var args = docopt.docopt(doc, {
|
|
help: true,
|
|
version: 'tend ' + require('../package.json').version,
|
|
});
|
|
|
|
var config = tend.parseConfig();
|
|
if (!config && !args['<dir>'] && !args['<command>']) {
|
|
console.error('No .tendrc file found, must run with "<dir> <command>"'.red);
|
|
process.exit(1);
|
|
}
|
|
|
|
if (config && args['<action>']) {
|
|
var action = args['<action>'];
|
|
if (!config[action]) {
|
|
console.error(('Action ' + action + ' not found in .tendrc file').red);
|
|
process.exit(1);
|
|
}
|
|
|
|
var newConfig = {};
|
|
newConfig[action] = config[action];
|
|
newConfig[action].runOnce = true;
|
|
newConfig[action].start = true;
|
|
config = newConfig;
|
|
}
|
|
|
|
if (!config) {
|
|
config = {};
|
|
}
|
|
|
|
if (args['<dir>'] && args['<command>']) {
|
|
config['cli'] = {
|
|
filter: args['<filter>'],
|
|
ignoreHidden: args['--ignoreHidden'],
|
|
restart: args['--restart'],
|
|
start: args['--start'],
|
|
command: args['<command>'],
|
|
directory: args['<dir>'],
|
|
}
|
|
}
|
|
|
|
for (var key in config) {
|
|
console.log(('Starting listener: ' + key).green);
|
|
var options = config[key];
|
|
tend.tend(options.directory, options.command, options);
|
|
}
|