Skip to content

Commit

Permalink
Merge b614b57 into 72b4a7a
Browse files Browse the repository at this point in the history
  • Loading branch information
jpaulin committed Jan 17, 2017
2 parents 72b4a7a + b614b57 commit 22bb114
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
21 changes: 21 additions & 0 deletions bin/david.js
Expand Up @@ -2,6 +2,7 @@

var david = require('../')
var clc = require('cli-color-tty')()
var ansi = require('ansi')
var Table = require('cli-table')
var fs = require('fs')
var path = require('path')
Expand All @@ -10,6 +11,9 @@ var argv = require('minimist')(process.argv.slice(2))
var xtend = require('xtend')
var exit = require('exit')

// Let's map a cursor to the terminal, to send ANSI escape sequences
var cursor = ansi(process.stdout)

if (argv.usage || argv.help || argv.h) {
console.log(fs.readFileSync(path.join(__dirname, 'usage.txt'), 'utf8'))
exit()
Expand All @@ -22,6 +26,11 @@ if (argv.version || argv.v) {

argv.update = argv._.indexOf('update') > -1 || argv._.indexOf('u') > -1

// Any necessary ANSI commands, that will ensure terminal staying nice after exit
function cleanUpTTY () {
cursor.show()
}

function getNonWarnDepNames (deps) {
return Object.keys(deps).reduce(function (names, name) {
if (!deps[name].warn) {
Expand Down Expand Up @@ -222,12 +231,14 @@ if (argv.global || argv.g) {
npm.load(opts, function (err) {
if (err) {
console.error('Failed to load npm', err)
cleanUpTTY()
exit(1)
}

npm.commands.ls([], true, function (err, data) {
if (err) {
console.error('Failed to list global dependencies', err)
cleanUpTTY()
exit(1)
}

Expand All @@ -243,20 +254,23 @@ if (argv.global || argv.g) {
getUpdatedDeps(pkg, function (err, deps) {
if (err) {
console.error('Failed to get updated dependencies/devDependencies', err)
cleanUpTTY()
exit(1)
}

if (argv.update) {
installDeps(deps, opts, function (err) {
if (err) {
console.error('Failed to update global dependencies', err)
cleanUpTTY()
exit(1)
}
printWarnings(deps, 'global')
})
} else {
printDeps(deps, 'global')
if (getNonWarnDepNames(deps).length) {
cleanUpTTY()
exit(1)
}
// Log feedback if all global dependencies are up to date
Expand All @@ -282,16 +296,19 @@ if (argv.global || argv.g) {
pkg = JSON.parse(pkg)
} catch (err) {
console.error('Failed to parse package.json', err)
cleanUpTTY()
exit(1)
}
} catch (err) {
console.error('Failed to read package.json', err)
cleanUpTTY()
exit(1)
}

getUpdatedDeps(pkg, function (err, deps, devDeps, optionalDeps) {
if (err) {
console.error('Failed to get updated dependencies/devDependencies', err)
cleanUpTTY()
exit(1)
}

Expand All @@ -301,18 +318,21 @@ if (argv.global || argv.g) {
installDeps(deps, opts, function (err) {
if (err) {
console.error('Failed to update/save dependencies', err)
cleanUpTTY()
exit(1)
}

installDeps(devDeps, xtend(opts, {dev: true}), function (err) {
if (err) {
console.error('Failed to update/save devDependencies', err)
cleanUpTTY()
exit(1)
}

installDeps(optionalDeps, xtend(opts, {optional: true}), function (err) {
if (err) {
console.error('Failed to update/save optionalDependencies', err)
cleanUpTTY()
exit(1)
}

Expand All @@ -330,6 +350,7 @@ if (argv.global || argv.g) {
if (getNonWarnDepNames(deps).length ||
getNonWarnDepNames(devDeps).length ||
getNonWarnDepNames(optionalDeps).length) {
cleanUpTTY()
exit(1)
} else {
// Log feedback if all dependencies are up to date
Expand Down
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -25,6 +25,7 @@
"LICENCE"
],
"dependencies": {
"ansi": "^0.3.1",
"async": "^2.0.1",
"cli-color-tty": "^2.0.0",
"cli-table": "^0.3.1",
Expand Down

0 comments on commit 22bb114

Please sign in to comment.