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-wwwouaiebe-buildnumber

v1.0.2

Published

Grunt plugin - read values from a json file and set to grunt.config.data or change the values in the json file, so values can be used with grunt

Downloads

1

Readme

Grunt-wwwouaiebe-BuildNumber

Yet another build number plugin for grunt...

  • Read properties from a json file, transform the properties with a given function and add these properties to the grunt.config.data object
  • Read properties from a json file, transform the properties with a given function and write these properties to the json file

What to do in your Gruntfile.js

In your Gruntfile.js, add a section named buildnumber to the data object passed into grunt.initConfig():

grunt.initConfig ( {
    buildnumber : {
        options : {
            file : 'buildNumber.json'
        },
        start : {
            action : 'read',
            values : [
                {
                    name : 'build',
                    initialValue : 0,
                    transform : value => String ( value ).padStart ( 5, '0' )
                }
            ]
        },
        end : {
            action : 'write',
            values : [
                {
                    name : 'build',
                    initialValue : 0,
                    transform : value => value + 1
                }
            ]
        }
    }
}

You have also to load the plugin:

grunt.loadNpmTasks('grunt-wwwouaiebe-buildnumber');

And finally, register a task:

grunt.registerTask( 'a_task', [ 'buildnumber:start' ] );

or

grunt.registerTask( 'another_task', [ 'buildnumber:end' ] );

About the config

In the options, you precise the file used ( in the sample, buildNumber.json ).

You can have multiple configurations ( in the sample, start and end ).

In each configuration, you precise witch action must be executed ( must be 'read' or 'write').

Then you add an array of objects that are the properties to read or write to the json file ( the values in the sample ).

For each property :

  • the name is the the property name to read or write in the json file. Never use buildnumber for this property name, that's the task name and the property will be ignored!
  • the initialValue is the value to use when the property is not found in the json file
  • transform is an optional function used to modify the property before writing the property in the grunt.config.data ( when the action is 'read' - in the sample, the numeric property is transformed into a string and completed with 0 on the left ) or before writing the property in the json file ( when the action is 'write' - in the sample the property is simply incremented )

Notice that the properties are added in the grunt.config.data object, so you can easily use the properties in grunt templates or read the properties with the grunt.config.get method