Skip to content

Commit

Permalink
safer and better logging
Browse files Browse the repository at this point in the history
  • Loading branch information
mokkabonna committed Sep 1, 2013
1 parent abec6d4 commit 6f53b2d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 18 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "grunt-bower-verify",
"version": "0.2.4",
"version": "0.2.5",
"description": "> Install and test all your dependencies versions.",
"main": "tasks/verify.js",
"dependencies": {
Expand Down
46 changes: 29 additions & 17 deletions tasks/verify.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,36 +16,48 @@ module.exports = function(grunt) {
//install package
bower.commands.install([endpoint + (version ? '#' + version : '')], {
production: true,
verbose : isVerbose
verbose: isVerbose
}).on('end', handleInstallEnd).on('error', handleInstallError).on('log', handleLog);

function handleLog(data) {
grunt.verbose.writeln(data.id.cyan + (data.id.length < 7 ? '\t\t' : '\t') + data.message.yellow);
try {
grunt.verbose.writeln(data.id.cyan + (data.id.length < 7 ? '\t\t' : '\t') + data.message.yellow);
} catch (e) {
grunt.log.writeln('log data not as expected');
}
}

function handleInstallEnd(packages) {
if (!Object.keys(packages).length) log('Installed\t'.cyan + name);
try {
if (!Object.keys(packages).length) log('Installed\t'.cyan + name);

grunt.util._.each(packages, function(package) {
log('Installed\t'.cyan + (package.pkgMeta.name + '#' + package.pkgMeta.version).yellow);
});
grunt.util._.each(packages, function(package) {
log('Installed\t'.cyan + (package.pkgMeta.name + '#' + package.pkgMeta.version).yellow);
});
} catch (e) {
log('Install data not as expected.');
}

done();
}

function handleInstallError(err) {

if (err.code === 'ECONFLICT') log('Incompatible version '.red + name);

err.picks.forEach(function(pick) {
pick.dependants.forEach(function(dependant) {
grunt.util._.each(dependant.pkgMeta.dependencies, function(dependantVersion, dependency) {
if (err.name !== dependency) return; //don't print packages that isn't relevant here
if (semver.satisfies(version, dependantVersion)) return; //don't print for dependants that are satisfied
log('Package '.cyan + dependant.pkgMeta.name.yellow + ' requires '.green + (dependency + '#' + dependantVersion).yellow);
try {
if (err.code === 'ECONFLICT') log('Incompatible version '.red + name);

err.picks.forEach(function(pick) {
pick.dependants.forEach(function(dependant) {
grunt.util._.each(dependant.pkgMeta.dependencies, function(dependantVersion, dependency) {
if (err.name !== dependency) return; //don't print packages that isn't relevant here
if (semver.satisfies(version, dependantVersion)) return; //don't print for dependants that are satisfied
log('Package '.cyan + dependant.pkgMeta.name.yellow + ' requires '.green + (dependency + '#' + dependantVersion).yellow);
});
});
});
});

} catch (e) {
log('Error data not as expected.');
}

done();
}
Expand Down Expand Up @@ -87,7 +99,7 @@ module.exports = function(grunt) {
var versions = data.versions.filter(function(version) {
//Skip versions that does not satisfy the bower.json version
if (!semver.satisfies(version, mustSatisfy)) {
grunt.verbose.writeln('Ignoring '.cyan +(endpoint + '#' + version).yellow + ' does not satisfy '.cyan + mustSatisfy.yellow);
grunt.verbose.writeln('Ignoring '.cyan + (endpoint + '#' + version).yellow + ' does not satisfy '.cyan + mustSatisfy.yellow);
return false;
}
return true;
Expand Down

0 comments on commit 6f53b2d

Please sign in to comment.