Skip to content

Commit 4d580a8

Browse files
committed
pick-updates: prototype interactive update picker
1 parent de0ebe1 commit 4d580a8

File tree

134 files changed

+50975
-15
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

134 files changed

+50975
-15
lines changed

lib/config/cmd-list.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ var cmdList = [
6767
'set',
6868
'get',
6969
'update',
70+
'pick-updates',
7071
'outdated',
7172
'prune',
7273
'pack',

lib/pick-updates.js

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
'use strict'
2+
3+
const BB = require('bluebird')
4+
5+
const { render, AppContext, StdinContext } = require('ink')
6+
const { Installer } = require('./install.js')
7+
const npm = require('./npm.js')
8+
const npmConfig = require('./config/figgy-config.js')
9+
let outdated = null
10+
const path = require('path')
11+
const pudding = require('figgy-pudding')
12+
const PickUpdatesComponent = require('libpickupdates')
13+
const React = require('react')
14+
const readline = require('readline')
15+
const validate = require('aproba')
16+
17+
pickUpdates.usage = [
18+
'npm pick-updates'
19+
].join('\n')
20+
21+
pickUpdates.completion = (opts, cb) => {
22+
validate('OF', [opts, cb])
23+
return cb(null, []) // fill in this array with completion values
24+
}
25+
26+
const PickUpdatesConfig = pudding({
27+
'dry-run': {},
28+
unicode: {}
29+
})
30+
31+
module.exports = (args, cb) => BB.try(() => {
32+
return pickUpdates(args)
33+
}).nodeify(cb)
34+
function pickUpdates (args) {
35+
npm.config.set('long', true)
36+
outdated = BB.promisify(require('./outdated.js'))
37+
const opts = PickUpdatesConfig(npmConfig())
38+
const app = render(React.createElement(AppContext.Consumer, {}, ({ exit }) => {
39+
return React.createElement(StdinPicker, { exit, opts })
40+
}))
41+
return app.waitUntilExit()
42+
}
43+
44+
function StdinPicker ({ exit, opts }) {
45+
return React.createElement(
46+
StdinContext.Consumer,
47+
{},
48+
({ stdin, setRawMode }) => {
49+
readline.emitKeypressEvents(stdin)
50+
setRawMode(true)
51+
stdin.on('keypress', key => {
52+
if (key === '\u0003') {
53+
exit()
54+
}
55+
})
56+
return React.createElement(PickUpdatesComponent, {
57+
stdin,
58+
unicode: process.platform === 'darwin',
59+
onDone () { exit() },
60+
getOutdated () {
61+
return outdated([], true).then(makeJSON)
62+
},
63+
installUpdates (names) {
64+
if (names.length) {
65+
return BB.fromNode(cb => {
66+
new Installer(npm.prefix, !!opts['dry-run'], names).run(cb)
67+
})
68+
} else {
69+
return Promise.resolve(names)
70+
}
71+
}
72+
})
73+
}
74+
)
75+
}
76+
77+
function makeJSON (list, opts) {
78+
var out = {}
79+
list.forEach(function (p) {
80+
var dep = p[0]
81+
var depname = p[1]
82+
var dir = dep.path
83+
var has = p[2]
84+
var want = p[3]
85+
var latest = p[4]
86+
var type = p[6]
87+
dir = path.relative(process.cwd(), dir)
88+
out[depname] = { current: has,
89+
wanted: want,
90+
latest: latest,
91+
location: dir
92+
}
93+
out[depname].type = type
94+
out[depname].homepage = dep.package.homepage
95+
})
96+
return out
97+
}

node_modules/arrify/index.js

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/arrify/license

Lines changed: 21 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/arrify/package.json

Lines changed: 65 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/arrify/readme.md

Lines changed: 36 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/astral-regex/index.js

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/astral-regex/license

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/astral-regex/package.json

Lines changed: 64 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/astral-regex/readme.md

Lines changed: 43 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/cli-spinners/index.js

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/cli-spinners/license

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)