Skip to content

Commit

Permalink
pick-updates: prototype interactive update picker
Browse files Browse the repository at this point in the history
  • Loading branch information
zkat committed Feb 21, 2019
1 parent de0ebe1 commit 4d580a8
Show file tree
Hide file tree
Showing 134 changed files with 50,975 additions and 15 deletions.
1 change: 1 addition & 0 deletions lib/config/cmd-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ var cmdList = [
'set',
'get',
'update',
'pick-updates',
'outdated',
'prune',
'pack',
Expand Down
97 changes: 97 additions & 0 deletions lib/pick-updates.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
'use strict'

const BB = require('bluebird')

const { render, AppContext, StdinContext } = require('ink')
const { Installer } = require('./install.js')
const npm = require('./npm.js')
const npmConfig = require('./config/figgy-config.js')
let outdated = null
const path = require('path')
const pudding = require('figgy-pudding')
const PickUpdatesComponent = require('libpickupdates')
const React = require('react')
const readline = require('readline')
const validate = require('aproba')

pickUpdates.usage = [
'npm pick-updates'
].join('\n')

pickUpdates.completion = (opts, cb) => {
validate('OF', [opts, cb])
return cb(null, []) // fill in this array with completion values
}

const PickUpdatesConfig = pudding({
'dry-run': {},
unicode: {}
})

module.exports = (args, cb) => BB.try(() => {
return pickUpdates(args)
}).nodeify(cb)
function pickUpdates (args) {
npm.config.set('long', true)
outdated = BB.promisify(require('./outdated.js'))
const opts = PickUpdatesConfig(npmConfig())
const app = render(React.createElement(AppContext.Consumer, {}, ({ exit }) => {
return React.createElement(StdinPicker, { exit, opts })
}))
return app.waitUntilExit()
}

function StdinPicker ({ exit, opts }) {
return React.createElement(
StdinContext.Consumer,
{},
({ stdin, setRawMode }) => {
readline.emitKeypressEvents(stdin)
setRawMode(true)
stdin.on('keypress', key => {
if (key === '\u0003') {
exit()
}
})
return React.createElement(PickUpdatesComponent, {
stdin,
unicode: process.platform === 'darwin',
onDone () { exit() },
getOutdated () {
return outdated([], true).then(makeJSON)
},
installUpdates (names) {
if (names.length) {
return BB.fromNode(cb => {
new Installer(npm.prefix, !!opts['dry-run'], names).run(cb)
})
} else {
return Promise.resolve(names)
}
}
})
}
)
}

function makeJSON (list, opts) {
var out = {}
list.forEach(function (p) {
var dep = p[0]
var depname = p[1]
var dir = dep.path
var has = p[2]
var want = p[3]
var latest = p[4]
var type = p[6]
dir = path.relative(process.cwd(), dir)
out[depname] = { current: has,
wanted: want,
latest: latest,
location: dir
}
out[depname].type = type
out[depname].homepage = dep.package.homepage
})
return out
}
8 changes: 8 additions & 0 deletions node_modules/arrify/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions node_modules/arrify/license

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

65 changes: 65 additions & 0 deletions node_modules/arrify/package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 36 additions & 0 deletions node_modules/arrify/readme.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions node_modules/astral-regex/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions node_modules/astral-regex/license

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

64 changes: 64 additions & 0 deletions node_modules/astral-regex/package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 43 additions & 0 deletions node_modules/astral-regex/readme.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions node_modules/cli-spinners/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions node_modules/cli-spinners/license

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 4d580a8

Please # to comment.