mirror of
https://github.com/bower/bower.git
synced 2026-01-22 20:58:08 -05:00
128 lines
3.1 KiB
JavaScript
Executable File
128 lines
3.1 KiB
JavaScript
Executable File
#!/usr/bin/env node
|
|
|
|
var path = require('path');
|
|
var tty = require('tty');
|
|
var mout = require('mout');
|
|
var updateNotifier = require('update-notifier');
|
|
var bower = require('../lib');
|
|
var pkg = require(path.join(__dirname, '..', 'package.json'));
|
|
var cli = require('../lib/util/cli');
|
|
var Logger = require('../lib/core/Logger');
|
|
|
|
// --------
|
|
|
|
var options;
|
|
var renderer;
|
|
var loglevel;
|
|
var command;
|
|
var commandFunc;
|
|
var emitter;
|
|
var notifier;
|
|
var levels = Logger.LEVELS;
|
|
|
|
process.title = 'bower';
|
|
|
|
// Handle print of version
|
|
options = cli.readOptions({
|
|
version: { type: Boolean, shorthand: 'v' },
|
|
help: { type: Boolean, shorthand: 'h' }
|
|
});
|
|
|
|
if (options.version) {
|
|
process.stdout.write(pkg.version + '\n');
|
|
process.exit();
|
|
}
|
|
|
|
// Set loglevel
|
|
if (bower.config.silent) {
|
|
loglevel = levels.error;
|
|
} else if (bower.config.verbose) {
|
|
loglevel = -Infinity;
|
|
} else if (bower.config.quiet) {
|
|
loglevel = levels.warn;
|
|
} else {
|
|
loglevel = levels[bower.config.loglevel] || levels.info;
|
|
}
|
|
|
|
// Enable interactive if terminal is TTY,
|
|
// loglevel is equal or lower then conflict
|
|
bower.config.interactive = tty.isatty(1) && loglevel <= levels.conflict;
|
|
|
|
// Get the command to execute
|
|
while (options.argv.remain.length) {
|
|
command = options.argv.remain.join(' ');
|
|
|
|
// Alias lookup
|
|
if (bower.abbreviations[command]) {
|
|
command = bower.abbreviations[command].replace(/\s/g, '.');
|
|
break;
|
|
}
|
|
|
|
command = command.replace(/s/g, '.');
|
|
|
|
// Direct lookup
|
|
if (mout.object.has(bower.commands, command)) {
|
|
break;
|
|
}
|
|
|
|
options.argv.remain.pop();
|
|
}
|
|
|
|
// Execute the command
|
|
commandFunc = command && mout.object.get(bower.commands, command);
|
|
command = command && command.replace(/\./g, ' ');
|
|
|
|
// If no command was specified, show bower help
|
|
// Do the same if the command is unknown
|
|
if (!commandFunc) {
|
|
emitter = bower.commands.help();
|
|
command = 'help';
|
|
// If the user requested help, show the command's help
|
|
// Do the same if the actual command is a group of other commands (e.g.: cache)
|
|
} else if (options.help || !commandFunc.line) {
|
|
emitter = bower.commands.help(command);
|
|
command = 'help';
|
|
// Call the line method
|
|
} else {
|
|
emitter = commandFunc.line(process.argv);
|
|
|
|
// If the method failed to interpret the process arguments
|
|
// show the command help
|
|
if (!emitter) {
|
|
emitter = bower.commands.help(command);
|
|
command = 'help';
|
|
}
|
|
}
|
|
|
|
// Get the renderer and configure it with the executed command
|
|
renderer = cli.getRenderer(command, emitter.json, bower.config);
|
|
|
|
emitter
|
|
.on('end', function (data) {
|
|
if (!bower.config.silent) {
|
|
renderer.end(data);
|
|
}
|
|
})
|
|
.on('error', function (err) {
|
|
if (levels.error >= loglevel) {
|
|
renderer.error(err);
|
|
}
|
|
|
|
process.exit(1);
|
|
})
|
|
.on('log', function (log) {
|
|
if (levels[log.level] >= loglevel) {
|
|
renderer.log(log);
|
|
}
|
|
});
|
|
|
|
// Check for newer version of Bower
|
|
notifier = updateNotifier({
|
|
packageName: pkg.name,
|
|
packageVersion: pkg.version
|
|
});
|
|
|
|
if (notifier.update && levels.info >= loglevel) {
|
|
renderer.updateNotice(notifier.update);
|
|
}
|