mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2024-09-11 19:17:09 +03:00
script: Use process.exit() in renaming script
Gets rid of a lot of if-else that made the code harder to follow. This should be pretty safe and unproblematic in a standalone script like this, versus some more complex or nested Node process scenario, or scenarios with async input/output that might be ongoing when the process.exit() is handled. Also, update some of the code comments a bit. Co-authored-by: Andrew Dupont <github@andrewdupont.net>
This commit is contained in:
parent
5ecd2b8475
commit
f21824e730
@ -10,6 +10,7 @@ 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.
|
||||
@ -17,42 +18,43 @@ if (lastSegment.length > 4) {
|
||||
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.');
|
||||
} else {
|
||||
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.");
|
||||
// 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(`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}`);
|
||||
|
||||
// Rename 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...');
|
||||
};
|
||||
});
|
||||
console.log('Filename does not start with "p" or "P". Skipping...');
|
||||
};
|
||||
};
|
||||
});
|
||||
|
||||
} catch (e) {
|
||||
console.error("There was a problem during the renaming script!:");
|
||||
|
Loading…
Reference in New Issue
Block a user