Skip to content

Commit

Permalink
Merge branch 'refactor-cli-handling' into develop
Browse files Browse the repository at this point in the history
 * refactor: mute index.js
 * style: clean some empty lines
 * chore: update binary task and don't concatenate files
 * refactor: cli handling into helper module
  • Loading branch information
davidlinse committed May 24, 2014
1 parent 8144c89 commit ec863ca
Show file tree
Hide file tree
Showing 9 changed files with 136 additions and 78 deletions.
2 changes: 1 addition & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ module.exports = function(grunt) {
grunt.registerTask('pre', ['clean', 'default']);

//
grunt.registerTask('build', ['concat', 'generate-binary']);
grunt.registerTask('build', [/*'concat', */ 'generate-binary']);

//
grunt.registerTask('release', ['pre', 'cov', 'build', 'plato', 'cl', 'clean:tmp']);
Expand Down
33 changes: 33 additions & 0 deletions bin/_cli.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*!
* git-contributors (0.1.8) - 2014-05-24
* https://github.com/davidlinse/git-contributors.js.git
* Copyright (c) 2014 David Linse; License: MIT
*/

/**
* cli helper module
* @version 0.1.1
*/

module.exports = {

parse: function (argv, version) {
'use strict';

var program = require('commander');

// TODO: move to 'cli' helper
//
program
.version(version)
.usage('/path/to/repository')
.parse(argv);

if (!program.args.length) {
program.help();
process.exit(0);
}

return program;
}
};
49 changes: 13 additions & 36 deletions bin/git-contributors
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,19 @@
* Copyright (c) 2014 David Linse; License: MIT
*/

/* jshint indent:2 */

var exec = require('child_process').exec;

var git = {

log: function(opts, cb) {
'use strict';

process.chdir(opts.cwd);

exec('git log --pretty="%an %ae"', opts, function(err, stdout) {
cb(err, stdout);
});

}
};
/*!
* git-contributors (0.1.8) - 2014-05-24
* https://github.com/davidlinse/git-contributors.js.git
* Copyright (c) 2014 David Linse; License: MIT
*/

module.exports = git;
/**
* git-contributors module
*/

var fs = require('fs'),
path = require('path'),
git = require('./gitlog'),

_ = require('lodash');

Expand Down Expand Up @@ -103,7 +94,7 @@ var __exec = function (err, stdout, cb) {
cb(null, list);
};


//--

var GitContributors = function GitContributors () {};

Expand All @@ -123,25 +114,11 @@ GitContributors.prototype.list = function (opts, cb) {
});
};


GitContributors.prototype.parse = function parseOpts (argv, version) {
'use strict';

var program = require('commander');

// TODO: move to 'cli' helper
//
program
.version(version)
.usage('/path/to/repository')
.parse(process.argv);

if (!program.args.length) {
program.help();
process.exit(0);
}

var target = program.args[0];
var program = require('./_cli').parse(argv, version);
var target = program.args[0];

this.list(target, function (err, data) {

Expand All @@ -151,7 +128,6 @@ GitContributors.prototype.parse = function parseOpts (argv, version) {
}

console.log(data);

process.exit(0);
});
};
Expand All @@ -168,3 +144,4 @@ if (!module.parent) {

module.exports.GitContributors.parse(process.argv, version);
}

29 changes: 29 additions & 0 deletions bin/gitlog.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*!
* git-contributors (0.1.8) - 2014-05-24
* https://github.com/davidlinse/git-contributors.js.git
* Copyright (c) 2014 David Linse; License: MIT
*/

/**
* gitlog module
*/

/* jshint indent:2 */

var exec = require('child_process').exec;

var git = {

log: function(opts, cb) {
'use strict';

process.chdir(opts.cwd);

exec('git log --pretty="%an %ae"', opts, function(err, stdout) {
cb(err, stdout);
});

}
};

module.exports = git;
9 changes: 0 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,3 @@
module.exports.GitContributors = process.env.MOCHA_COV ?
require('./lib-cov/git-contributors').GitContributors :
require('./lib/git-contributors').GitContributors;


