Git Product home page Git Product logo

ver's Introduction

ver

This module generates a ver.ts with as version from the latest git tag for you to use in code.

What?

In node.js there is een idiomatic way of storing the version of whichever program you're building which is the package.json.

In Deno the versions are managed by git tags, which is better, because you manage the version of your software in a more abstract way: using git, and not npm. npm is more locked-in to a technology. (git is also a technology but if you're not using that then I don't know what to say).

This presents a problem though:

The .git directory (where the tags are stored) is not available in production code (or at least shouldn't be) but it's a pretty common approach in node.js to parse the package.json and use the version found there to display in your app. For example, an api could return it's version in a header, and a cli wants to display the version in it's --help.

There is a Deno module that solves this problem with a rich feature set, including a cli which does the git tagging. Check it out here: https://deno.land/x/version_ts

While the above solution is excellent, I wanted a super simple version of this. Not requiring a cli to be installed but just generating a single .ts file for you to use based on the latest git tag.

How?

In the startup of your app, put

await ensureVersion();

This will generate a ver.ts file in the cwd of your project. ensureVersion will make just that file always contains the latest version from your git tag list.

Whenever you need the current version, you can import the ver.ts or use

await getVersion();

anywhere in your application to get the sematic version.

Note that using getVersion is better because it lazy loads (with await import) the ver.ts

ver's People

Contributors

gerbenrampaart avatar

Watchers

 avatar  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.