forked from highcharts/highcharts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcopy-release.js
176 lines (151 loc) · 5.11 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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
/* eslint-env node */
/* eslint valid-jsdoc: 0, no-console: 0 */
/**
* This node script copies contents over from dist packages to shim repos and
* optionally commits and pushes releases.
*/
(function () {
'use strict';
var fs = require('fs-extra');
// Set this to true after changes have been reviewed
//var push = process.argv[2] === '--push';
var push = true;
function releaseRepo(product) {
return {
highcharts: 'highcharts-dist',
highmaps: 'highmaps-release',
highstock: 'highstock-release'
}[product];
}
/**
* Commit, tag and push
*/
function runGit(product, version) {
/*
var options = { cwd: __dirname.replace('/highcharts', '/' + product + '-release') },
puts = function (err, stdout) {
if (err) {
throw err;
}
sys.puts(stdout);
};
*/
var commands = [
'cd ~/github/' + releaseRepo(product),
'git add --all',
'git commit -m "v' + version + '"',
'git tag -a "v' + version + '" -m "Tagged ' + product + ' version ' + version + '"',
'git push',
'git push --tags',
'npm publish'
];
// 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;
/**
* Continue after writing files
*/
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('../' + releaseRepo(product) + '/' + file + '.json', function (err, json) {
if (err) {
throw err;
}
json = JSON.parse(json);
json.version = 'v' + version;
json = JSON.stringify(json, null, ' ');
fs.writeFile('../' + releaseRepo(product) + '/' + file + '.json', json, proceed);
});
});
}
/**
* Copy the JavaScript files over
*/
function copyFiles(product, name) {
var extras = [];
console.log('Copying ' + name + ' files...');
// Copy the files over to shim repo
fs.readdir('build/dist/' + product + '/code/', function (err, files) {
if (err) {
throw err;
}
files.forEach(function (src) {
if ((src.indexOf('.') !== 0) && (src.indexOf('readme') === -1)){
fs.copy(
'build/dist/' + product + '/code/' + src,
'../' + releaseRepo(product) + '/' + src,
function (copyerr) {
if (copyerr) {
throw copyerr;
}
}
);
}
});
});
// Copy Highstock and Highmaps into the Highcharts release repo for use
// with npm and bower.
if (product === 'highstock') {
extras = ['highstock.src.js', 'highstock.js'];
} else if (product === 'highmaps') {
extras = ['highmaps.src.js', 'highmaps.js', 'modules/map.src.js', 'modules/map.js'];
}
extras.forEach(function (src) {
['', 'js/'].forEach(function (folder) {
var path = folder + src;
fs.copy(
'build/dist/' + product + '/code/' + path,
'../' + releaseRepo('highcharts') + '/' + path,
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.');
}
});
}());