Repository navigation
Expand file tree
/
Copy pathversion.js
More file actions
48 lines (38 loc) · 1.42 KB
/
Copy pathversion.js
File metadata and controls
48 lines (38 loc) · 1.42 KB
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
const fs = require('fs');
const path = require('path');
const {version} = require('../package');
const {format} = require('date-fns');
const crypto = require('crypto');
const cwd = process.cwd();
function replaceTextInFile(filepath, match, replacement) {
var filename = path.join(cwd, filepath);
const updatedText = fs
.readFileSync(filename, 'utf-8')
.replace(match, replacement);
if (updatedText.indexOf(replacement) === -1) {
throw new Error(`Failed to update text in ${filepath}`);
}
fs.writeFileSync(filename, updatedText);
console.log(`Updated ${filepath}: ${replacement}`);
}
// Update version in snippet
replaceTextInFile(
path.join('src', 'amplitude-snippet.js'),
/cdn\.amplitude\.com\/libs\/amplitude-[0-9]+\.[0-9]+\.[0-9]+-min\.gz\.js/,
`cdn.amplitude.com/libs/amplitude-${version}-min.gz.js`,
);
// Update integrity hash in snippet
const sdkText = fs.readFileSync(path.join('.', `amplitude.min.js`), 'utf-8');
const hash = crypto.createHash('sha384').update(sdkText).digest('base64');
replaceTextInFile(
path.join('src', 'amplitude-snippet.js'),
/as.integrity = 'sha384-[a-zA-Z0-9+\/]+';/,
`as.integrity = 'sha384-${hash}';`,
);
// Update version and relase date in readme
replaceTextInFile(
'README.md',
/\[[0-9]+\.[0-9]+\.[0-9]+ - Released on [A-Z][a-z]+ [0-9]+, [0-9]{4}]/,
`[${version} - Released on ${format(new Date(), 'MMMM D, YYYY')}]`,
);
console.log(`Updated version to ${version}`);