From 49ec7507725fcc504599b835347ab27c7ff30295 Mon Sep 17 00:00:00 2001 From: Felix Yan Date: Wed, 4 Nov 2015 17:32:52 +0800 Subject: [PATCH] Add support for NPM Registry --- README.rst | 7 +++++++ nvchecker/get_version.py | 1 + nvchecker/source/npm.py | 17 +++++++++++++++++ 3 files changed, 25 insertions(+) create mode 100644 nvchecker/source/npm.py diff --git a/README.rst b/README.rst index d2063f8..b3d29d5 100644 --- a/README.rst +++ b/README.rst @@ -159,6 +159,13 @@ Check `RubyGems `_ for updates. gems The name used on RubyGems, e.g. ``sass``. +Check NPM Registry +---------- +Check `NPM Registry `_ for updates. + +npm + The name used on NPM Registry, e.g. ``coffee-script``. + Check Local Pacman Database --------------------------- This is used when you run ``nvchecker`` on an Arch Linux system and the program always keeps up with a package in your configured repositories for `Pacman`_. diff --git a/nvchecker/get_version.py b/nvchecker/get_version.py index 472d93f..ec7ea4b 100644 --- a/nvchecker/get_version.py +++ b/nvchecker/get_version.py @@ -5,6 +5,7 @@ logger = logging.getLogger(__name__) handler_precedence = ( 'github', 'gitcafe', 'aur', 'pypi', 'archpkg', 'gems', 'pacman', 'cmd', 'bitbucket', 'gcode_hg', 'gcode_svn', 'regex', 'manual', 'vcs', + 'npm', ) def get_version(name, conf, callback): diff --git a/nvchecker/source/npm.py b/nvchecker/source/npm.py new file mode 100644 index 0000000..4c5280f --- /dev/null +++ b/nvchecker/source/npm.py @@ -0,0 +1,17 @@ +import json +from functools import partial + +from tornado.httpclient import AsyncHTTPClient + +NPM_URL = 'https://registry.npmjs.org/%s' + +def get_version(name, conf, callback): + repo = conf.get('npm') or name + url = NPM_URL % repo + AsyncHTTPClient().fetch(url, user_agent='lilydjwg/nvchecker', + callback=partial(_npm_done, name, callback)) + +def _npm_done(name, callback, res): + data = json.loads(res.body.decode('utf-8')) + version = data['dist-tags']['latest'] + callback(name, version)