Skip to content

Commit

Permalink
Merge pull request #6 from mcasimir/dist-fixes
Browse files Browse the repository at this point in the history
fix cli dev
  • Loading branch information
mcasimir committed Jul 31, 2016
2 parents 0345338 + d30faa1 commit 9634a4e
Show file tree
Hide file tree
Showing 21 changed files with 410 additions and 295 deletions.
8 changes: 8 additions & 0 deletions .releaseflowrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module.exports = {
logLevel: 'debug',
developmentBranch: 'master',
plugins: [
'bump-package-json',
'generate-changelog'
]
};
11 changes: 0 additions & 11 deletions .releaseflowrc.js

This file was deleted.

Empty file removed lib/.gitkeep
Empty file.
35 changes: 0 additions & 35 deletions lib/Changelog.js

This file was deleted.

167 changes: 109 additions & 58 deletions lib/Git.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ var _execCommand = require('./execCommand');

var _execCommand2 = _interopRequireDefault(_execCommand);

var _semver = require('semver');

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
Expand Down Expand Up @@ -60,20 +62,48 @@ function _applyDecoratedDescriptor(target, property, decorators, descriptor, con

var COMMIT_SEPARATOR = '[----COMMIT--END----]';
var HASH_DELIMITER = '-hash-';
var GIT_DEFAULT_OPTIONS = {
remoteName: 'origin',
repoHttpProtocol: 'http'
};

var TAG_HISTORY_RE = /^([0-9a-f]{5,40})\s+\(tag: refs\/tags\/([^,\)]+)/;

var Git = (_class = function () {
function Git() {
var options = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0];

_classCallCheck(this, Git);

this.options = options;
this.options = Object.assign(GIT_DEFAULT_OPTIONS, options);
this.conventionalCommitsFilter = options.conventionalCommitsFilter || _conventionalCommitsFilter2.default;
this.conventionalCommitsParser = options.conventionalCommitsParser || _conventionalCommitsParser2.default;
this.execCommand = options.execCommand || _execCommand2.default;
}

_createClass(Git, [{
key: 'getRemoteUrl',
value: function getRemoteUrl() {
return this.execCommand('git config --get remote.' + this.options.remoteName + '.url');
}
}, {
key: 'getRepoHttpUrl',
value: function getRepoHttpUrl() {
if (this.options.repoHttpUrl) {
return this.options.repoHttpUrl;
}

var protocol = this.options.repoHttpProtocol;
var remoteUrl = this._remoteUrlToHttpUrl(this.getRemoteUrl());

return protocol + '://' + remoteUrl;
}
}, {
key: '_remoteUrlToHttpUrl',
value: function _remoteUrlToHttpUrl(remoteUrl) {
return remoteUrl.replace(/^[^@]*@/, '').replace(/:/g, '/').replace(/\.git$/, '');
}
}, {
key: 'openBranch',
value: function openBranch(branchName) {
this.execCommand('git checkout -b ' + branchName);
Expand All @@ -87,7 +117,7 @@ var Git = (_class = function () {
}, {
key: 'pushCurrentBranch',
value: function pushCurrentBranch() {
this.pushRef(this.currentBranch());
this.pushRef(this.getCurrentBranch());
}
}, {
key: 'pushRef',
Expand All @@ -98,7 +128,8 @@ var Git = (_class = function () {
key: 'link',
value: function link(path) {
path = (path || '').replace(/^\//, '');
return this.repoHttpUrl + '/' + path;
var base = this.getRepoHttpUrl().replace(/\/$/, '');
return base + '/' + path;
}
}, {
key: 'commitLink',
Expand All @@ -116,8 +147,8 @@ var Git = (_class = function () {
return this.execCommand(['git fetch', this.options.remoteName, 'refs/heads/*:refs/remotes/' + this.options.remoteName + '/*', '+refs/tags/*:refs/tags/*'].join(' '));
}
}, {
key: 'currentBranch',
value: function currentBranch() {
key: 'getCurrentBranch',
value: function getCurrentBranch() {
return this.execCommand('git rev-parse --abbrev-ref HEAD');
}
}, {
Expand All @@ -131,87 +162,107 @@ var Git = (_class = function () {
return Boolean(this.execCommand('git --no-pager cherry -v').length);
}
}, {
key: 'localTags',
value: function localTags() {
return this.execCommand('git log --no-walk --tags --pretty="%h %d %s" --decorate=full', {
key: '_parseTagHistoryLine',
value: function _parseTagHistoryLine(line) {
var tagMatch = line.match(TAG_HISTORY_RE);
if (tagMatch) {
return {
sha: tagMatch[1],
name: tagMatch[2]
};
}
}
}, {
key: 'getLocalTags',
value: function getLocalTags() {
var _this = this;

var tagHistory = this.execCommand('git log --no-walk --tags --pretty="%h %d %s" --decorate=full', {
splitLines: true
}).filter(function (line) {
return line.match(/\(tag: refs\/tags\//);
}).map(function (line) {
return line.match(/\(tag: refs\/tags\/([^,\)]+)/)[1];
return _this._parseTagHistoryLine(line);
}).filter(function (line) {
return line;
}).filter(function (tag) {
return (0, _semver.valid)(tag.name);
});

return tagHistory.sort(function (tag1, tag2) {
return (0, _semver.gt)(tag1.name, tag2.name);
});
}
}, {
key: 'hasLocalTags',
value: function hasLocalTags() {
return Boolean(this.localTags().length);
return Boolean(this.getLocalTags().length);
}
}, {
key: 'lastLocalTagSha',
value: function lastLocalTagSha() {
return this.hasLocalTags() && this.execCommand('git --no-pager log --no-walk --tags --pretty="%h" --decorate=short -1') || null;
key: 'getLastLocalTagSha',
value: function getLastLocalTagSha() {
var tags = this.getLocalTags();
var lastTag = tags[tags.length - 1];
return lastTag && lastTag.sha;
}
}, {
key: 'lastTagName',
value: function lastTagName() {
var tags = this.localTags();
return tags[tags.length];
}
}, {
key: 'commits',
value: function commits(fromSha, options) {
var _this = this;

var range = fromSha ? fromSha + '..' : '';
var rawCommits = this.execCommand(['git --no-pager log', '--pretty=\'format:%B%n' + HASH_DELIMITER + '%n%H' + COMMIT_SEPARATOR + '\'', range].join(' ')).split(COMMIT_SEPARATOR).filter(function (line) {
return line;
});

var commits = rawCommits.map(function (rawCommit) {
var commit = _this.conventionalCommitsParser.sync(rawCommit, options);

if (commit.header && commit.header.match('BREAKING') || commit.footer && commit.footer.match('BREAKING')) {
commit.breaking = true;
}

if (commit.hash) {
commit.shortHash = commit.hash.slice(0, 7);
}

return commit;
});

return this.conventionalCommitsFilter(commits);
key: 'getLastLocalTagName',
value: function getLastLocalTagName() {
var tags = this.getLocalTags();
var lastTag = tags[tags.length - 1];
return lastTag && lastTag.name;
}
}, {
key: 'hasLocalTag',
value: function hasLocalTag(tagName) {
return this.localTags().indexOf(tagName) !== -1;
var found = this.getLocalTags().find(function (tag) {
return tag.name === tagName;
});
return Boolean(found);
}
}, {
key: 'isCurrentBranch',
value: function isCurrentBranch(branchName) {
return this.currentBranch() === branchName;
return this.getCurrentBranch() === branchName;
}
}, {
key: 'remoteUrl',
get: function get() {
return this.execCommand('git config --get remote.' + this.options.remoteName + '.url');
key: 'getRawCommits',
value: function getRawCommits(fromSha) {
var range = fromSha ? fromSha + '..' : '';
return this.execCommand(['git --no-pager log', '--pretty=\'format:%B%n' + HASH_DELIMITER + '%n%H' + COMMIT_SEPARATOR + '\'', range].join(' ')).split(COMMIT_SEPARATOR).filter(function (line) {
return line;
});
}
}, {
key: 'repoHttpUrl',
get: function get() {
if (this.options.repoHttpUrl) {
return this.options.repoHttpUrl;
key: '_parseRawCommit',
value: function _parseRawCommit(rawCommit) {
var options = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];

var commit = this.conventionalCommitsParser.sync(rawCommit, options);

if (commit.header && commit.header.match('BREAKING') || commit.footer && commit.footer.match('BREAKING')) {
commit.breaking = true;
}

var protocol = this.options.repoHttpProtocol;
var remoteUrl = this.remoteUrl.replace(/^[^@]*@/, '').replace(/:/g, '/').replace(/\.git$/, '');
if (commit.hash) {
commit.shortHash = commit.hash.slice(0, 7);
}

return protocol + '://' + remoteUrl;
return commit;
}
}, {
key: 'conventionalCommits',
value: function conventionalCommits(fromSha) {
var _this2 = this;

var options = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];

var rawCommits = this.getRawCommits(fromSha);
var commits = rawCommits.map(function (rawCommit) {
return _this2._parseRawCommit(rawCommit, options);
});
return this.conventionalCommitsFilter(commits);
}
}]);

return Git;
}(), (_applyDecoratedDescriptor(_class.prototype, 'remoteUrl', [_memoizeDecorator2.default], Object.getOwnPropertyDescriptor(_class.prototype, 'remoteUrl'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, 'repoHttpUrl', [_memoizeDecorator2.default], Object.getOwnPropertyDescriptor(_class.prototype, 'repoHttpUrl'), _class.prototype)), _class);
}(), (_applyDecoratedDescriptor(_class.prototype, 'getRemoteUrl', [_memoizeDecorator2.default], Object.getOwnPropertyDescriptor(_class.prototype, 'getRemoteUrl'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, 'getRepoHttpUrl', [_memoizeDecorator2.default], Object.getOwnPropertyDescriptor(_class.prototype, 'getRepoHttpUrl'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, 'getLocalTags', [_memoizeDecorator2.default], Object.getOwnPropertyDescriptor(_class.prototype, 'getLocalTags'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, 'getLastLocalTagSha', [_memoizeDecorator2.default], Object.getOwnPropertyDescriptor(_class.prototype, 'getLastLocalTagSha'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, 'getLastLocalTagName', [_memoizeDecorator2.default], Object.getOwnPropertyDescriptor(_class.prototype, 'getLastLocalTagName'), _class.prototype)), _class);
exports.default = Git;
14 changes: 8 additions & 6 deletions lib/Phase.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = exports.Step = undefined;
exports.Step = exports.default = undefined;

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

Expand Down Expand Up @@ -38,9 +38,9 @@ var Phase = function () {
}
}, {
key: 'before',
value: function before(step, callback) {
var idx = this.steps.findIndex(function (fn) {
return fn.name === step;
value: function before(stepName, callback) {
var idx = this.steps.findIndex(function (step) {
return step.name === stepName;
});

if (idx !== -1) {
Expand All @@ -49,8 +49,10 @@ var Phase = function () {
}
}, {
key: 'run',
value: function run(args) {
return this.steps.run(args);
value: function run() {
var _steps;

return (_steps = this.steps).run.apply(_steps, arguments);
}
}]);

Expand Down
Loading

0 comments on commit 9634a4e

Please sign in to comment.