Skip to content
Browse files

added support for showing specific releases via `latest`, `n`, and `n…

….n.n` based on Tjholowaychuk's request. Closes #2
  • Loading branch information...
1 parent 80b2c3d commit 9af4c759d2c911445e38d34ed30a33a19b17ae54 @dylang committed Aug 26, 2011
Showing with 119 additions and 24 deletions.
  1. +13 −3 lib/cli.js
  2. +25 −1 lib/github.js
  3. +49 −3 lib/npm.js
  4. +32 −17 readme.md
View
16 lib/cli.js
@@ -7,7 +7,15 @@ var log = require('./log');
var FS = require('fs');
var Util = require('./util');
-CLI.setUsage('changelog <npm module name or github repo url> [OPTIONS]. \n More help at https://github.com/dylang/changelog').parse({
+CLI.setUsage('changelog <npm module name> [release] [options]\n' +
+ ' changelog <github repo url> [release] [options]\n' +
+ '\n' +
+ 'Release:\n' +
+ ' latest Show only the latest release. ie: changelog express latest\n' +
+ ' number Show that many recent releases. ie: changelog express 3 \n' +
+ ' n.n.n Show changes for a specific release. ie: changelog express 2.4.4'
+
+).parse({
color: ['c', 'Output as Color (terminal default)'],
markdown: ['m', 'Output as Github-flavored Markdown (file default)'],
json: ['j', 'Output as JSON'],
@@ -19,6 +27,8 @@ CLI.main(function (args, options) {
var project = args[0];
+ var releaseRequested = args[1];
+
if (!project) {
try {
log.debug('Project not specified. Looking for a package.json in ' + process.cwd() + ' instead.');
@@ -40,12 +50,12 @@ CLI.main(function (args, options) {
var repo = project.match(/github\.com\/([^\/]*\/[^\/]*)/);
if (repo && repo[1]) {
repo = repo[1].replace(/\.git$/, '');
- Github.changelog(repo, this);
+ Github.changelog(repo, releaseRequested, this);
} else {
throw new Error('Bad repo url: ' + project);
}
} else {
- Npm.changelog(project, this);
+ Npm.changelog(project, releaseRequested, this);
}
}
},
View
26 lib/github.js
@@ -48,7 +48,7 @@ function changes(options, cb) {
});
}
-function changelog(repo, cb) {
+function changelog(repo, releaseRequested, cb) {
var Versions = [];
var VersionsHash = {};
@@ -70,6 +70,30 @@ function changelog(repo, cb) {
Object.keys(VersionsHash).forEach(function(simpleDate) {
Versions.push(VersionsHash[simpleDate]);
});
+
+ if (releaseRequested) {
+ var tmpVersions = [];
+ var i;
+
+ // All == all versions
+ if (releaseRequested.toString().toLowerCase() == 'all') {
+ tmpVersions = Versions;
+ }
+ // Latest == Latest single version
+ else if (releaseRequested.toString().toLowerCase() == 'latest') {
+ tmpVersions.push(Versions[0]);
+ // Integer == that many versions. 1 = one version.
+ } else if (parseInt(releaseRequested, 10) == releaseRequested) {
+ for (i = 0; i < Math.min(releaseRequested, Versions.length - 1); i++) {
+ tmpVersions.push(Versions[i]);
+ }
+ // Require valid version
+ } else {
+ log.error('Github\'s API does not yet support release versions. See https://github.com/github/developer.github.com/issues/17 for more info.')
+ }
+ Versions = tmpVersions;
+ }
+
cb(err, {
project: data.project,
versions: Versions
View
52 lib/npm.js
@@ -77,7 +77,7 @@ function versions(moduleName, cb) {
}
}
- err = new Error((author ? author : 'Owner of module ') + ' did not specify the repository url in the package.json for ' + moduleName + '.');
+ err = new Error((author ? author : 'Owner of module ') + ' did `not specify the repository url in the package.json for ' + moduleName + '.');
}
if ((!err && !repo) || (data && !v.length)) {
err = new Error('Unknown package: ' + moduleName);
@@ -92,7 +92,7 @@ function versions(moduleName, cb) {
});
}
-function changelog(packageName, cb) {
+function changelog(packageName, releaseRequested, cb) {
var Versions;
Step(function() {
@@ -106,13 +106,15 @@ function changelog(packageName, cb) {
function(err, data) {
var i;
var project;
+ var upcoming;
+
if (data) {
project = data.project;
}
if (data && data.changes) {
if (data.changes[0].date > Versions[0].date) {
- Versions.unshift({ version: 'Upcoming', date: data.changes[0].date});
+ Versions.unshift({ version: 'Upcoming', date: data.changes[0].date, upcoming: true });
}
data.changes.forEach(function(change){
@@ -128,6 +130,50 @@ function changelog(packageName, cb) {
}
});
}
+
+ // Removing Upcoming.
+ if (Versions[0].upcoming) {
+ upcoming = Versions.shift();
+ }
+
+ if (releaseRequested) {
+ var tmpVersions = [];
+
+ // All == all versions
+ if (releaseRequested.toString().toLowerCase() == 'all') {
+ tmpVersions = Versions;
+ }
+ // Latest == Latest single version
+ else if (releaseRequested.toString().toLowerCase() == 'latest') {
+ tmpVersions.push(Versions[0]);
+ }
+ // Upcoming == Show what's in the pipeline for the next release
+ else if (releaseRequested.toString().toLowerCase() == 'upcoming') {
+ if (upcoming) {
+ tmpVersions.push(upcoming);
+ }
+
+ // Integer == that many versions. 1 = one version.
+ } else if (parseInt(releaseRequested, 10) == releaseRequested) {
+ for (i = 0; i < Math.min(releaseRequested, Versions.length - 1); i++) {
+ tmpVersions.push(Versions[i]);
+ }
+
+ // Require valid version
+ } else if (!Semver.valid(releaseRequested)) {
+ log.error('Invalid version syntax. Versions can be latest, an integer, or n.n.n where n are integers.')
+
+ // x.x.x then look for that specific version
+ } else {
+ Versions.forEach(function(Version) {
+ if (Semver.satisfies(Version.version, releaseRequested)) {
+ tmpVersions.push(Version);
+ }
+ });
+ }
+ Versions = tmpVersions;
+ }
+
cb(err, {
project: project,
versions: Versions
View
49 readme.md
@@ -13,27 +13,39 @@ Modules do not need to be installed locally to get a changelog but they must def
![Example using Express](https://github.com/dylang/changelog/raw/master/examples/express.png)
- $ changelog {npm module name} [options]
+ $ changelog {npm module name} [release] [options]
`npm module`: The module name, such as `express`.
Any Public Github.com Repository
--------------------------------
+Changelog also works on any public Github repo.
+
![Example using Bootstrap from Github](https://github.com/dylang/changelog/raw/master/examples/twitter-bootstrap.png)
$ changelog {Github.com repo url} [options]
`Github.com repo url`: Urls can be any format, such as `https://github.com/dylang/changelog` or `git@github.com:dylang/changelog.git` or even just `github.com/dylang/changelog`.
-Options
--------
+Help
+----
+
+ Usage:
+ changelog <npm module name> [release] [options]
+ changelog <github repo url> [release] [options]
+
+ Release:
+ latest Show only the latest release. ie: changelog express latest
+ number Show that many recent releases. ie: changelog express 3
+ n.n.n Show changes for a specific release. ie: changelog express 2.4.4
- * `-c`, `--color` Output as Color (default)
- * `-m`, `--markdown` Output as Github-flavored Markdown (default when piping to a file)
- * `-j`, `--json` Output as JSON
- * `-d`, `--debug` Enable debugging
- * `-h`, `--help` Display help and usage details
+ Options:
+ -c, --color Output as Color (terminal default)
+ -m, --markdown Output as Github-flavored Markdown (file default)
+ -j, --json Output as JSON
+ -d, --debug Enable debugging
+ -h, --help Display help and usage details
Install
=======
@@ -42,7 +54,7 @@ Using [npm](http://npmjs.org) just do:
$ npm-g install changelog
-The `-g` installs changelog globally so you can use `changelog` anywhere.
+Using `npm-g` installs changelog globally so you can use `changelog` anywhere. You can also just use `npm install changelog` if you are using it as a module for another project.
Update
======
@@ -51,6 +63,8 @@ To make sure you have the latest version:
$ npm-g update
+This will update all of your global modules.
+
More Examples
=============
@@ -63,7 +77,7 @@ Changelog can be easily integrated into other tools.
var Changelog = require('changelog');
- Changelog.npm('request', callback);
+ Changelog.npm('express', callback);
Changelog.github('joyent/node', callback);
function callback(err, data) {
@@ -93,18 +107,19 @@ How it works
* Changelog uses the [Github V3 API](http://developer.github.com/) and [npmjs.org API](http://search.npmjs.org/).
-Future
-======
+Upcoming Features
+=================
- * Support paging Github's API to aquire more than 100 commits.
- * Ability to set the start and end version.
- * Use Git tags to detect versions (waiting for Github to fix [Issue #17](https://github.com/github/developer.github.com/issues/17)).
* Add header and/or footer to the output with module name, contributors, etc.
+ * Support private Github repos and Github Fi.
+ * Better color choices for those with default terminal colors.
+ * Support versions/releases for Github repositories (waiting for Github to address [Github API Issue #17](https://github.com/github/developer.github.com/issues/17)).
+ * Support paging Github's API to aquire more than 100 commit messages.
Want to help?
=============
-I love merging in pull requests.
+Here are some ideas I have no idea how to do.
* Support for `brew` and `gem`?
* Integrate into `npm update`?
@@ -114,4 +129,4 @@ About
=====
[Dylan Greene](http://github.com/dylang) built this because he was always curious what was changed when doing `npm update`.
-This module is inspired by but not related to [TheChangelog](http://thechangelog.com/).
+This module's name is inspired by listening to [TheChangelog Podcast](http://thechangelog.com/) on the way to [work](http://opower.com).

0 comments on commit 9af4c75

Please sign in to comment.
Something went wrong with that request. Please try again.