forked from highcharts/highcharts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
copy-release.js
145 lines (132 loc) · 4.41 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
/* eslint-env node, es6 */
/* eslint valid-jsdoc: 0, no-console: 0 */
/* eslint func-style: ["error", "declaration", { "allowArrowFunctions": true }] */
/**
* 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');
// TODO avoid dependency on highcharts-assembler
const {
getFilesInFolder
} = require('highcharts-assembler/src/build.js');
// Set this to true after changes have been reviewed
const push = process.argv[2] === '--push';
const releaseRepo = 'highcharts-dist';
/**
* 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,
'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, cb) {
var i = 0;
/**
* Continue after writing files
*/
function proceed(err) {
const noop = () => {};
i = i + 1;
if (err) {
throw err;
}
return (i === 2) ? cb() : noop();
}
console.log('Updating bower.json and package.json for ' + name + '...');
['bower', 'package'].forEach(function (file) {
fs.readFile('../' + releaseRepo + '/' + file + '.json', function (err, json) {
if (err) {
throw err;
}
json = JSON.parse(json);
json.version = version;
json = JSON.stringify(json, null, ' ');
fs.writeFile('../' + releaseRepo + '/' + file + '.json', json, proceed);
});
});
}
/**
* Copy the JavaScript files over
*/
function copyFiles() {
const fnFilter = (src) => (
(src.indexOf('.') !== 0) &&
(src.indexOf('readme') === -1)
);
const existing = [];
const mapFromTo = {};
const pathTo = '../' + releaseRepo + '/';
['highcharts', 'highstock', 'highmaps', 'gantt']
.map((prod) => 'build/dist/' + prod + '/code/')
.forEach((pathDir) => {
const files = getFilesInFolder(pathDir, true);
files.forEach((filename) => {
if (fnFilter(filename) && !existing.includes(filename)) {
existing.push(filename);
mapFromTo[pathDir + filename] = pathTo + filename;
}
});
});
// Copy all the files to release repository
Object.keys(mapFromTo).forEach((from) => {
const to = mapFromTo[from];
fs.copy(
from,
to,
function (copyerr) {
if (copyerr) {
throw copyerr;
}
}
);
});
}
// Load the current products and versions
fs.readFile('build/dist/products.js', 'utf8', function (err, products) {
if (err) {
throw err;
}
if (products) {
products = products.replace('var products = ', '');
products = JSON.parse(products);
}
const name = 'Highcharts';
const version = products[name].nr;
const product = name.toLowerCase();
copyFiles(product, name);
updateJSONFiles(product, version, name, () => {
if (push) {
runGit(product, version);
}
});
if (!push) {
console.log('Please verify the changes in the release repos. Then run again ' +
'with --push as an argument.');
}
});
}());