Skip to content

Commit 86bb581

Browse files
author
Kevin Gravier
committed
Merge branch 'release/1.1.1'
2 parents a89afcb + 32bcc78 commit 86bb581

21 files changed

+638
-127
lines changed

.travis.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,13 @@ before_install:
2727
brew install gnu-getopt;
2828
echo export FLAGS_GETOPT_CMD="$(brew --prefix gnu-getopt)/bin/getopt" >~/.gitflow_export;
2929
fi
30+
- export PREV=$(pwd)
31+
- git clone https://github.com/mrkmg/git-stream.git /tmp/git-stream
32+
- cd /tmp/git-stream
33+
- git submodule update --init --recursive
34+
- git checkout v0.7.2
35+
- sudo make install PREFIX=~
36+
- cd $PREV
3037
before_script:
3138
- git config --global user.email "test@test.com"
3239
- git config --global user.name "Testing Tester"

README.md

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
# node-generate-release
2-
Generate a release for a project following semver using nodejs and gitflow
2+
Generate a release for a project following semver using nodejs and
3+
[gitflow](https://github.com/petervanderdoes/gitflow-avh) or
4+
[git-stream](https://github.com/mrkmg/git-stream)
35

46
[![Generate Release on Travis CI](https://img.shields.io/travis/mrkmg/node-generate-release/master.svg?style=flat-square)](https://travis-ci.org/mrkmg/node-generate-release/branches)
57
[![Coverage Status](https://img.shields.io/coveralls/mrkmg/node-generate-release/master.svg?style=flat-square)](https://coveralls.io/github/mrkmg/node-generate-release?branch=master)
68
[![Generate Release on NPM](https://img.shields.io/npm/v/generate-release.svg?style=flat-square)](https://www.npmjs.com/package/generate-release)
79
[![Generate Release uses the MIT](https://img.shields.io/npm/l/generate-release.svg?style=flat-square)](https://opensource.org/licenses/MIT)
810

9-
Current Version: 1.1.0
11+
Current Version: 1.1.1
1012

1113
Requires NodeJS v4.0.0 or greater
1214

@@ -41,7 +43,7 @@ Then add the following to your `package.json` file:
4143

4244
Then you can run `npm run-script release` in order to generate a release.
4345

44-
**Important notes for OSX**
46+
**Important notes for gitflow OSX**
4547

4648
Git-flow from nvie is broken on OSX, and `generate-release` will not work. Please use the updated and actively
4749
maintained version from petervanderdoes,
@@ -59,13 +61,13 @@ This is the default process.
5961
1. Fetches from `remote`
6062
1. Rebases `remote`/develop into develop
6163
1. Resets master to `remote`/master
62-
1. Starts a git-flow release named the new version number
64+
1. Starts a gitflow or git-stream release named the new version number
6365
1. Changes the version number in package.json and any files in `files_to_version`
6466
1. Runs all `pre_commit_commands`
6567
1. Commits the changes to the package.json and any file in `files_to_version` and `files_to_commit`
6668
1. *This will also commit any file deletions which may have occurred during the `pre_commit_commands`*
6769
1. Runs all `post_commit_commands`
68-
1. Runs the git-flow finish release command
70+
1. Runs the gitflow or git-stream finish release command
6971
1. Pushes master, develop, and tags to `remote`
7072
1. Runs all the `post_complete_commands`
7173

@@ -88,7 +90,8 @@ run `generate-release --help` to see this as well.
8890
-n, --no-confirm Do not ask for confirmation. Default: prompt for confirmation
8991
-l, --skip-git-pull Do not pull from origin and rebase master and dev. Default: Do pull
9092
-s, --skip-git-push Do not push to origin when complete. Default: Do push
91-
-f, --skip-git-flow-finish Do not finish git-flow release. Default: Do finish
93+
-f, --skip-git-flow-finish, Do not finish git-flow release. Default: Do finish
94+
--skip-finish
9295
-d, --release-file FILE Path to your .release.json file. Default: ./.release.json
9396
-o, --remote REMOTE Change the remote. Default: origin
9497
-q, --quiet Less output. Default: Do show output
@@ -105,7 +108,7 @@ is an example with all default options set.
105108
"no_confirm": false,
106109
"skip_git_pull": false,
107110
"skip_git_push": false,
108-
"skip_git_flow_finish": false,
111+
"skip_finish": false,
109112
"release_message": true,
110113
"remote": "origin",
111114
"pre_commit_commands": [],

main/index.js

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ var ReleaseCanceledError_1 = require("./lib/error/ReleaseCanceledError");
4444
// tslint:disable-next-line
4545
require("es6-shim");
4646
var Observatory = require("observatory");
47-
var path_1 = require("path");
4847
var UncleanWorkingDirectoryError_1 = require("./lib/error/UncleanWorkingDirectoryError");
4948
var GitCommands_1 = require("./lib/GitCommands");
5049
var Options_1 = require("./lib/Options");
@@ -54,7 +53,6 @@ var HelpError_1 = require("./lib/error/HelpError");
5453
var askConfirmUpdate_1 = require("./lib/question/askConfirmUpdate");
5554
var askReleaseMessage_1 = require("./lib/question/askReleaseMessage");
5655
var askReleaseType_1 = require("./lib/question/askReleaseType");
57-
var gitFlowSettings_1 = require("./lib/helper/gitFlowSettings");
5856
var globNormalize_1 = require("./lib/helper/globNormalize");
5957
var incrementVersion_1 = require("./lib/helper/incrementVersion");
6058
var replaceVersionInFile_1 = require("./lib/helper/replaceVersionInFile");
@@ -117,7 +115,6 @@ var Main = /** @class */ (function () {
117115
case 0: return [4 /*yield*/, this.loadOptions()];
118116
case 1:
119117
_a.sent();
120-
this.loadGitFlowSettings();
121118
GitCommands_1.GitCommands.checkForCleanWorkingDirectory();
122119
this.loadPackageFile();
123120
return [4 /*yield*/, this.setReleaseMessage()];
@@ -180,9 +177,6 @@ var Main = /** @class */ (function () {
180177
});
181178
});
182179
};
183-
Main.prototype.loadGitFlowSettings = function () {
184-
this.gitFlowSettings = gitFlowSettings_1.gitFlowSettings(path_1.resolve("./"));
185-
};
186180
Main.prototype.loadPackageFile = function () {
187181
this.packageFile = new PackageFile_1.PackageFile(this.options.packageFileLocation);
188182
this.packageFile.load();
@@ -253,12 +247,10 @@ var Main = /** @class */ (function () {
253247
Main.prototype.setupGitCommands = function () {
254248
this.gitCommands = new GitCommands_1.GitCommands({
255249
currentVersion: this.options.currentVersion,
256-
developBranch: this.gitFlowSettings.develop,
257-
masterBranch: this.gitFlowSettings.master,
258250
nextVersion: this.options.nextVersion,
259251
releaseMessage: this.releaseMessage,
260252
remote: this.options.remote,
261-
skipGitFlowFinish: this.options.skipGitFlowFinish,
253+
skipFinish: this.options.skipFinish,
262254
});
263255
};
264256
Main.prototype.runGitPull = function () {
@@ -313,7 +305,7 @@ var Main = /** @class */ (function () {
313305
this.observatoryDone("post_commit_commands", "Complete");
314306
};
315307
Main.prototype.runGitFinish = function () {
316-
if (this.options.skipGitFlowFinish) {
308+
if (this.options.skipFinish) {
317309
this.observatoryDone("git_finish", "Skip");
318310
return;
319311
}

main/lib/GitCommands.js

Lines changed: 61 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,24 @@ var child_process_1 = require("child_process");
99
var fs_1 = require("fs");
1010
var temp_1 = require("temp");
1111
var UncleanWorkingDirectoryError_1 = require("./error/UncleanWorkingDirectoryError");
12+
var gitFlowSettings_1 = require("./helper/gitFlowSettings");
13+
var gitStreamSettings_1 = require("./helper/gitStreamSettings");
1214
var env = process.env;
1315
env.GIT_MERGE_AUTOEDIT = "no";
1416
var AVH_EDITION_REGEX = /AVH Edition/;
17+
var RepoType;
18+
(function (RepoType) {
19+
RepoType[RepoType["GitFlow"] = 0] = "GitFlow";
20+
RepoType[RepoType["GitStream"] = 1] = "GitStream";
21+
})(RepoType || (RepoType = {}));
1522
var GitCommands = /** @class */ (function () {
1623
function GitCommands(opts) {
17-
this.developBranch = "develop";
1824
this.isAvh = false;
19-
this.masterBranch = "master";
20-
this.skipGitFlowFinish = false;
25+
this.skipFinish = false;
2126
this.releaseMessage = "release/" + this.nextVersion;
2227
if (opts.currentVersion) {
2328
this.currentVersion = opts.currentVersion;
2429
}
25-
if (opts.developBranch) {
26-
this.developBranch = opts.developBranch;
27-
}
28-
if (opts.masterBranch) {
29-
this.masterBranch = opts.masterBranch;
30-
}
3130
if (opts.nextVersion) {
3231
this.nextVersion = opts.nextVersion;
3332
}
@@ -37,17 +36,38 @@ var GitCommands = /** @class */ (function () {
3736
if (opts.remote) {
3837
this.remote = opts.remote;
3938
}
40-
if (opts.skipGitFlowFinish) {
41-
this.skipGitFlowFinish = opts.skipGitFlowFinish;
39+
if (opts.skipFinish) {
40+
this.skipFinish = opts.skipFinish;
41+
}
42+
this.repoType = GitCommands.getRepoType();
43+
switch (this.repoType) {
44+
case RepoType.GitFlow:
45+
var gfSettings = gitFlowSettings_1.gitFlowSettings();
46+
this.masterBranch = gfSettings.master;
47+
this.developBranch = gfSettings.develop;
48+
this.isAvh = GitCommands.isAvhEdition();
49+
break;
50+
case RepoType.GitStream:
51+
var gsSettings = gitStreamSettings_1.gitStreamSettings();
52+
this.developBranch = gsSettings.develop;
4253
}
43-
this.isAvh = GitCommands.isAvhEdition();
4454
if (!opts.currentVersion) {
4555
throw new Error("Current Version is not set.");
4656
}
4757
if (!opts.nextVersion) {
4858
throw new Error("Next Version is not set.");
4959
}
5060
}
61+
GitCommands.getRepoType = function () {
62+
var gitConfigData = fs_1.readFileSync("./.git/config").toString();
63+
if (/\[gitstream/.test(gitConfigData)) {
64+
return RepoType.GitStream;
65+
}
66+
if (/\[gitflow/.test(gitConfigData)) {
67+
return RepoType.GitFlow;
68+
}
69+
throw new Error("Unknown Git Plugin");
70+
};
5171
GitCommands.isAvhEdition = function () {
5272
var versionResult = child_process_1.execSync("git flow version", { env: env });
5373
return AVH_EDITION_REGEX.test(versionResult.toString());
@@ -84,16 +104,20 @@ var GitCommands = /** @class */ (function () {
84104
GitCommands.git("fetch", this.remote);
85105
GitCommands.git("checkout", this.developBranch);
86106
GitCommands.git("pull", this.remote, this.developBranch, "--rebase");
87-
GitCommands.git("checkout", this.masterBranch);
88-
GitCommands.git("reset", "--hard", this.remote + "/" + this.masterBranch);
107+
if (this.repoType === RepoType.GitFlow) {
108+
GitCommands.git("checkout", this.masterBranch);
109+
GitCommands.git("reset", "--hard", this.remote + "/" + this.masterBranch);
110+
}
89111
};
90112
GitCommands.prototype.push = function () {
91-
if (this.skipGitFlowFinish) {
113+
if (this.skipFinish) {
92114
GitCommands.git("push", "-u", this.remote, this.releaseBranch);
93115
}
94116
else {
95117
GitCommands.git("push", this.remote, this.developBranch);
96-
GitCommands.git("push", this.remote, this.masterBranch);
118+
if (this.repoType === RepoType.GitFlow) {
119+
GitCommands.git("push", this.remote, this.masterBranch);
120+
}
97121
GitCommands.git("push", this.remote, "--tags");
98122
}
99123
};
@@ -108,8 +132,16 @@ var GitCommands = /** @class */ (function () {
108132
}
109133
};
110134
GitCommands.prototype.start = function () {
111-
GitCommands.git("checkout", this.developBranch);
112-
GitCommands.git("flow", "release", "start", this.nextVersion);
135+
switch (this.repoType) {
136+
case RepoType.GitFlow:
137+
GitCommands.git("checkout", this.developBranch);
138+
GitCommands.git("flow", "release", "start", this.nextVersion);
139+
break;
140+
case RepoType.GitStream:
141+
GitCommands.git("checkout", this.developBranch);
142+
GitCommands.git("stream", "release", "start", this.nextVersion);
143+
break;
144+
}
113145
};
114146
GitCommands.prototype.commit = function (files) {
115147
GitCommands.addDeletedFiles();
@@ -120,12 +152,18 @@ var GitCommands = /** @class */ (function () {
120152
GitCommands.git("commit", "-m", this.releaseMessage);
121153
};
122154
GitCommands.prototype.finish = function () {
123-
this.isAvh ? this.finishAvh() : this.finishNonAvh();
124-
};
125-
GitCommands.prototype.finishNonAvh = function () {
126-
GitCommands.git("flow", "release", "finish", "-m", this.releaseMessage, this.nextVersion);
155+
switch (this.repoType) {
156+
case RepoType.GitFlow:
157+
this.isAvh ?
158+
this.finishGitFlowAvh() :
159+
GitCommands.git("flow", "release", "finish", "-m", this.releaseMessage, this.nextVersion);
160+
break;
161+
case RepoType.GitStream:
162+
GitCommands.git("stream", "release", "finish", "-p", "-m", this.releaseMessage, this.nextVersion);
163+
break;
164+
}
127165
};
128-
GitCommands.prototype.finishAvh = function () {
166+
GitCommands.prototype.finishGitFlowAvh = function () {
129167
var releaseMessageFile = temp_1.path();
130168
fs_1.writeFileSync(releaseMessageFile, this.releaseMessage);
131169
try {

main/lib/Options.js

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,10 @@ var options = {
111111
switches: ["h", "help"],
112112
validate: function (input) { return typeof input === "boolean"; },
113113
},
114-
skipGitFlowFinish: {
114+
skipFinish: {
115115
default: false,
116-
file_key: "skip_git_flow_finish",
117-
switches: ["f", "skip-git-flow-finish"],
116+
file_key: ["skip_finish", "skip_git_flow_finish"],
117+
switches: ["f", "skip-finish", "skip-git-flow-finish"],
118118
validate: function (input) { return typeof input === "boolean"; },
119119
},
120120
skipGitPull: {
@@ -175,8 +175,18 @@ var Options = /** @class */ (function () {
175175
}
176176
};
177177
Options.prototype.getFileValue = function (fileKey) {
178-
if (this.fileData[fileKey]) {
179-
return this.fileData[fileKey];
178+
if (Array.isArray(fileKey)) {
179+
for (var _i = 0, fileKey_1 = fileKey; _i < fileKey_1.length; _i++) {
180+
var key = fileKey_1[_i];
181+
if (this.fileData[key]) {
182+
return this.fileData[key];
183+
}
184+
}
185+
}
186+
else {
187+
if (this.fileData[fileKey]) {
188+
return this.fileData[fileKey];
189+
}
180190
}
181191
};
182192
Options.prototype.loadFileData = function () {

main/lib/error/HelpError.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ var HelpError = /** @class */ (function (_super) {
1919
__extends(HelpError, _super);
2020
function HelpError(post) {
2121
var _newTarget = this.constructor;
22-
var _this = _super.call(this, "generate-release\n\n-p, --package FILE Path to package.json file. Default: ./package.json\n-c, --current-version VERSION Current Version. Default: read from package.json\n-v, --next-version VERSION Next Version. Default: automatically bumps\n-t, --release-type TYPE Release Type: patch, minor, major. Ignored when next-version is given.\n Default: prompt, if next-version is undefined\n-n, --no-confirm Do not ask for confirmation. Default: prompt for confirmation\n-l, --skip-git-pull Do not pull from origin and rebase master and dev. Default: Do pull\n-s, --skip-git-push Do not push to origin when complete. Default: Do push\n-f, --skip-git-flow-finish Do not finish git-flow release. Default: Do finish\n-d, --release-file FILE Path to your .release.json file. Default: ./.release.json\n-o, --remote REMOTE Change the remote. Default: origin\n-q, --quiet Less output. Default: Do show output\n-m, release-message [MESSAGE] Set a release message. If no message given, prompt for one. Will replace\n \"{version}\" with the next version. Default: Release {version}\n\n" + (post ? post : "") + "\n") || this;
22+
var _this = _super.call(this, "generate-release\n\n-p, --package FILE Path to package.json file. Default: ./package.json\n-c, --current-version VERSION Current Version. Default: read from package.json\n-v, --next-version VERSION Next Version. Default: automatically bumps\n-t, --release-type TYPE Release Type: patch, minor, major. Ignored when next-version is given.\n Default: prompt, if next-version is undefined\n-n, --no-confirm Do not ask for confirmation. Default: prompt for confirmation\n-l, --skip-git-pull Do not pull from origin and rebase master and dev. Default: Do pull\n-s, --skip-git-push Do not push to origin when complete. Default: Do push\n-f, --skip-git-flow-finish, Do not finish git-flow release. Default: Do finish\n --skip-finish\n-d, --release-file FILE Path to your .release.json file. Default: ./.release.json\n-o, --remote REMOTE Change the remote. Default: origin\n-q, --quiet Less output. Default: Do show output\n-m, release-message [MESSAGE] Set a release message. If no message given, prompt for one. Will replace\n \"{version}\" with the next version. Default: Release {version}\n\n" + (post ? post : "") + "\n") || this;
2323
var proto = _newTarget.prototype;
2424
if (Object.setPrototypeOf) {
2525
Object.setPrototypeOf(_this, proto);

main/lib/helper/gitFlowSettings.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@
77
Object.defineProperty(exports, "__esModule", { value: true });
88
var fs_1 = require("fs");
99
var iniparser_1 = require("iniparser");
10+
var path_1 = require("path");
1011
var BRANCH_CONFIG = 'gitflow "branch"';
1112
var PREFIX_CONFIG = 'gitflow "prefix"';
12-
function gitFlowSettings(projectPath) {
13-
var file = projectPath + "/.git/config";
13+
function gitFlowSettings() {
14+
var file = path_1.resolve(".") + "/.git/config";
1415
if (!fs_1.existsSync(file)) {
1516
throw new Error("Git Config File is missing: " + file);
1617
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
"use strict";
2+
/**
3+
* Generate Release
4+
* Written by Kevin Gravier <kevin@mrkmg.com>
5+
* MIT License 2018
6+
*/
7+
Object.defineProperty(exports, "__esModule", { value: true });
8+
var fs_1 = require("fs");
9+
var iniparser_1 = require("iniparser");
10+
var path_1 = require("path");
11+
var BRANCH_CONFIG = 'gitstream "branch"';
12+
var PREFIX_CONFIG = 'gitstream "prefix"';
13+
function gitStreamSettings() {
14+
var file = path_1.resolve(".") + "/.git/config";
15+
if (!fs_1.existsSync(file)) {
16+
throw new Error("Git Config File is missing: " + file);
17+
}
18+
var iniData = iniparser_1.parseSync(file);
19+
if (!iniData) {
20+
throw new Error("Failed to parse init file");
21+
}
22+
if (!iniData[BRANCH_CONFIG] || !iniData[BRANCH_CONFIG].working) {
23+
throw new Error("Git config missing git-stream branch configuration");
24+
}
25+
return {
26+
develop: iniData[BRANCH_CONFIG].working,
27+
};
28+
}
29+
exports.gitStreamSettings = gitStreamSettings;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "generate-release",
3-
"version": "1.1.0",
3+
"version": "1.1.1",
44
"description": "Generate a release using git-glow",
55
"engines": {
66
"node": ">=4.0.0"

0 commit comments

Comments
 (0)