-
-
Notifications
You must be signed in to change notification settings - Fork 145
/
Copy pathrename.js
62 lines (50 loc) · 2.3 KB
/
rename.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
try {
console.log("Starting the binary renaming script...");
const fs = require('fs');
const prefix = process.argv[2];
const pulsarVersion = require('../package.json').version;
const versionSegments = pulsarVersion.split('.');
const lastSegment = versionSegments[versionSegments.length - 1];
// Detecting Rolling release version strings
if (lastSegment.length > 4) {
// For example, '1-dev' is longer than 4 characters,
// and the format like '2023081600' from CI is longer than 4 characters.
// Either of those would indicate Rolling, not Regular.
console.log(`Based on the version string in package.json (${pulsarVersion}),`);
console.log('we are *not* preparing a Regular release, so *not* renaming any binaries.');
console.log('Exiting the binary renaming script.');
process.exit(0);
}
// Warn about required prefix as first argument.
// If prefix was not provided, print warning and do nothing else,
// exiting "cleanly" with status 0.
if (typeof prefix !== "string" || prefix.length === 0) {
console.log("A prefix is required. Pass the desired prefix as the first argument to this script.");
console.log('Example usage: "node script/rename.js Windows"');
console.log('or: "node script/rename.js ARM.Linux"');
console.log("Exiting the binary renaming script.");
process.exit(0);
}
console.log(`Based on the version string in package.json (${pulsarVersion}),`);
console.log('we *are* preparing a Regular release, so *renaming all binaries with prefixes*.');
console.log(`Prefix is: ${prefix}`);
// Renaming files under ./binaries/* that haven't already been renamed...
const fileNames = fs.readdirSync('./binaries');
fileNames.forEach((file) => {
console.log(`Existing filename is: ${file}`);
// We use 'starting with "p" or "P"' as the heuristic for whether or not
// the file has already been renamed (and thus prefixed) before.
if (file.startsWith('p') || file.startsWith('P')) {
let dest = `${prefix}.${file}`
// Replace any spaces with periods in the resulting filenames
dest = dest.replace(/ /g,".");
console.log(`Renaming file from "${file}" to "${dest}"`);
fs.renameSync(`./binaries/${file}`, `./binaries/${dest}`);
} else {
console.log('Filename does not start with "p" or "P". Skipping...');
};
});
} catch (e) {
console.error("There was a problem during the renaming script!:");
console.error(e);
};