add this update-version.js
file inside utils folder
const fs = require('fs')
let packageJson = require('../package.json')
// Current Time
const now = new Date()
// Read Markdown File
fs.readFile('CHANGELOG.md', 'utf8', (err, data) => {
if (err) {
console.error(err)
return
}
// Find Matched Line With `#`
const regexHash = /^#.*/gm
const matchedHash = data.match(regexHash)?.[1]
// Find Matched Data Inside `[]`
const regexBrackets = /\[(.*?)\]/g
const matchedBrackets = matchedHash.match(regexBrackets)
// Current Version
const version = matchedBrackets[0].replace(/\[|\]/g, '')
// Deploy Time
const formattedDate = `${ now.getDate() }-${ (now.getMonth() + 1).toString().padStart(2, '0') }-${ now.getFullYear() } ${ now.getHours() % 12 || 12 }:${ String(now.getMinutes()).padStart(2, '0') }:${ String(now.getSeconds()).padStart(2, '0') } ${ now.getHours() >= 12 ? 'PM' : 'AM' }`
// Update package.json With New Version And UpdatedAt Time
packageJson = { ...packageJson, version, updatedAt: formattedDate }
// Write Updated package.json Back To File
fs.writeFileSync('./package.json', JSON.stringify(packageJson, null, 2))
})
Update package.json
file with update-version
script
{
"name": "demo-project",
"version": "1.9.0",
"updatedAt": "25-04-2024 5:16:29 PM",
"private": true,
"engines": {
"node": "^18.18.0"
},
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"update-version": "node utils/update-version.js",
},
}
add CHANGELOG.md
file inside root directory
# Changelog
All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [1.9.0] - 25-04-2024
### Added
- Added `Route Wise and Brand Wise BPR Report` download feature
- On click `Sales Point Text Label` on map get statistics and redirect to home
### Fixed
- Update `Outlet Wise Hygiene Report` api params for sales point, and fixed spent time calculation
- Notification time issue
## [1.8.0] - 24-04-2024
### Added
- Highlight selected outlet and SR on map with animation
- Navigate to `Hygiene Report` page when select SR from map
### Changed
- Dynamically add table header and value based on filter panel selection when download `Route Wise Hygiene Report`
- Increase zoom level `25` to `30` when select outlet
- Change `Outlet Text Label` and `Icon Border` color `black` to `blue` when selected
Run npm run update-version
before using any git commands to deployment branch
npm run update-version
git add .
git commit -m"feat: added script for update software version with time"
git push
Import package.json
file and view
import packageJson from '../../package.json'
const Header = () => {
return (
<>
<div>v {packageJson?.version}</div>
<div> {packageJson?.updatedAt}</div>
</>
)}