Browse files

first real working version of changelog

  • Loading branch information...
1 parent 2da5393 commit de27b261ab7ae7d290ebf69f57a11937b264b969 @drewfish committed Apr 7, 2012
Showing with 113 additions and 31 deletions.
  1. +23 −2 Changelog.md
  2. +1 −0 Readme.md
  3. +81 −28 lib/crank.js
  4. +1 −1 package.json
  5. +7 −0 templates-changelog/md.mu
View
25 Changelog.md
@@ -1,6 +1,27 @@
+version 0.0.2 / Sat Apr 07 2012 11:29:25 GMT-0700 (PDT)
+=======================================================
+change 2da5393ad6c80ad69ff7bfdd30fe5dc1b8fe9f66
+
+* initial work on "changelog" op. still lots to do
+* formatted to be more like our default format
+* `crank version` works, plus infrastructure for that
+* added semver dependency
+* also ignore vim swap files
+* as it so happens, none of TODO was that interesting
+* small tweaks
+* added licenses and bugs fields
+* licensing in each file
+* formatting tweaks
+* makefile not needed
+* only need one readme
+* packaging infrastructure
+* second
+
+
version 0.0.1 / 2010-01-03
==========================
- change 186905c536abe7b178b554f18e4e6f836f8d7913
+change 186905c536abe7b178b554f18e4e6f836f8d7913
+
+* Initial release
- * Initial release
View
1 Readme.md
@@ -124,6 +124,7 @@ a tool to update version number and changelog, for npm module development
* `{{version}}` string
* `{{date}}` string, date that crank was run
+* `{{changeid}}` string
* `{{changes}}` list of objects
* `{{changeid}}` string
* `{{date}}` string
View
109 lib/crank.js
@@ -26,7 +26,7 @@
var
libasync = require('async'),
libfs = require('fs'),
- libmu = require('mu'),
+ libmu = require('mu2'),
libpath = require('path'),
libprocess = require('child_process'),
libsemver = require('semver'),
@@ -74,14 +74,14 @@ function Base(options) {
//TODO dateformat: 'TODO',
filters: []
},
- version: {
+ versions: {
//TODO dateformat: 'TODO',
filters: []
},
database: {
type: 'regexp',
file: 'Changelog.md',
- regexp: '\\bversion\\s+([0-9.]+)[\\s\\S]*\\bchange\\s+(\\S+)'
+ regexp: '\\bversion\\s+([0-9.]+)[\\s\\S]*?\\bchange\\s+(\\S+)'
}
}
};
@@ -111,16 +111,33 @@ Base.prototype.fileReadJSON = function(path) {
};
+Base.prototype.fileWrite = function(path, content) {
+ return libfs.writeFileSync(path, content, 'utf-8');
+};
+
+
Base.prototype.fileWriteJSON = function(path, content) {
- var content;
- if (! libpath.existsSync(path)) {
- return {};
- }
content = JSON.stringify(content, null, 4);
return libfs.writeFileSync(path, content, 'utf-8');
};
+Base.prototype.filter = function(list, filters) {
+ if (! filters.length) {
+ // nothing to do
+ return list;
+ }
+ // TODO
+ return list;
+};
+
+
+Base.prototype.dateFormat = function(date, format) {
+ // TODO
+ return date;
+};
+
+
Base.prototype.scmGetCurrentChangeID = function(cb) {
var me = this;
this._scmInit(function(error) {
@@ -359,6 +376,10 @@ OPVersion.prototype.run = function(command) {
function OPChangelog(base) {
this.base = base;
+ if (! this.base.config.changelog.template) {
+ this.base.config.changelog.template =
+ libpath.extname(this.base.config.changelog.file).substr(1);
+ }
}
OPS.changelog = OPChangelog;
@@ -376,35 +397,33 @@ OPChangelog.prototype.usage = function(command) {
OPChangelog.prototype.run = function(command) {
- var me = this;
- var db;
- var mapChangeVersion;
- var currentChangeID;
- var latestChangeID;
- var changes;
- var latestVersion;
+ var me = this,
+ db,
+ mapChangeVersion,
+ currentChangeID,
+ latestChangeID,
+ changes,
+ latestVersion,
+ rendered = '';
db = makeChangelogDB(this.base, this.base.config.changelog.database);
libasync.series([
// read db
function step1(cb) {
-console.log('--STEP1-- read db');
db.read(function(error, map) {
if (error) {
cb(error);
return;
}
mapChangeVersion = map;
-console.log(mapChangeVersion);
cb();
});
},
// get changeid of target
function step2(cb) {
-console.log('--STEP2-- get changeid of target');
me.base.scmGetCurrentChangeID(function(error, changeid) {
if (error) {
cb(error);
@@ -421,49 +440,83 @@ console.log('--STEP2-- get changeid of target');
// get latest changeid in db
function step3(cb) {
-console.log('--STEP3-- get latest changeid in db');
latestChangeID = mapChangeVersion[Object.keys(mapChangeVersion)[0]];
+ if (currentChangeID === latestChangeID) {
+ console.log('NOTICE: no changes since last crank. done..');
+ return;
+ }
cb();
},
// list log entries from last-rev to current-rev
function step4(cb) {
-console.log('--STEP4-- list log entries from last-rev to current-rev');
me.base.scmListChanges(latestChangeID, currentChangeID, function(error, list) {
if (error) {
cb(error);
return;
}
changes = list;
-//console.log(changes);
cb();
});
},
// get latest version
function step5(cb) {
-console.log('--STEP5-- get latest version');
+ var pkgPath, pkg;
+ pkgPath = libpath.join(me.base.config.target, 'package.json');
+ pkg = me.base.fileReadJSON(pkgPath);
+ latestVersion = pkg.version;
cb();
},
// filter/transform/templatize changes
function step6(cb) {
-console.log('--STEP6-- filter/transform/templatize changes');
- cb();
+ var release = {}, releases, template;
+
+ changes = me.base.filter(changes,
+ me.base.config.changelog.changes.filters);
+ changes.forEach(function(change) {
+ change.date = me.base.dateFormat(change.date,
+ me.base.config.changelog.changes.dateFormat);
+ });
+
+ release = {
+ version: latestVersion,
+ date: me.base.dateFormat(new Date(),
+ me.base.config.changelog.versions.dateFormat),
+ changeid: currentChangeID,
+ changes: changes
+ };
+ releases = [ release ];
+ releases = me.base.filter(releases,
+ me.base.config.changelog.versions.filters);
+ release = releases[0];
+
+ template = libpath.join(__dirname, '..', 'templates-changelog',
+ me.base.config.changelog.template + '.mu');
+ libmu.compileAndRender(template, release)
+ .on('error', function(error) {
+ cb(error);
+ })
+ .on('data', function(data) {
+ rendered += data.toString();
+ })
+ .on('end', function() {
+ cb();
+ });
},
// update changelog
function step7(cb) {
-console.log('--STEP7-- update changelog');
-// fileRead
-// prepend
-// fileWrite
+ var content;
+ content = me.base.fileRead(me.base.config.changelog.file);
+ content = rendered + content;
+ me.base.fileWrite(me.base.config.changelog.file, content);
cb();
},
// update db
function step8(cb) {
-console.log('--STEP8-- update db');
db.update(latestVersion, latestChangeID, cb);
},
View
2 package.json
@@ -28,7 +28,7 @@
"devDependencies": {},
"dependencies": {
"async": ">= 0.1.18",
- "mu": ">= 0.5.2",
+ "mu2": ">= 0.5.3",
"semver": ">= 1.0.13"
},
"main": "lib/crank",
View
7 templates-changelog/md.mu
@@ -0,0 +1,7 @@
+
+version {{version}} / {{date}}
+=======================================================
+change {{changeid}}
+
+{{#changes}}* {{{message}}}
+{{/changes}}

0 comments on commit de27b26

Please sign in to comment.