forked from highcharts/highcharts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
copy-release.js
142 lines (119 loc) · 3.99 KB
/
copy-release.js
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/*jslint nomen: true*/
/*global require, console, __dirname, process*/
/**
* This node script copies contents over from dist packages to shim repos and
* optionally commits and pushes releases.
*/
(function () {
'use strict';
var
// Set this to true after changes have been reviewed
push = process.argv[2] === '-push',
fs = require('fs-extra'),
sys = require('sys'),
cmd = require('child_process');
/**
* Commit, tag and push
*/
function runGit(product, version) {
var options = { cwd: __dirname.replace('/highcharts.com', '/' + product + '-release') },
puts = function (err, stdout) {
if (err) {
throw err;
}
sys.puts(stdout);
},
commands = [
//'git status',
'cd ~/github/' + product + '-release',
'git add --all',
'git commit -m "v' + version + '"',
'git tag -a "v' + version + '" -m "Tagged ' + product + ' version ' + version + '"',
'git push',
'git push --tags'
];
//cmd.exec(commands.join(' && '), options, puts);
console.log('\n--- ' + product + ': Verify changes and run: ---');
console.log(commands.join(' &&\n'));
}
/**
* Add the current version to the Bower file
*/
function updateJSONFiles(product, version, name) {
var i = 0;
function proceed (err) {
i = i + 1;
if (err) {
throw err;
}
if (push && i === 2) {
runGit(product, version);
}
}
console.log('Updating bower.json and package.json for ' + name + '...');
['bower', 'package'].forEach(function (file ) {
fs.readFile('../' + product + '-release/' + file + '.json', function (err, json) {
if (err) {
throw err;
}
json = JSON.parse(json);
json.version = 'v' + version;
json = JSON.stringify(json, null, ' ');
fs.writeFile('../' + product + '-release/' + file + '.json', json, proceed);
});
});
}
/**
* Copy the JavaScript files over
*/
function copyFiles(product, name) {
console.log('Copying ' + name + ' files...');
// Copy the files over to shim repo
fs.readdir('build/dist/' + product + '/js/', function (err, files) {
if (err) {
throw err;
}
files.forEach(function (src) {
if (src.indexOf('.') !== 0) {
fs.copy(
'build/dist/' + product + '/js/' + src,
'../' + product + '-release/' + src,
function (err) {
if (err) {
throw err;
}
}
);
}
});
});
}
/**
* Run the procedure for each of Highcharts, Highstock and Highmaps
*/
function runProduct(name, version) {
var product = name.toLowerCase();
copyFiles(product, name);
updateJSONFiles(product, version, name);
}
// Load the current products and versions
fs.readFile('build/dist/products.js', 'utf8', function (err, products) {
var name;
if (err) {
throw err;
}
if (products) {
products = products.replace('var products = ', '');
products = JSON.parse(products);
}
for (name in products) {
if (products.hasOwnProperty(name)) {
runProduct(name, products[name].nr);
}
}
if (!push) {
console.log('Please verify the changes in the release repos. Then run again ' +
'with -push as an argument.');
}
});
}());