# @angcap/git-info

> creates a version file to display git info in your angular app

Latest version **1.1.2** (published 2022-11-02) · MIT license · 0 weekly downloads

## Install

```sh
npm install @angcap/git-info
pnpm add @angcap/git-info
yarn add @angcap/git-info
bun add @angcap/git-info
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.2 |
| Published | 2022-11-02 |
| First published | 2020-11-17 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 4 |
| Unpacked size | 34.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Angelo Capone |
| Maintainers | angcap |
| Keywords | schematics, angular |

## Links

- npm: https://www.npmjs.com/package/@angcap/git-info
- Repository: https://github.com/angcap/angular-git-info
- Homepage: https://github.com/angcap/angular-git-info#readme
- Issues: https://github.com/angcap/angular-git-info/issues
- npm.io page: https://npm.io/package/@angcap/git-info

## Dependencies (4)

- [typescript](https://npm.io/package/typescript.md) ~3.8.2
- [@angular-devkit/core](https://npm.io/package/@angular-devkit/core.md) ^10.0.6
- [@angular-devkit/schematics](https://npm.io/package/@angular-devkit/schematics.md) ^10.0.6
- [@angular-devkit/schematics-cli](https://npm.io/package/@angular-devkit/schematics-cli.md) ^12.2.17

## Alternatives

- [@regle/core](https://npm.io/package/@regle/core.md) — 47.0K weekly downloads
- [typeof-arguments](https://npm.io/package/typeof-arguments.md) — 12.5K weekly downloads
- [@lokalise/projects-engine-contracts](https://npm.io/package/@lokalise/projects-engine-contracts.md) — 978 weekly downloads
- [@osjwnpm/nam-laboriosam-quibusdam](https://npm.io/package/@osjwnpm/nam-laboriosam-quibusdam.md) — 70 weekly downloads
- [@oridune/validator](https://npm.io/package/@oridune/validator.md) — 16 weekly downloads

## Recent versions

- 1.1.2 (latest) — 2022-11-02
- 1.1.0 — 2020-12-02
- 1.0.2 — 2020-11-17
- 1.0.1 — 2020-11-17

## README

# Description

This tool is a fork of *@w11k/git-info*, it uses `git-last-commit` instead of `git-describe` in order to expose a richer set of
information from the git repo.

This schematic fro the angular-cli let's you easily setup a workflow that allows you to access the git-information in your Angular App.
Read our detailed [blog post](https://www.thecodecampus.de/blog/display-the-version-and-git-hash-in-angular) about the topic.

## Installation

Add this schematic to your project using the `ng add` command
```bash
ng add @w11k/git-info
```

This will setup everything you need. We will automatically
- add required devDependencies to your `package.json`
- add a script `git-version.js` in the same folder where your `package.json` ist
- add a npm `postinstall`-hook to the `scipts` section of your `package.json`
- add the automatically generated file to the `.gitignore`

## Customization

By default the schematic hooks into the `postinstall`-hook that is triggered after `npm install` has finished. 
Typically you would execute a fresh `npm install` on your build server whenever you deploy a new version of your app.
If you however don't do a fresh install every time due to caching for example you can call the postinstall hook manually via 
```bash
npm run postinstall
```
or use another hook like `prebuild` or no hook at all, but just a regular script in the `scripts` section of the `package.json`  

## Usage

After each `npm install` we trigger the npm-hook to update the automatically generated file `environments/version.ts`
This is a normal Typescript file that simply exports a constant. It is very important that this file in not committed to the git-repo.
The file looks similar to this:


```typescript
// IMPORTANT: THIS FILE IS AUTO GENERATED! DO NOT MANUALLY EDIT OR CHECKIN!
/* tslint:disable */
export const VERSION = {
    "shortHash": "fdfdb21",
    "hash": "fdfdb211e2c95fd4fc5159f2194e34d8b3438f50",
    "subject": "switch from git-describe to git-last-commit",
    "sanitizedSubject": "switch-from-git-describe-to-git-last-commit",
    "body": "",
    "authoredOn": "2020-11-17T07:00:56.000Z",
    "committedOn": "2020-11-17T07:00:56.000Z",
    "author": {
        "name": "Angelo Capone",
        "email": "capone.angelo@gmail.com"
    },
    "committer": {
        "name": "Angelo Capone",
        "email": "capone.angelo@gmail.com"
    },
    "notes": "",
    "branch": "master",
    "tags": [],
    "version": "1.0.0"
};
/* tslint:enable */
```

To use the generated VERSION you can simply import it in your Angular Components/Services like so
```typescript
import { Component } from '@angular/core';
import { VERSION } from '../environments/version';  

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  title = 'app';
  
  constructor() {
    console.log(`Application version is: version (from package.json)=${VERSION.version}, git-branch=${VERSION.branch}, git-hash=${VERSION.shortHash}`);
  }
}
```

### Automatically bump the version number
To update the version number every time your CI/CD publishes an update to production use
``` bash 
npm version patch
```

## Acknowledgement
- Idea and Code heavily inspired by this [blog post](https://medium.com/@amcdnl/version-stamping-your-app-with-the-angular-cli-d563284bb94d)
- Angular schematic implementation heavily inspired by [jest-schematic](https://github.com/briebug/jest-schematic)

---
_Source: https://npm.io/package/@angcap/git-info · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
