Permalink
Browse files

First commit

  • Loading branch information...
0 parents commit fd59013e20084350aa764a45e5ffd749c4266cf9 @dylang committed Aug 1, 2011
Showing with 4,006 additions and 0 deletions.
  1. +1 −0 .npmignore
  2. +22 −0 LICENSE
  3. +1 −0 README
  4. +3 −0 bin/changelog.js
  5. +4 −0 changelog.js
  6. +64 −0 lib/cli.js
  7. +87 −0 lib/github.js
  8. +94 −0 lib/npm.js
  9. +16 −0 lib/util.js
  10. +196 −0 node_modules/cli/README.md
  11. +1,125 −0 node_modules/cli/cli.js
  12. +17 −0 node_modules/cli/examples/cat.js
  13. +16 −0 node_modules/cli/examples/command.js
  14. +54 −0 node_modules/cli/examples/echo.js
  15. +6 −0 node_modules/cli/examples/glob.js
  16. +20 −0 node_modules/cli/examples/long_desc.js
  17. +11 −0 node_modules/cli/examples/progress.js
  18. +18 −0 node_modules/cli/examples/sort.js
  19. +9 −0 node_modules/cli/examples/spinner.js
  20. +27 −0 node_modules/cli/examples/static.coffee
  21. +25 −0 node_modules/cli/examples/static.js
  22. +1 −0 node_modules/cli/index.js
  23. +23 −0 node_modules/cli/package.json
  24. +55 −0 node_modules/request/LICENSE
  25. +123 −0 node_modules/request/README.md
  26. +150 −0 node_modules/request/cookies.js
  27. +424 −0 node_modules/request/main.js
  28. +146 −0 node_modules/request/mimetypes.js
  29. +14 −0 node_modules/request/package.json
  30. BIN node_modules/request/tests/googledoodle.png
  31. +45 −0 node_modules/request/tests/server.js
  32. +74 −0 node_modules/request/tests/test-body.js
  33. 0 node_modules/request/tests/test-cookies.js
  34. +30 −0 node_modules/request/tests/test-errors.js
  35. +136 −0 node_modules/request/tests/test-pipes.js
  36. +7 −0 node_modules/request/tests/test-ssl.js
  37. +84 −0 node_modules/request/tests/test-timeout.js
  38. +71 −0 node_modules/step/README.markdown
  39. +154 −0 node_modules/step/lib/step.js
  40. +11 −0 node_modules/step/package.json
  41. +26 −0 node_modules/step/test/callbackTest.js
  42. +27 −0 node_modules/step/test/errorTest.js
  43. +21 −0 node_modules/step/test/fnTest.js
  44. +102 −0 node_modules/step/test/groupTest.js
  45. +17 −0 node_modules/step/test/helper.js
  46. +49 −0 node_modules/step/test/parallelTest.js
  47. +1 −0 node_modules/wordwrap/.npmignore
  48. +54 −0 node_modules/wordwrap/README.markdown
  49. +10 −0 node_modules/wordwrap/example/center.js
  50. +3 −0 node_modules/wordwrap/example/meat.js
  51. +42 −0 node_modules/wordwrap/index.js
  52. +37 −0 node_modules/wordwrap/package.json
  53. +63 −0 node_modules/wordwrap/test/idleness.txt
  54. +31 −0 node_modules/wordwrap/test/wrap.js
  55. +42 −0 package.json
  56. +117 −0 readme.md
