GithubHelp home page GithubHelp logo

isabella232 / angular-git-info Goto Github PK

View Code? Open in Web Editor NEW

This project forked from w11k/angular-git-info

0.0 0.0 0.0 38 KB

A schematic that adds the git version info to your project

License: MIT License

TypeScript 94.08% JavaScript 5.92%

angular-git-info's Introduction

@w11k/git-info

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 about the topic.

Installation

Add this schematic to your project using the ng add command

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

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:

// IMPORTANT: THIS FILE IS AUTO GENERATED! DO NOT MANUALLY EDIT OR CHECKIN!
/* tslint:disable */
export const VERSION = {
    "dirty": true,
    "raw": "34a0f1d-dirty",
    "hash": "34a0f1d",
    "distance": null,
    "tag": null,
    "semver": null,
    "suffix": "34a0f1d-dirty",
    "semverString": null,
    "version": "0.0.0"
};
/* tslint:enable */

To use the generated VERSION you can simply import it in your Angular Components/Services like so

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-tag=${VERSION.tag}, git-hash=${VERSION.hash}`);
  }
}

Acknowledgement

  • Idea and Code heavily inspired by this blog post
  • Angular schematic implementation heavily inspired by jest-schematic

angular-git-info's People

Contributors

kaihenzler avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.