diff --git a/Changelog.MD b/Changelog.MD
new file mode 100644
index 0000000..a47b12f
--- /dev/null
+++ b/Changelog.MD
@@ -0,0 +1,13 @@
+My app - Changelog
+# ALL (2013-11-15)
+
+
+## Features
+
+- **bootstrap:** creating initial structure
+ ([dea45d68](https://github.com/rafinskipg/Git-change-log/commits/dea45d68ce9555e876680bf7c0778add2f367a30))
+
+
+## Breaking Changes
+
+
diff --git a/README.md b/README.md
index 5d86ec4..cefd299 100644
--- a/README.md
+++ b/README.md
@@ -2,3 +2,72 @@ Git-change-log
==============
Generates a git changelog, inspired & based on Angular JS changelog generator
+
+## Usage
+
+Follow the Commit Guidelines when you commit.
+Create a changelog with
+
+```
+node changelog.js
+```
+It does accept some parameters
+
+```
+node changelog.js {VERSION} {OUTPUTFILE} {APPNAME} {G|B}
+```
+
+## Git Commit Guidelines - Source : "Angular JS"
+
+We have very precise rules over how our git commit messages can be formatted. This leads to **more
+readable messages** that are easy to follow when looking through the **project history**. But also,
+we use the git commit messages to **generate the AngularJS change log**.
+
+### Commit Message Format
+Each commit message consists of a **header**, a **body** and a **footer**. The header has a special
+format that includes a **type**, a **scope** and a **subject**:
+
+```
+():
+
+
+
+
+```
+
+Any line of the commit message cannot be longer 100 characters! This allows the message to be easier
+to read on github as well as in various git tools.
+
+### Type
+Must be one of the following:
+
+* **feat**: A new feature
+* **fix**: A bug fix
+* **docs**: Documentation only changes
+* **style**: Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)
+* **refactor**: A code change that neither fixes a bug or adds a feature
+* **test**: Adding missing tests
+* **chore**: Changes to the build process or auxiliary tools and libraries such as documentation generation
+
+
+### Scope
+The scope could be anything specifying place of the commit change. For example `$location`,
+`$browser`, `$compile`, `$rootScope`, `ngHref`, `ngClick`, `ngView`, etc...
+
+### Subject
+The subject contains succinct description of the change:
+
+* use the imperative, present tense: "change" not "changed" nor "changes"
+* don't capitalize first letter
+* no dot (.) at the end
+
+###Body
+Just as in the **subject**, use the imperative, present tense: "change" not "changed" nor "changes"
+The body should include the motivation for the change and contrast this with previous behavior.
+
+###Footer
+The footer should contain any information about **Breaking Changes** and is also the place to
+reference GitHub issues that this commit **Closes**.
+
+
+A detailed explanation can be found in this [document][commit-message-format].
\ No newline at end of file
diff --git a/changelog.js b/changelog.js
index e78bd76..ce16c49 100644
--- a/changelog.js
+++ b/changelog.js
@@ -7,16 +7,28 @@ var child = require('child_process');
var fs = require('fs');
var util = require('util');
var q = require('qq');
-var _s = require('underscore-string');
-var GIT_LOG_CMD = 'git log development --grep="%s" -E --format=%s %s..HEAD';
-//var GIT_LOG_CMD = 'git log --grep="%s" -E --format=%s %s..HEAD';
+var BRANCH_NAME = '';
+
+var GIT_LOG_CMD = 'git log '+BRANCH_NAME+' --grep="%s" -E --format=%s %s..HEAD';
+var GIT_NOTAG_LOG_CMD = 'git log '+BRANCH_NAME+' --grep="%s" -E --format=%s';
+
var GIT_TAG_CMD = 'git describe --tags --abbrev=0';
-var PROVIDER = 'BitBucket';
+var PROVIDER = 'G'; //[G]ithub [B]itbucket
var HEADER_TPL = '%s \n# %s (%s)\n\n';
-var LINK_ISSUE = '[#%s](https://bitbucket.org/adesisnetlife/repsol-proyecto-f-nix-intranet/issues/%s)';
-var LINK_COMMIT = '[%s](https://bitbucket.org/adesisnetlife/repsol-proyecto-f-nix-intranet/commits/%s)';
+var USER_NAME = 'rafinskipg';
+var PROJECT_NAME = 'Git-change-log';
+
+var LINK_ISSUE = ({
+ G: '[#%s](https://github.com/'+USER_NAME+ '/'+ PROJECT_NAME+'/issues/%s)',
+ B : '[#%s](https://bitbucket.org/'+USER_NAME+ '/'+PROJECT_NAME+'/issues/%s)'})
+ [PROVIDER];
+
+var LINK_COMMIT = ({
+ G: '[%s](https://github.com/'+USER_NAME+ '/' +PROJECT_NAME+'/commits/%s)',
+ B: '[%s](https://bitbucket.org/'+USER_NAME+ '/'+PROJECT_NAME +'/commits/%s)'})
+ [PROVIDER];
var EMPTY_COMPONENT = '$$';
@@ -124,10 +136,16 @@ var printSection = function(stream, title, section, printCommitLinks) {
var readGitLog = function(grep, from) {
var deferred = q.defer();
-
+ //TODO if there is no tag , create a 0.0.0 Tag automattically
+ var command = from != 'NONETAG' ? GIT_LOG_CMD: GIT_NOTAG_LOG_CMD ;
+ if(from == 'NONETAG'){
+ command = util.format(command, grep, '%H%n%s%n%b%n==END==');
+ }else{
+ command = util.format(command, grep, '%H%n%s%n%b%n==END==', from);
+ }
+
// TODO(vojta): if it's slow, use spawn and stream it instead
-
- child.exec(util.format(GIT_LOG_CMD, grep, '%H%n%s%n%b%n==END==', from), function(code, stdout, stderr) {
+ child.exec(command , function(code, stdout, stderr) {
var commits = [];
@@ -144,7 +162,7 @@ var readGitLog = function(grep, from) {
};
-var writeChangelog = function(stream, commits, version, appName) {
+var writeChangelog = function(stream, commits) {
var sections = {
fix: {},
feat: {},
@@ -174,7 +192,7 @@ var writeChangelog = function(stream, commits, version, appName) {
};
});
- stream.write(util.format(HEADER_TPL, version, appName, version, currentDate()));
+ stream.write(util.format(HEADER_TPL, options.version, options.appName, options.version, currentDate()));
printSection(stream, 'Documentation', sections.docs);
printSection(stream, 'Bug Fixes', sections.fix);
printSection(stream, 'Features', sections.feat);
@@ -186,25 +204,27 @@ var writeChangelog = function(stream, commits, version, appName) {
var getPreviousTag = function() {
var deferred = q.defer();
- console.log(GIT_TAG_CMD);
+
child.exec(GIT_TAG_CMD, function(code, stdout, stderr) {
- if (code) deferred.reject('Cannot get the previous tag.');
- else deferred.resolve(stdout.replace('\n', ''));
+ if (code ) deferred.resolve('NONETAG');
+ else deferred.resolve(stdout.replace('\n', ''));
});
return deferred.promise;
};
-var generate = function(version, file, appName) {
-
+var generate = function() {
+
getPreviousTag().then(function(tag) {
-
console.log('Reading git log since', tag);
readGitLog('^fix|^feat|^docs|BREAKING', tag).then(function(commits) {
console.log('Parsed', commits.length, 'commits');
- console.log('Generating changelog to', file || 'stdout', '(', version, ')');
- writeChangelog(file ? fs.createWriteStream(file) : process.stdout, commits, version, appName);
+ console.log('Generating changelog to', options.file || 'stdout', '(', options.version, ')');
+ writeChangelog(options.file ? fs.createWriteStream(options.file) : process.stdout, commits);
+ },
+ function(){
+ console.log("It seems that that tag doesn't exists");
});
});
};
@@ -213,13 +233,30 @@ var generate = function(version, file, appName) {
// publish for testing
exports.parseRawCommit = parseRawCommit;
+var options = {
+ version : 'ALL',
+ file: 'Changelog.MD',
+ appName : 'My app - Changelog'
+};
+
// hacky start if not run by jasmine :-D
if (process.argv.join('').indexOf('jasmine-node') === -1) {
- //node changelog.js 1.0.0 changelog.md "My App"
+
if (process.argv[5] != undefined) {
- if (process.argv[5] == 'GitHub' || process.argv[5] == 'BitBucket') {
+ if (process.argv[5] == 'G' || process.argv[5] == 'B') {
PROVIDER = process.argv[5];
+
}
}
- generate(process.argv[2], process.argv[3], process.argv[4]);
+
+ var params = {
+ version : process.argv[2],
+ file : process.argv[3],
+ appName : process.argv[4]
+ }
+
+ for (var attrname in params) { options[attrname] = (typeof(params[attrname]) != 'undefined' ? params[attrname]: options[attrname]); }
+
+ generate();
+ //node changelog.js 1.0.0 changelog.md "My App" "G"
}
diff --git a/npm-debug.log b/npm-debug.log
deleted file mode 100644
index d1b433d..0000000
--- a/npm-debug.log
+++ /dev/null
@@ -1,59 +0,0 @@
-0 info it worked if it ends with ok
-1 verbose cli [ 'C:\\Program Files\\nodejs\\\\node.exe',
-1 verbose cli 'C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js',
-1 verbose cli 'install',
-1 verbose cli 'child_process',
-1 verbose cli '--save-dev' ]
-2 info using npm@1.3.8
-3 info using node@v0.10.18
-4 verbose node symlink C:\Program Files\nodejs\\node.exe
-5 verbose readDependencies using package.json deps
-6 verbose cache add [ 'child_process', null ]
-7 verbose cache add name=undefined spec="child_process" args=["child_process",null]
-8 verbose parsed url { protocol: null,
-8 verbose parsed url slashes: null,
-8 verbose parsed url auth: null,
-8 verbose parsed url host: null,
-8 verbose parsed url port: null,
-8 verbose parsed url hostname: null,
-8 verbose parsed url hash: null,
-8 verbose parsed url search: null,
-8 verbose parsed url query: null,
-8 verbose parsed url pathname: 'child_process',
-8 verbose parsed url path: 'child_process',
-8 verbose parsed url href: 'child_process' }
-9 silly lockFile 4845fa97-child-process child_process
-10 verbose lock child_process C:\Users\rafael.pedrola\AppData\Roaming\npm-cache\4845fa97-child-process.lock
-11 silly lockFile 4845fa97-child-process child_process
-12 silly lockFile 4845fa97-child-process child_process
-13 verbose addNamed [ 'child_process', '' ]
-14 verbose addNamed [ null, '*' ]
-15 silly lockFile 512a7ef6-child-process child_process@
-16 verbose lock child_process@ C:\Users\rafael.pedrola\AppData\Roaming\npm-cache\512a7ef6-child-process.lock
-17 silly addNameRange { name: 'child_process', range: '*', hasData: false }
-18 verbose url raw child_process
-19 verbose url resolving [ 'https://registry.npmjs.org/', './child_process' ]
-20 verbose url resolved https://registry.npmjs.org/child_process
-21 info trying registry request attempt 1 at 15:02:21
-22 http GET https://registry.npmjs.org/child_process
-23 http 404 https://registry.npmjs.org/child_process
-24 silly registry.get cb [ 404,
-24 silly registry.get { server: 'CouchDB/1.3.1 (Erlang OTP/R15B03)',
-24 silly registry.get date: 'Fri, 15 Nov 2013 14:02:25 GMT',
-24 silly registry.get 'content-type': 'application/json',
-24 silly registry.get 'content-length': '52',
-24 silly registry.get 'cache-control': 'must-revalidate' } ]
-25 silly lockFile 512a7ef6-child-process child_process@
-26 silly lockFile 512a7ef6-child-process child_process@
-27 error 404 'child_process' is not in the npm registry.
-27 error 404 You should bug the author to publish it
-27 error 404
-27 error 404 Note that you can also install from a
-27 error 404 tarball, folder, or http url, or git url.
-28 error System Windows_NT 6.1.7601
-29 error command "C:\\Program Files\\nodejs\\\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "install" "child_process" "--save-dev"
-30 error cwd C:\proyectos\generator\Git-change-log
-31 error node -v v0.10.18
-32 error npm -v 1.3.8
-33 error code E404
-34 verbose exit [ 1, true ]