forked from antelle/argon2-browser
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathprepare-deployment.js
78 lines (60 loc) · 2.18 KB
/
prepare-deployment.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
const fs = require('fs');
const child_process = require('child_process');
const packageJson = require('../package.json');
const version = packageJson.version;
const date = new Date().toISOString().split('T')[0];
const commit = process.argv
.filter((arg) => arg.startsWith('--commit'))
.map((arg) => arg.split('=')[1])[0];
const tag = process.argv
.filter((arg) => arg.startsWith('--tag'))
.map((arg) => arg.split('=')[1])[0];
const branch = process.argv
.filter((arg) => arg.startsWith('--branch'))
.map((arg) => arg.split('=')[1])[0];
const fileSafeBranch = branch.replace(/[^\w.]+/g, '_');
const filePrefix = tag || `branch/${fileSafeBranch}/${version}/${commit}`;
const versionName = filePrefix.replace(/\//g, '-');
console.log(
`Preparing deployment for commit ${commit} on ${branch} ` +
(tag ? 'and tag ' + tag : 'without tag')
);
const shaSums = child_process.execSync('shasum dist/argon2.*').toString();
console.log(`Release checksums:\n${shaSums}`);
const maxFileGrowth = 5;
for (const file of [
'dist/argon2.js',
'dist/argon2.wasm',
'dist/argon2-simd.wasm',
]) {
const gitSize = child_process
.execSync(`git ls-tree --long ${commit} "${file}"`)
.toString()
.split(/\s+/)[3];
const currentSize = fs.statSync(file).size;
const growth = (currentSize / gitSize) * 100 - 100;
console.log(
`${file}: ${gitSize} bytes in git, ${currentSize} bytes now, ` +
`${growth.toFixed(2)}% growth`
);
if (growth > maxFileGrowth) {
console.error(
`File ${file} is too big, allowed growth is ${maxFileGrowth}%.\n` +
`Please check if this is expected and update the build scripts if so.`
);
process.exit(2);
}
}
console.log(`File growth is within ${maxFileGrowth}%, proceeding.\n`);
const config = require('../.bintray.json');
config.version = {
name: versionName,
desc: versionName,
released: date,
vcs_tag: tag,
};
for (const file of config.files) {
file.uploadPattern = file.uploadPattern.replace('{prefix}', filePrefix);
}
fs.writeFileSync('bintray.json', JSON.stringify(config, null, 2));
console.log('Created bintray.json');