npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

grunt-version-file

v0.2.2

Published

Writes code provenance information to a JSON file for deployment alongside the application

Downloads

257

Readme

grunt-version-file

NPM version Build Status Coverage Status Dependency status Dev Dependency Status Built with Grunt

NPM

Writes code provenance information to a JSON file for deployment alongside the application

Knowing exactly which version of the application has been deployed is crucial for debugging, but it is difficult without careful record keeping. One solution to this problem is to automatically generate a file with code provenance information that is deployed alongside the application. This plugin does that.

An example version file:

{
  "datestring": "Sun Oct 12 2014 13:21:08",
  "npm_version": "1.0.1",
  "git_describe": "v0.1.4-0-g8209160"
}

Getting Started

This plugin requires Grunt ~0.4.4

If you haven't used Grunt before, be sure to check out the Getting Started guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:

npm install grunt-version-file --save-dev

Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:

grunt.loadNpmTasks('grunt-version-file');

The "version_file" task

Overview and Usage

In your project's Gruntfile, add a section named version_file to the data object passed into grunt.initConfig().

grunt.initConfig({
    version_file: {
      make: {
        options: {
          out: ["some/file/path.json"],
          generator_list: ["foo", "bar"],
          generator_dir: "some_directory_in_grunt_version_file"
        }
      }
    }
});

Options

options.out

  • Type: String
  • Purpose: Output file path to write to
  • Default value: None, required

options.generator_list

  • Type: Array of ``String`
  • Purpose: Specify the list of version file value generators to use
  • Default value: ["datestring", "npm_version", "git_describe"]

options.generator_dir

  • Type: String
  • Purpose: Specify the path to the directory with value generator definitions
  • Default value: "generators"

Generators

grunt-version-file uses a plugin architecture to generate key value-entries for code provenance. It is deployed wih several generators and you can easily create your own. Please make a pull request if you do!

A generator plugin is made available to the grunt-version-file plugin via a javascript file which exports an object with a label function, a value function and (optionally) an init function. These functions must operate synchronously and must wait for any asynchronous operations to complete before returning to their caller.

The label_value function an object containing a label field with the String label for this generator and a value field containing the (possibly build-specific) String value of this generator's field for the version file.

The init function is executed before the value or label function are called.

A generator's name in the generator_list option is the filename without the .js extension. It is recommended that this is the same as the generator's label, but it is not required.

Contributing

In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using Grunt.

Adding generators

To add a generator create a new file in the lib/generators directory which exports an object with a label, value and optionally an init function. See the included generators for examples.

Code smells and future development

The following could be better, code contributions welcome :)

  • The tests don't use mock objects for GVF classes, they should
  • Stub functions are used in tests in place of Grunt's Task.done() or a mock
  • The generator init functions are not executed at construction and initialisation but just before label_value is called
  • Further generalise output_creator (e.g. add XmlCreator), specify which to use via the Gruntfile configuration

Changelog

  • 0.1.0 - Initial release
  • 0.1.1 - Readme fixes and Travis CI
  • 0.2.0 - Async generators, generalised output creator API for easy generation of other output formats
  • 0.2.1 - Bug fix - added missing q dependency
  • 0.2.2 - Dev dependency update

License

Copyright (c) 2014 Christo Fogelberg

Licensed under the MIT License