@@ -0,0 +1 @@
+node_modules
22 LICENSE
@@ -0,0 +1,22 @@
+(The MIT License)
+
+Copyright (c) 2009-2011 Dylan Greene <dylang@gmail.com>
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+'Software'), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1 README
@@ -0,0 +1 @@
+This file was created by JetBrains WebStorm 2.1.2 for binding GitHub repository
@@ -0,0 +1,3 @@
+#!/usr/bin/env node
+
+require('../lib/cli.js');
@@ -0,0 +1,4 @@
+module.exports = {
+ npm: require('./lib/npm'),
+ github: require('./lib/github')
+};
@@ -0,0 +1,64 @@
+var log = require('logging');
+var CLI = require('cli');
+var Util = require('./util');
+
+CLI.parse();
+
+/*
+ Usage:
+ changelog npm request
+ changelog github mikeal/request
+ changelog http://github.com/mikeal/request
+
+ With plugins?
+ changelog gem httparty
+ changelog brew redis
+ */
+
+CLI.main(function (args, options) {
+ var project = args[0];
+
+ if (!project) {
+ console.log('Usage: changelog { npm package name or github.com repo url }')
+ } else {
+ if (project.match(/github.com/)) {
+ var repo = project.match(/github\.com\/([^\/]*\/[^\/]*)/);
+ if (repo && repo[1]) {
+ repo = repo[1].replace(/\.git$/, '');
+ require('./github').changelog(repo, output);
+ } else {
+ log('bad repo descriptor');
+ }
+ } else {
+ require('./npm').changelog(project, output);
+ }
+ }
+
+});
+
+
+function output(err, changelog) {
+ if (err || !changelog) {
+ log(err && err.message || 'no errors', 'no changelog');
+ } else {
+ changelog.forEach(function(version){
+ if (version.changes) {
+ var date = version.date;
+ var versionString = (version.version ? version.version + ' / ' : '')
+ + date.getFullYear() + '-' + Util.padZero(date.getMonth() + 1) + '-' + Util.padZero(date.getDate());
+ console.log('');
+ console.log(versionString);
+ console.log(new Array(versionString.length + 1).join('='));
+ console.log('');
+ var uniqueChanges = {};
+ version.changes.forEach(function(change){
+ if (!uniqueChanges[change.message]) {
+ console.log(Util.bullet(change.message));
+ }
+ uniqueChanges[change.message] = true;
+ });
+ }
+ });
+ }
+}
+
@@ -0,0 +1,87 @@
+var log = require('logging').from(__filename);
+var URL = require('url');
+var Request = require('request');
+var Step = require('step');
+var Util = require('./util');
+
+function changes(options, cb) {
+ // TODO: better argument check and url fix, or just use npm project name
+
+ var repoURL = URL.parse(options.repo.replace(/\.git$/, ''));
+ var project = repoURL.pathname;
+
+ if (!project) {
+ throw new Error('that\'s no github url i know of');
+ }
+
+ // remove leading /'s
+ project = project.replace(/^\//g, '');
+
+ var api = 'https://api.github.com/repos/' + project + '/commits?per_page=100';
+ //log('api:', api);
+ Request({uri: api}, function (error, response, body) {
+ // TODO: better check for return data
+
+ var changes = [];
+ if (!error && response.statusCode === 200) {
+ var data = JSON.parse(body);
+ data.forEach(function(change){
+ var date = new Date(change.commit.committer.date);
+ var message = change.commit.message;
+ changes.push({
+ date: date,
+ message: message
+ });
+ });
+ } else {
+ log('Github Request Error', error, response.statusCode);
+ throw new Error('Unknown repo: ' + options.repo);
+ }
+ cb(error, { changes: changes });
+ });
+}
+
+function changelog(repo, cb) {
+ var Versions = [];
+ var VersionsHash = {};
+ Step(function() {
+ changes({repo: repo}, this);
+ },
+ function(err, data) {
+ if (err) { log(err.message); throw err; }
+
+ if (data.changes) {
+ data.changes.forEach(function(change){
+ if (change) {
+ var date = change.date;
+ var simpleDate = date.getFullYear() + '-' + Util.padZero(date.getMonth() + 1) + '-' + Util.padZero(date.getDate());
+ VersionsHash[simpleDate] = VersionsHash[simpleDate] || { date: new Date(simpleDate), changes: [] };
+ VersionsHash[simpleDate].changes.push(change);
+ }
+ });
+ }
+
+ Object.keys(VersionsHash).forEach(function(simpleDate) {
+ Versions.push(VersionsHash[simpleDate]);
+ });
+ cb(err, Versions);
+ });
+}
+
+module.exports = {
+ changes: changes,
+ changelog: changelog
+};
+
+
+ /*
+ Request({uri: 'https://github.com/api/v2/json/commits/show/dylang/node-xml/eb9faadc1a99157a123bf6fe0748e3e0d52caaf6'}, function(error, response, body) {
+ if (!error && response.statusCode === 200) {
+ var data = JSON.parse(body).commit.modified;
+ data.forEach(function(change){
+ log(change.filename, change.diff);
+ });
+ }
+
+ });
+ */
@@ -0,0 +1,94 @@
+var Request = require('request');
+var log = require('logging');
+var Step = require('step');
+var Github = require('./github');
+
+function sortVersions (a, b) {
+ a = a.split('.');
+ b = b.split('.');
+ a = [parseInt(a[0], 10), parseInt(a[1], 10), parseInt(a[2], 10)];
+ b = [parseInt(b[0], 10), parseInt(b[1], 10), parseInt(b[2], 10)];
+
+ if (a[0] > b[0]) return -1;
+ if (a[0] < b[0]) return 1;
+
+ if (a[1] > b[1]) return -1;
+ if (a[1] < b[1]) return 1;
+
+ if (a[2] > b[2]) return -1;
+ if (a[2] < b[2]) return 1;
+ return 0;
+}
+
+function versions(packageName, cb) {
+ var v = [];
+ Request({ uri: 'http://search.npmjs.org/api/' + packageName }, function(err, response, body) {
+ var data = JSON.parse(body);
+ var repo;
+ if (data && data.repository && data.repository.url) {
+ repo = data.repository.url;
+ } else {
+ throw new Error('Package author did not specify the code repo location.');
+ }
+ if (data && data.time) {
+ var time = data.time;
+ delete time.created;
+ delete time.modified;
+ var keys = Object.keys(time).sort(sortVersions);
+ keys.forEach(function(version){
+ v.push({
+ version: version,
+ date: new Date(time[version])
+ });
+ });
+ }
+ if (!repo || !v.length) {
+ throw new Error('Unknown package: ' + packageName);
+ }
+
+ cb(err, {
+ repo: repo,
+ versions: v
+ });
+ });
+}
+
+function changelog(packageName, cb) {
+ var Versions;
+
+ Step(function() {
+ versions(packageName, this);
+ },
+ function(err, data) {
+ if (err) { log('ERROR', err.message); throw err; }
+ Versions = data.versions;
+ Github.changes(data, this);
+ },
+ function(err, data) {
+ if (err) { log('ERROR', err.message); throw err; }
+ //log('**** VERSIONS ****', Versions);
+ //log('**** CHANGES ****', data.changes);
+ var i;
+ if (data.changes) {
+ data.changes.forEach(function(change){
+ //log('change', change);
+ if (change) {
+ for (i = Versions.length - 1; i > 0; i--) {
+ if (change.date < Versions[i].date) {
+ break;
+ }
+ }
+ Versions[i].changes = Versions[i].changes || [];
+ Versions[i].changes.push(change);
+ }
+ });
+ }
+ cb(err, Versions);
+ }
+ );
+}
+
+module.exports = {
+ versions: versions,
+ changelog: changelog
+};
@@ -0,0 +1,16 @@
+var log = require('logging').from(__filename);
+var WordWrap = require('wordwrap')(4, 80);
+
+function padZero(n) {
+ return n > 10 ? n : '0' + n;
+}
+
+function bullet(string) {
+ string = string.replace(/(\r?\n)+/g, '\r\n');
+ return ' * ' + WordWrap(string).trim();
+}
+
+module.exports = {
+ padZero: padZero,
+ bullet: bullet
+};
Oops, something went wrong.

0 comments on commit fd59013

Please sign in to comment.