if (!module.parent) {

var fs = require('fs');
var version = JSON.parse(fs.readFileSync('package.json', 'utf-8')).version;

module.exports.GitContributors.parse(process.argv, version);
}
33 changes: 33 additions & 0 deletions lib/_cli.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*!
* git-contributors (0.1.8) - 2014-05-24
* https://github.com/davidlinse/git-contributors.js.git
* Copyright (c) 2014 David Linse; License: MIT
*/

/**
* cli helper module
* @version 0.1.1
*/

module.exports = {

parse: function (argv, version) {
'use strict';

var program = require('commander');

// TODO: move to 'cli' helper
//
program
.version(version)
.usage('/path/to/repository')
.parse(argv);

if (!program.args.length) {
program.help();
process.exit(0);
}

return program;
}
};
31 changes: 9 additions & 22 deletions lib/git-contributors.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
/*!
* git-contributors (0.1.8) - 2014-05-24
* https://github.com/davidlinse/git-contributors.js.git
* Copyright (c) 2014 David Linse; License: MIT
*/

/**
* git-contributors module
* https://github.com/davidlinse/git-contributors.js
*
* Copyright (c) 2014 David Linse, contributors
* Licensed under the MIT license.
*/

var fs = require('fs'),
Expand Down Expand Up @@ -84,7 +86,7 @@ var __exec = function (err, stdout, cb) {
cb(null, list);
};


//--

var GitContributors = function GitContributors () {};

Expand All @@ -104,25 +106,11 @@ GitContributors.prototype.list = function (opts, cb) {
});
};


GitContributors.prototype.parse = function parseOpts (argv, version) {
'use strict';

var program = require('commander');

// TODO: move to 'cli' helper
//
program
.version(version)
.usage('/path/to/repository')
.parse(process.argv);

if (!program.args.length) {
program.help();
process.exit(0);
}

var target = program.args[0];
var program = require('./_cli').parse(argv, version);
var target = program.args[0];

this.list(target, function (err, data) {

Expand All @@ -132,7 +120,6 @@ GitContributors.prototype.parse = function parseOpts (argv, version) {
}

console.log(data);

process.exit(0);
});
};
Expand Down
10 changes: 6 additions & 4 deletions lib/gitlog.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
/*!
* git-contributors (0.1.8) - 2014-05-24
* https://github.com/davidlinse/git-contributors.js.git
* Copyright (c) 2014 David Linse; License: MIT
*/

/**
* gitlog module
* https://github.com/davidlinse/git-contributors.js
*
* Copyright (c) 2014 David Linse, contributors
* Licensed under the MIT license.
*/

/* jshint indent:2 */
Expand Down
18 changes: 12 additions & 6 deletions tasks/generate-binary.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
Generate the binary file.
$ grunt generate-bin
$ grunt generate-binary
@author David Linse <[email protected]>
@version 0.1.0
@version 0.1.1
@license MIT
*/
Expand All @@ -17,20 +17,26 @@ module.exports = function(grunt) {
grunt.registerTask('generate-binary', function() {

var shebang = grunt.file.read('fixtures/binary-header');
var footer = grunt.file.read('fixtures/binary-footer');

var opts = {
process: function(content) {
return shebang +'\n' +
content.replace(' git = require(\'./gitlog\'),\n', '');
return shebang + '\n' +
grunt.config.process('<%= banner %>') +
content + '\n' +
footer + '\n';
}
};

var src = grunt.config.process('tmp/<%= pkg.name %>.js');
var src = grunt.config.process('lib/<%= pkg.name %>.js');
var dest = grunt.config.process('bin/<%= pkg.name %>');

grunt.file.mkdir('bin');
grunt.file.copy('lib/_cli.js', 'bin/_cli.js');
grunt.file.copy('lib/gitlog.js', 'bin/gitlog.js');

grunt.file.copy(src, dest, opts);

require('fs').chmodSync(dest, '755');
});

};

0 comments on commit ec863ca

Please sign in to comment.