UNPKG

1.14 kBJavaScriptView Raw
1'use strict';
2
3var _ = require('lodash'),
4 childProcess = require('child_process'),
5 execSync = childProcess.execSync,
6 semver = require('semver'),
7 spawn = childProcess.spawn;
8
9var branch = 'npm-packages';
10
11var reLine = /^.*$/gm;
12
13var output = execSync('git log ' + branch + ' --pretty=format:"%s | %h"').toString();
14
15var 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
21pairs = _.filter(pairs, '0');
22
23pairs.sort(function(a, b) {
24 return semver.gt(a[0], b[0]) ? 1 : (semver.lt(a[0], b[0]) ? -1 : 0);
25});
26
27pairs = pairs.map(function(pair) {
28 var tag = pair[0] + (branch == 'master' ? '' : '-' + branch);
29 return [
30 //'git checkout ' + tag + ' && git commit --amend --no-edit --date "`date`"',
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});