Skip to content

Commit

Permalink
feat(preset): add express
Browse files Browse the repository at this point in the history
  • Loading branch information
stevemao committed Aug 3, 2015
1 parent a2df9ca commit c4b20b1
Show file tree
Hide file tree
Showing 8 changed files with 229 additions and 4 deletions.
53 changes: 53 additions & 0 deletions presets/express.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
'use strict';
var Q = require('q');
var readFile = Q.denodeify(require('fs').readFile);
var resolve = require('path').resolve;
var semver = require('semver');

function presetOpts(cb) {
var parserOpts = {
headerPattern: /^(\w*)\: (.*)$/,
headerCorrespondence: [
'component',
'shortDesc'
]
};

var writerOpts = {
transform: function(commit) {
if (commit.component === 'perf') {
commit.component = 'Performance';
} else if (commit.component === 'deps') {
commit.component = 'Dependencies';
} else {
return;
}

return commit;
},
groupBy: 'component',
commitGroupsSort: 'title',
commitsSort: ['component', 'shortDesc'],
generateOn: function(commit) {
return semver.valid(commit.version);
}
};

Q.all([
readFile(resolve(__dirname, '../templates/express/template.hbs'), 'utf-8'),
readFile(resolve(__dirname, '../templates/express/header.hbs'), 'utf-8'),
readFile(resolve(__dirname, '../templates/express/commit.hbs'), 'utf-8')
])
.spread(function(template, header, commit) {
writerOpts.mainTemplate = template;
writerOpts.headerPartial = header;
writerOpts.commitPartial = commit;

cb(null, {
parserOpts: parserOpts,
writerOpts: writerOpts
});
});
}

module.exports = presetOpts;
4 changes: 0 additions & 4 deletions presets/jshint.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@ function presetOpts(cb) {
return;
}

if (!commit.type || typeof commit.type !== 'string') {
return;
}

