This Python script is designed to generate version information for your project by leveraging Git metadata. It retrieves details such as the current Git tag, commit count, and branch name, then writes this information into a TypeScript file. This is useful for including version information within your application.
git describe --tags --long: Gets the most recent tag and the number of commits since that tag.git rev-parse --abbrev-ref HEAD: Retrieves the current branch name.src/version.tsx file with the version details in TypeScript format.To generate the version information and write it to a TypeScript file, execute the script with:
python versionGenerator.py
src/version.tsx.After running the script, src/version.tsx will contain something like:
export const versionInfo = {
versionCode: 1234567,
versionName: "1.0.0",
fullVersionName: "v1.0.0-5-gabc123@main",
updated: "2024-09-09 12:34:56"
};
Here:
versionCode is a unique code representing the version.versionName is extracted from the latest Git tag.fullVersionName includes the tag, commit count, and branch name.updated shows the date and time when the version was generated.src/version.tsx) needs to be writable. Make sure the src/ directory exists and has the right permissions.src/ directory is present and accessible.