forked from VCityTeam/UD-Viz
-
Notifications
You must be signed in to change notification settings - Fork 0
/
prePublish.js
69 lines (61 loc) · 2.11 KB
/
prePublish.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
const fs = require('fs');
const exec = require('child-process-promise').exec;
const version = process.argv[2];
if (!version) throw new Error('no version argument found');
const subStringVersion = version.split('.');
if (subStringVersion.length != 3)
throw new Error('Version format length error');
subStringVersion.forEach((digit) => {
if (isNaN(digit)) {
throw new Error('Version format digit error');
}
});
console.log('Change ud-viz-monorepo version to ', version);
/**
* It prints the stdout and stderr of a result object
*
* @param {{stdout:string,stderr:string}} result - The result of the command execution.
*/
const printExec = function (result) {
console.log('stdout: \n', result.stdout);
console.log('stderr: \n', result.stderr);
};
const changeVersionPackageJSON = function (path) {
return new Promise((resolve) => {
console.log(path, '[x]');
const content = JSON.parse(fs.readFileSync(path));
content.version = version;
// update dependencie
for (const key in content.dependencies) {
if (key.startsWith('@ud-viz/')) {
content.dependencies[key] = version;
}
}
fs.writeFileSync(path, JSON.stringify(content));
exec('npx prettier ' + path + ' -w')
.then(printExec)
.then(resolve);
});
};
changeVersionPackageJSON('./packages/shared/package.json').then(() => {
changeVersionPackageJSON('./packages/browser/package.json').then(() => {
changeVersionPackageJSON('./packages/node/package.json').then(() => {
changeVersionPackageJSON('./package.json').then(() => {
console.log('Start reset');
exec('npm run reset')
.then(printExec)
.then(() => {
exec(
'git log | grep -v ^commit | grep -v ^Author | grep -v ^Date | grep -vi merge | grep . | head -n 150 > ./docs/static/ChangelogDiff.txt'
)
.then(printExec)
.then(() => {
console.log(
'PrePublish done, you have to update ./docs/static/Changelog.md with ./docs/static/ChangelogDiff.txt'
);
});
});
});
});
});
});