3.0.2 • Published 2 years ago
@yummy/app-version v3.0.2
A yummy app version library
An opinionated utility to generate a version of the current library / application.
Installation
# npm i -D @yummy/app-versionUsage
The library needs a working git repository to run. It uses the git describe command to generate the output.
By default, appVersion uses the last found git tag and appends the branch, date, distance to the last git tag and git hash:
import { appVersion } from "@yummy/app-version";
appVersion();
// => 1.2.3+main.20240608+7.g6cef876
^ ^ ^ ^ ^
| | | | |
git tag | date | git hash
git branch distance to last git commitAll parts can be disabled individually:
branch = falseto omit the git branchdate = falseto omit the current datedistance = falseto omit the distance to the last git taghash = falseto omit the current git hash
import { appVersion } from "@yummy/app-version";
appVersion({ branch: false });
// => 1.2.3+20240608+7.g6cef876
appVersion({ date: false });
// => 1.2.3+main+7.g6cef876
appVersion({ distance: false });
// => 1.2.3+main.20240608+g6cef876
appVersion({ hash: false });
// => 1.2.3+main.20240608+7
// => 1.2.3+main.20240608+7.g6cef876Additionally, you can pass a prefix:
import { appVersion } from "@yummy/app-version";
appVersion({ prefix: "my-custom-prefix" });
// => my-custom-prefix+1.2.3+20240608+7.g6cef876Example with esbuild
This is useful for when you want to transpile your code into a specific directory.
import * as esbuild from "esbuild";
import { appVersion } from "@yummy/app-version";
// assume that @ is the project root
import app from "@/package.json" assert { type: "json" };
const version = appVersion({ prefix: app.name });
await esbuild.build({
entryPoints: ["src/index.ts"],
outdir: `dist/${version}`;
bundle: true,
});Development
To release the package, follow those steps
# generate changelog and provide git version tag
# @see https://github.com/absolute-version/commit-and-tag-version for details
npm run release