mirror of
https://github.com/bower/bower.git
synced 2026-02-12 06:55:04 -05:00
77 lines
1.7 KiB
JavaScript
Executable File
77 lines
1.7 KiB
JavaScript
Executable File
#!/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 options;
|
|
var command;
|
|
var renderer;
|
|
var levels;
|
|
|
|
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);
|
|
}); |