48 lines
No EOL
1.6 KiB
JavaScript
48 lines
No EOL
1.6 KiB
JavaScript
const fs = require('fs');
|
|
const path = require('path');
|
|
|
|
function changeVersion(newVersion) {
|
|
const packageJsonPath = path.join(__dirname, 'package.json');
|
|
|
|
// Read the current package.json
|
|
fs.readFile(packageJsonPath, 'utf8', (err, data) => {
|
|
if (err) {
|
|
console.error('Error reading package.json:', err);
|
|
return;
|
|
}
|
|
|
|
let packageJson;
|
|
try {
|
|
packageJson = JSON.parse(data);
|
|
} catch (parseError) {
|
|
console.error('Error parsing package.json:', parseError);
|
|
return;
|
|
}
|
|
|
|
// Update the version
|
|
packageJson.version = newVersion;
|
|
|
|
// Write the updated package.json back to file
|
|
fs.writeFile(packageJsonPath, JSON.stringify(packageJson, null, 2), 'utf8', (writeErr) => {
|
|
if (writeErr) {
|
|
console.error('Error writing package.json:', writeErr);
|
|
return;
|
|
}
|
|
console.log(`Version updated to ${newVersion}`);
|
|
});
|
|
}
|
|
);
|
|
}
|
|
|
|
//Semver based on current date and time
|
|
const currentDate = new Date();
|
|
const year = currentDate.getFullYear();
|
|
const month = String(currentDate.getMonth() + 1).padStart(2, '0');
|
|
const day = String(currentDate.getDate()).padStart(2, '0');
|
|
const hours = String(currentDate.getHours()).padStart(2, '0');
|
|
const minutes = String(currentDate.getMinutes()).padStart(2, '0');
|
|
const seconds = String(currentDate.getSeconds()).padStart(2, '0');
|
|
|
|
const newVersion = `1.${year}${month}${day}.${hours}${minutes}${seconds}`;
|
|
|
|
changeVersion(newVersion); |