Coder Social home page Coder Social logo

renke / babel-plugin-git-version Goto Github PK

View Code? Open in Web Editor NEW
8.0 2.0 5.0 9 KB

Expose the current commit's hash and the name of "nearest" tag as constants in your code. Useful to quickly find out what version of your application is deployed.

License: ISC License

JavaScript 100.00%

babel-plugin-git-version's Introduction

babel-plugin-git-version

Expose the current commit's hash and the name of "nearest" tag as constants in your code. Useful to quickly find out what version of your application is deployed.

Installation

npm install --save-dev babel-plugin-git-version

Also make sure that git is in your $PATH.

Usage

Add it to your .babelrc configuration

{
  "plugins": [
    "git-version"
  ]
}

After that the constants GIT_COMMIT and GIT_TAG can be used in your code. They will be replaced by the commit hash of HEAD and the name of the "nearest" tag (or "unknown" if those values can't be parsed).

console.log(`Version: ${GIT_TAG} (${GIT_COMMIT})`);

To avoid eslint warnings just add this to your config

"globals": {
  "GIT_COMMIT": false,
  "GIT_TAG": false,
},

You may customize the plugin to your liking

"plugins": [
  [
    "git-version",
    {
      "commitDefaultValue": "unknown_commit",
      "tagDefaultValue": "unknown_tag",

      "commitConstantName": "COMMIT",
      "tagConstantName": "TAG",

      "showDirty": true,
      "commitLength": 7,
      "tagCommitLength": 7
    }
  ]
]

The defaults are

const DEFAULT_OPTIONS = {
  commitDefaultValue: "unknown",
  tagDefaultValue: "unknown",

  commitConstantName: "GIT_COMMIT",
  tagConstantName: "GIT_TAG",

  showDirty: false,
  
  commitLength: 40,
  tagCommitLength: 0,
};

License

See LICENSE

babel-plugin-git-version's People

Contributors

monder avatar renke avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

babel-plugin-git-version's Issues

Cannot find module 'babel-runtime/helpers/extends'

I installed your package on expo app and got the following error while trying to run the application:

Android Bundling failed 657ms
index.js: [BABEL]: Cannot find module 'babel-runtime/helpers/extends'
Require stack:
- /src/frontend/node_modules/babel-plugin-git-version/lib/index.js
- /src/frontend/node_modules/@babel/core/lib/config/files/module-types.js
- /src/frontend/node_modules/@babel/core/lib/config/files/configuration.js
- /src/frontend/node_modules/@babel/core/lib/config/files/index.js
- /src/frontend/node_modules/@babel/core/lib/index.js
- /src/frontend/node_modules/metro-transform-worker/src/index.js
- /src/frontend/node_modules/metro/src/DeltaBundler/Worker.js
- /src/frontend/node_modules/jest-worker/build/workers/processChild.js (While processing: /src/frontend/node_modules/babel-plugin-git-version/lib/index.js)

I am using:

"babel-plugin-git-version": "^0.2.0",
"@babel/runtime": "^7.16.7",

I realize that this is quite an old project, but I want to make sure if this looks like something is wrong with my setup, or is the project just out of date and no longer supported?

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.