How do I display the app version in angular application? the version should be taken from package.json file
{
\"name\": \"angular-app\",
\"v
I have tried to solve this in a bit different way, also considering the ease of convenience and maintainability.
I have used the bash script to change the version across the whole application. The following script will ask you for the desired version number, and the same is applied throughout the application.
#!/bin/bash
set -e
# This script will be a single source of truth for changing versions in the whole app
# Right now its only changing the version in the template (e.g index.html), but we can manage
# versions in other files such as CHANGELOG etc.
PROJECT_DIR=$(pwd)
TEMPLATE_FILE="$PROJECT_DIR/src/index.html"
PACKAGE_FILE="$PROJECT_DIR/package.json"
echo ">> Change Version to"
read -p '>> Version: ' VERSION
echo
echo " #### Changing version number to $VERSION #### "
echo
#change in template file (ideally footer)
sed -i '' -E "s/(.*)<\/p>/
App version: $VERSION<\/p>/" $TEMPLATE_FILE
#change in package.json
sed -i '' -E "s/\"version\"\:(.*)/\"version\"\: \"$VERSION\",/" $PACKAGE_FILE
echo; echo "*** Mission Accomplished! ***"; echo;
I have saved this script in a file named version-manager.sh in the root of the project, and in my package.json file, I also created a script to run it when it is necessary to modify the version.
"change-version": "bash ./version-manager.sh"
Finally, I can just change the version by executing
npm run change-version
This command will change the version in the index.html template and also in the package.json file. Following were the few screenshots taken from my existing app.