#!/usr/bin/env node require('colors'); var path = require('path'); var mout = require('mout'); var pkg = require(path.join(__dirname, '..', 'package.json')); var cli = require('../lib/util/cli'); var commands = require('../lib/commands'); var updateNotifier = require('update-notifier'); // -------- var options; var command; var renderer; var levels; var notifier = updateNotifier({ packageName: pkg.name, packageVersion: pkg.version }); process.title = 'bower'; // Read CLI options options = cli.readOptions(process.argv, { version: { type: Boolean, shorthand: 'v' } }); // Handle print of version if (options.version) { process.stdout.write(pkg.version + '\n'); process.exit(); } // Parse log levels if (mout.object.hasOwn(options, 'log-levels')) { levels = (options['log-levels'] || '') .split(',') .map(function (level) { return level.trim(); }); } else { levels = ['action', 'warn']; } // Get the command to execute // TODO: abbreviations command = options.argv.remain && options.argv.remain.shift(); command = commands[command] || commands.help; // Get the renderer renderer = cli.getRenderer(options); // Execute the command renderer.begin(); command.line(process.argv) .on('data', function (data) { var func; // Check if this log level is allowed if (levels && levels.indexOf(data.level) === -1) { return; } // Attempt to use renderer function specified by the tag // Fallback to renderer.data if not found func = mout.string.camelCase(data.tag); if (!renderer[func]) { func = 'data'; } renderer[func](data); }) .on('end', function (data) { renderer.end(data); }) .on('error', function (err) { err.label = 'error'; err.tag = err.code ? err.code.toLowerCase() : 'error'; renderer.error(err); process.exit(1); }); if (notifier.update) { // TODO: This single line is inadequate. Make it more like it is in master. // I haven't done that until we have templating sorted. renderer.data({ level: 'warn', tag: 'update available', data: notifier.update.latest + ' (current: ' + notifier.update.current + ')' }); }