1 | 'use strict';
|
2 |
|
3 | var _ = require('lodash'),
|
4 | childProcess = require('child_process'),
|
5 | execSync = childProcess.execSync,
|
6 | semver = require('semver'),
|
7 | spawn = childProcess.spawn;
|
8 |
|
9 | var branch = 'npm-packages';
|
10 |
|
11 | var reLine = /^.*$/gm;
|
12 |
|
13 | var output = execSync('git log ' + branch + ' --pretty=format:"%s | %h"').toString();
|
14 |
|
15 | var pairs = _.map(output.match(reLine), function(value) {
|
16 | var pair = _.map(_.trim(value, '"\'').split('|'), _.trim);
|
17 | pair[0] = _.result(/\d+(?:\.\d+)*/.exec(pair[0]), 0, '');
|
18 | return pair;
|
19 | });
|
20 |
|
21 | pairs = _.filter(pairs, '0');
|
22 |
|
23 | pairs.sort(function(a, b) {
|
24 | return semver.gt(a[0], b[0]) ? 1 : (semver.lt(a[0], b[0]) ? -1 : 0);
|
25 | });
|
26 |
|
27 | pairs = pairs.map(function(pair) {
|
28 | var tag = pair[0] + (branch == 'master' ? '' : '-' + branch);
|
29 | return [
|
30 |
|
31 | 'git tag -f -a -m ' + tag + ' "' + tag + '" ' + pair[1],
|
32 | 'git push -f origin ' + tag
|
33 | ];
|
34 | });
|
35 |
|
36 | _.each(pairs, function(pair, index) {
|
37 | _.each(pair, function(command) {
|
38 | _.delay(function() {
|
39 | console.log(command)
|
40 | execSync(command);
|
41 | }, 1000 * index);
|
42 | });
|
43 | });
|