if (typeof commit.hash === 'string') {
commit.hash = commit.hash.substring(0, 7);
}
Expand Down
9 changes: 9 additions & 0 deletions templates/express/commit.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
* {{#if shortDesc}}{{shortDesc}}{{else}}{{header}}{{/if}}
{{#if body}}

{{body}}

{{/if}}
{{!-- commit references --}}{{#if references}}
Closes{{~#each references}} {{#if @root.linkReferences}}[{{#if this.owner}}{{this.owner}}/{{/if}}{{this.repository}}#{{this.issue}}]({{@root.host}}/{{#if this.repository}}{{#if this.owner}}{{this.owner}}/{{/if}}{{this.repository}}{{else}}{{#if @root.owner}}{{@root.owner}}/{{/if}}{{@root.repository}}{{/if}}/{{@root.issue}}/{{this.issue}}){{else}}{{this.repository}}#{{this.issue}}{{/if}}{{/each}}
{{/if}}
2 changes: 2 additions & 0 deletions templates/express/header.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{{#if version}}{{version}} / {{/if}}{{date}}
===================
14 changes: 14 additions & 0 deletions templates/express/template.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{{> header}}

{{#each commitGroups}}

{{#if title}}
### {{title}}

{{/if}}
{{#each commits}}
{{> commit root=@root}}
{{/each}}
{{/each}}


59 changes: 59 additions & 0 deletions test/express.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
'use strict';
var child = require('child_process');
var conventionalChangelog = require('../');
var expect = require('chai').expect;
var shell = require('shelljs');
var through = require('through2');
var writeFileSync = require('fs').writeFileSync;

describe('presets', function() {
describe('express', function() {
before(function(done) {
shell.cd('express');
shell.exec('git init');
writeFileSync('test1', '');
child.exec('git add --all && git commit -m"deps: type-is@~1.6.3\n\n - deps: mime-types@~2.1.1\n - perf: reduce try block size\n - perf: remove bitwise operations"', function() {
writeFileSync('test2', '');
child.exec('git add --all && git commit -m"perf: use saved reference to http.STATUS_CODES\n\ncloses #2602"', function() {
writeFileSync('test3', '');
shell.exec('git add --all && git commit -m"docs: add license comments"');
writeFileSync('test4', '');
child.exec('git add --all && git commit -m"deps: path-to-regexp@0.1.4"', function() {
writeFileSync('test5', '');
shell.exec('git add --all && git commit -m"Bad commit"');

done();
});
});
});
});

after(function() {
shell.cd('../');
});

it('should work if there is no semver tag', function(done) {
conventionalChangelog({
preset: 'express',
pkg: {
path: __dirname + '/fixtures/_express.json'
}
})
.pipe(through(function(chunk) {
chunk = chunk.toString();

expect(chunk).to.include('### Dependencies');
expect(chunk).to.include('type-is@~1.6.3');
expect(chunk).to.include(' - deps: mime-types@~2.1.1\n');
expect(chunk).to.include('path-to-regexp@0.1.4');
expect(chunk).to.include('### Performance');
expect(chunk).to.include('use saved reference to http.STATUS_CODES');

expect(chunk).to.not.include('license');
expect(chunk).to.not.include('Bad');

done();
}));
});
});
});
91 changes: 91 additions & 0 deletions test/fixtures/_express.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
{
"name": "express",
"description": "Fast, unopinionated, minimalist web framework",
"version": "4.13.1",
"author": "TJ Holowaychuk <tj@vision-media.ca>",
"contributors": [
"Aaron Heckmann <aaron.heckmann+github@gmail.com>",
"Ciaran Jessup <ciaranj@gmail.com>",
"Douglas Christopher Wilson <doug@somethingdoug.com>",
"Guillermo Rauch <rauchg@gmail.com>",
"Jonathan Ong <me@jongleberry.com>",
"Roman Shtylman <shtylman+expressjs@gmail.com>",
"Young Jae Sim <hanul@hanul.me>"
],
"license": "MIT",
"repository": "strongloop/express",
"homepage": "http://expressjs.com/",
"keywords": [
"express",
"framework",
"sinatra",
"web",
"rest",
"restful",
"router",
"app",
"api"
],
"dependencies": {
"accepts": "~1.2.10",
"array-flatten": "1.1.0",
"content-disposition": "0.5.0",
"content-type": "~1.0.1",
"cookie": "0.1.3",
"cookie-signature": "1.0.6",
"debug": "~2.2.0",
"depd": "~1.0.1",
"escape-html": "1.0.2",
"etag": "~1.7.0",
"finalhandler": "0.4.0",
"fresh": "0.3.0",
"merge-descriptors": "1.0.0",
"methods": "~1.1.1",
"on-finished": "~2.3.0",
"parseurl": "~1.3.0",
"path-to-regexp": "0.1.6",
"proxy-addr": "~1.0.8",
"qs": "4.0.0",
"range-parser": "~1.0.2",
"send": "0.13.0",
"serve-static": "~1.10.0",
"type-is": "~1.6.4",
"vary": "~1.0.0",
"utils-merge": "1.0.0"
},
"devDependencies": {
"after": "0.8.1",
"ejs": "2.3.2",
"istanbul": "0.3.9",
"marked": "0.3.3",
"mocha": "2.2.5",
"should": "7.0.1",
"supertest": "1.0.1",
"body-parser": "~1.13.2",
"connect-redis": "~2.3.0",
"cookie-parser": "~1.3.5",
"cookie-session": "~1.2.0",
"express-session": "~1.11.3",
"jade": "~1.11.0",
"method-override": "~2.3.3",
"morgan": "~1.6.1",
"multiparty": "~4.1.2",
"vhost": "~3.0.0"
},
"engines": {
"node": ">= 0.10.0"
},
"files": [
"LICENSE",
"History.md",
"Readme.md",
"index.js",
"lib/"
],
"scripts": {
"test": "mocha --require test/support/env --reporter spec --bail --check-leaks test/ test/acceptance/",
"test-ci": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --require test/support/env --reporter spec --check-leaks test/ test/acceptance/",
"test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --require test/support/env --reporter dot --check-leaks test/ test/acceptance/",
"test-tap": "mocha --require test/support/env --reporter tap --check-leaks test/ test/acceptance/"
}
}
1 change: 1 addition & 0 deletions test/prepare.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ shell.mkdir('jquery');
shell.mkdir('jshint');
shell.mkdir('eslint');
shell.mkdir('atom');
shell.mkdir('express');
shell.mkdir('cli');

0 comments on commit c4b20b1

Please sign in to comment.