Files
bower/bin/bower_new
André Cruz 20ba998383 Implement the uninstall command.
Made also some tweaks to the render stuff.
2013-05-30 21:57:05 +01:00

93 lines
1.9 KiB
JavaScript
Executable File

#!/usr/bin/env node
require('colors');
var path = require('path');
var pkg = require(path.join(__dirname, '..', 'package.json'));
var config = require('../lib/config');
var cli = require('../lib/util/cli');
var commands = require('../lib/commands');
var updateNotifier = require('update-notifier');
// --------
var options;
var renderer;
var loglevel;
var command;
var notifier;
var levels = {
'error': 5,
'conflict': 4,
'warn': 3,
'action': 2,
'info': 1,
'debug': 0
};
process.title = 'bower';
// Handle print of version
options = cli.readOptions({
version: { type: Boolean, shorthand: 'v' }
});
if (options.version) {
process.stdout.write(pkg.version + '\n');
process.exit();
}
// Set loglevel
if (config.silent) {
loglevel = Infinity;
} else if (config.verbose) {
loglevel = -Infinity;
} else if (config.quiet) {
loglevel = levels.warn;
} else {
loglevel = levels[config.loglevel] || levels.info;
}
config.interactive = loglevel <= levels.conflict;
// Get the command to execute
// TODO: abbreviations
command = options.argv.remain && options.argv.remain.shift();
if (!commands[command]) {
command = 'help';
}
// Get the renderer
renderer = cli.getRenderer(command, config);
// Check for newer version of Bower
notifier = updateNotifier({
packageName: pkg.name,
packageVersion: pkg.version
});
if (notifier.update && levels.info >= loglevel) {
renderer.updateAvailable(notifier.update);
}
// Execute the command
commands[command].line(process.argv)
.on('end', function (data) {
if (config.silent) {
return;
}
renderer.end(data);
})
.on('error', function (err) {
if (levels.error >= loglevel) {
renderer.error(err);
}
process.exit(1);
})
.on('notification', function (notification) {
if (levels[notification.level] >= loglevel) {
renderer.notification(notification);
}
});