-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgit-release
More file actions
executable file
·108 lines (100 loc) · 2.94 KB
/
Copy pathgit-release
File metadata and controls
executable file
·108 lines (100 loc) · 2.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#!/usr/bin/env node
var Promise = require("bluebird");
var program = require('commander');
var cp = require('child_process');
Promise.promisifyAll(cp);
var fs = require('fs');
Promise.promisifyAll(fs);
var path = require('path');
var semver = require('semver');
var pjson = require('./package.json');
var execOutput = function(command) {
return cp.execSync(command, { encoding: 'utf8' }).trim();
};
var inquirer = require('inquirer');
inquirer.promptAsync = function(questions) {
return new Promise(function(resolve, reject) {
try {
inquirer.prompt(questions, function(answers) {
resolve(answers);
});
} catch (e) {
reject(e);
}
});
};
var checkBranchUpToDate = function(branchName) {
var local = execOutput('git rev-parse ' + branchName);
var remote = execOutput('git rev-parse origin/' + branchName);
if (local !== remote) {
console.error("Error: " + branchName + " not up to date with origin");
process.exit(1);
}
}
program.
version(pjson.version).
option('--init', 'initialize repository').
parse(process.argv);
try {
var lastVersion = execOutput('git describe --abbrev=0 --match "[0-9]*" master');
if (program.init) {
console.error("Error: looks like this repository has already been initialized");
process.exit(1);
}
}
catch (error) {
if (program.init) {
try {
execOutput('git flow init -d');
execOutput('git flow release start 0.0.1');
execOutput('git flow release finish -m \'0.0.1\' 0.0.1');
execOutput('git checkout develop');
console.log("OK -- this commit is now tagged as version 0.0.1, and we're on develop and ready to roll!");
console.log("check everything looks alright, and then push");
process.exit(0);
}
catch (error) {
console.error('something went wrong: ' + error);
process.exit(1);
}
}
else {
console.error("Error: no tags found in repo, run again with '--init' to initialize for gitflow");
process.exit(1);
}
}
checkBranchUpToDate('master');
checkBranchUpToDate('develop');
console.log('The last version was ' + lastVersion + '.');
inquirer.promptAsync({
name: 'release',
message: 'What type of release are we doing?',
type: 'list',
choices: [{
name: 'Major (for breaking changes)',
value: 'major'
}, {
name: 'Minor (for new features with non-breaking changes)',
value: 'minor'
}, {
name: 'Patch (for bug fixes with non-breaking changes)',
value: 'patch'
}]
})
.then(function(answers) {
var version = semver.inc(lastVersion, answers.release);
console.log('The new version will be ' + version + '.');
return inquirer.promptAsync({
name: 'confirm',
message: 'Sound good?',
type: 'confirm',
default: true
})
.then(function(answers2) {
if (!answers2.confirm){
process.exit(1);
}
var branchType = answers.release == 'patch' ? 'hotfix' : 'release';
console.log(execOutput('git flow ' + branchType + ' start ' + version));
});
});