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-package

v0.1.3

Published

Grunt package.json rewriting module.

Downloads

2,168

Readme

grunt-package

by Delta Source

Introduction

This simple library for grunt is intended for rewriting package.json files during your build. The idea is, that you isolate your build directories from your source directory. This way, your source directory will always remain clean.

Example:

  • / (project root).

    This folder might contain the grunt file, but this is not necessary. I consider the grunt file as a source file as well.

    • src/

      Your sources. This folder should contain your source package.json file, as well as all other sources. Typicaly, your package.json file will have dev dependencies here. This is the folder you open in your IDE, and that you commit to git.

    • build/ (created by grunt)

      Your build folder. When you run grunt, your project is built into this folder. Here, you will also find some generated sources, like css files generated from less, html files generated from jade templates, etc.

      This is where you run your tests. You'll notice that some of your normal dev dependencies (like jade, less...) are no longer needed here. You'll only need these in src/. So it's safe to remove those. You'll also want your package.json to have a build timestamp, and maybe the user who performed the build. For traceability.

    • dist/ (created by *grunt release)

      Your release folder. This is a transformation of the build folder, with minimised versions of the sources, some removed folders etc. In the end, this is what you wish to publish to the npm registry. In the package.json file, you may want to remove the private property, and you might want to set a publishConfig.

Why rewriting?

You'll want to process your package.json file as a part of your build, if - for example - you want to change folders or properties. This way, you can manage versions easier, or make sure only a release is publishable to npm, etc.

Some examples:

  • in src/

      {
      	"name": "grunt-package",
      	"description": "Grunt Package Tasks",
      	"version": "0.1.0",
    		
      	"author": {
      		"name": "Delta Source OOD, Bulgaria",
      		"email": "[email protected]",
      		"url": "http://www.deltasource.eu"
      	},
    		
      	"contributors": [
      		"daankets":{
      			"name":"Daan Kets",
      			"email":"[email protected]"
      		}
      	],
    
      	"private": "true",
    
      	"main":"tasks/package.js",
        
          "repository": {
              "type": "git",
              "url": "http://git.deltasource.eu/deltasource/grunt-package.git"
          },
        
          "dependencies": {
              "grunt": "0.4.x"
          },
        
          "devDependencies": {
              "grunt": "latest"
          },
        
          "testDependencies": {
              "nodeunit": "latest"
          }
      }
  • in build/

      {
      	"name": "grunt-package",
      	"description": "Grunt Package Tasks",
      	"version": "0.1.0",
      	"author": {
      		"name": "Delta Source OOD, Bulgaria",
      		"email": "[email protected]",
      		"url": "http://www.deltasource.eu"
      	},			
      	"contributors": [
      		"daankets":{
      			"name":"Daan Kets",
      			"email":"[email protected]"
      		}
      	],
      	"private": "true",
      	"main":"tasks/package.js",                
          "dependencies": {
              "grunt": "0.4.x"
          },
          "devDependencies": {
              "nodeunit": "latest"
          }
      }
  • in dist/

      {
      	"name": "grunt-package",
      	"description": "Delta Source JavaScript Project Tooling",
      	"version": "0.1.0",
      	"author": {
      		"name": "Delta Source OOD, Bulgaria",
      		"email": "[email protected]",
      		"url": "http://www.deltasource.eu"
      	},
      	"contributors": [
      		"daankets":{
      			"name":"Daan Kets",
      			"email":"[email protected]"
      		}
      	],
      	"main":"tasks/package.js",                
      	"dependencies": {
         		"grunt": "0.4.x"
          }
     	}

Configuration

You can configure the package options in the grunt config, with one configuration per 'target'. The following options exist:

  • srcDir : "relativePath/" - The source directory (should contain the source package.json)
  • destDir : "relativePath/" - The destination directory (will contain the target package.json)
  • pretty : true | spaceCount - The source directory (should contain the source package.json)
  • remove : ["propertyName",...] - A list of properties to delete from the package.json file.
  • move : [["propertyNameFrom","propertyNameTo"],...] - A list of property pairs to move within the package.json file.
  • add : {"key":value} An object with keys and values to add within the package.json file.

Example:

  • In your src package.json:

      "devDepenencies":{
      	"grunt-package":"latest"
      }
  • In your gruntfile.js (assuming it's in the src dir, and of course you'll need other build tasks as well...):

      module.exports = function (grunt) {
    
      grunt.initConfig(
      	{
      		sourceDir: "./",
      		buildDir: "../build/",
      		releaseDir: "../dist/",
      		package: {
      			build: {
      				pretty: 4,
      				srcDir: "<%=sourceDir%>",
      				destDir: "<%=buildDir%>",
      				remove: ["devDependencies","repository"],
      				move: [
      					["testDependencies", "devDependencies"]
      				],
      				add: {
      					"build": {
      						"timestamp": new Date(),
      						"user": process.env.USER
      					}
      				}
      			},
      			release: {
      				pretty: false,
      				srcDir: "<%=buildDir%>",
      				destDir: "<%=releaseDir%>",
      				remove: ["devDependencies", "private"]
      			}
      		}
      	}
      );
    
      grunt.loadNpmTasks("grunt-package");
    
      grunt.registerTask("default", ["package:build"]);
    	

Notes

  • The package task will NEVER change your source package.json file. Your destination package.json file MUST be different from the source package.json file.
  • In a multiple-phase setup [build, release...], you'll want to use the output package.json from the previous phase as the input for the next phase.
  • The package task will NOT create directories for you. You'll need to do that yourself. This is part of a security measure in order to avoid mistakes.

License

This library is released under the Create Commons Attribution-ShareAlike 4.0 International License