rename.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. try {
  2. console.log("Starting the binary renaming script...");
  3. const fs = require('fs');
  4. const prefix = process.argv[2];
  5. const pulsarVersion = require('../package.json').version;
  6. const versionSegments = pulsarVersion.split('.');
  7. const lastSegment = versionSegments[versionSegments.length - 1];
  8. // Detecting Rolling release version strings
  9. if (lastSegment.length > 4) {
  10. // For example, '1-dev' is longer than 4 characters,
  11. // and the format like '2023081600' from CI is longer than 4 characters.
  12. // Either of those would indicate Rolling, not Regular.
  13. console.log(`Based on the version string in package.json (${pulsarVersion}),`);
  14. console.log('we are *not* preparing a Regular release, so *not* renaming any binaries.');
  15. console.log('Exiting the binary renaming script.');
  16. process.exit(0);
  17. }
  18. // Warn about required prefix as first argument.
  19. // If prefix was not provided, print warning and do nothing else,
  20. // exiting "cleanly" with status 0.
  21. if (typeof prefix !== "string" || prefix.length === 0) {
  22. console.log("A prefix is required. Pass the desired prefix as the first argument to this script.");
  23. console.log('Example usage: "node script/rename.js Windows"');
  24. console.log('or: "node script/rename.js ARM.Linux"');
  25. console.log("Exiting the binary renaming script.");
  26. process.exit(0);
  27. }
  28. console.log(`Based on the version string in package.json (${pulsarVersion}),`);
  29. console.log('we *are* preparing a Regular release, so *renaming all binaries with prefixes*.');
  30. console.log(`Prefix is: ${prefix}`);
  31. // Renaming files under ./binaries/* that haven't already been renamed...
  32. const fileNames = fs.readdirSync('./binaries');
  33. fileNames.forEach((file) => {
  34. console.log(`Existing filename is: ${file}`);
  35. // We use 'starting with "p" or "P"' as the heuristic for whether or not
  36. // the file has already been renamed (and thus prefixed) before.
  37. if (file.startsWith('p') || file.startsWith('P')) {
  38. let dest = `${prefix}.${file}`
  39. // Replace any spaces with periods in the resulting filenames
  40. dest = dest.replace(/ /g,".");
  41. console.log(`Renaming file from "${file}" to "${dest}"`);
  42. fs.renameSync(`./binaries/${file}`, `./binaries/${dest}`);
  43. } else {
  44. console.log('Filename does not start with "p" or "P". Skipping...');
  45. };
  46. });
  47. } catch (e) {
  48. console.error("There was a problem during the renaming script!:");
  49. console.error(e);
  50. };