comments for npm package.json with a grunt.js task
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*jslint node: true */ | |
'use strict'; | |
module.exports = function (grunt) { | |
/* | |
1. make package.json.js and export the json that will be saved as package.json | |
2. run grunt package.json, the new file will be written and you get a patch as well | |
*/ | |
grunt.registerTask('package.json', function () { | |
var fs = require('fs'); | |
var pnew = require('./package.json.js'); | |
var pcurrent = JSON.parse(fs.readFileSync('./package.json')); | |
var x = require('xdiff') | |
var diff = x.diff(pcurrent, pnew); | |
if (diff) { | |
console.log('Writing new package.json with changes:'); | |
console.log(diff); | |
fs.writeFileSync('./package.json', JSON.stringify(pnew, null, ' ')); | |
} else { | |
console.log('No changes.'); | |
} | |
}); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "your-project", | |
"version": "0.0.0", | |
"private": true, | |
"dependencies": {}, | |
"devDependencies": { | |
"xdiff": "^0.2.11", | |
"grunt": "^0.4.5" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
/* | |
You can use any kind of valid javascript comments in this file. | |
- marko | |
ps: you could also use this script to dynamicaly create a package.js | |
*/ | |
module.exports = { | |
"name": "your-project", | |
"version": "0.0.0", | |
"private": true, | |
"dependencies": { | |
// place your project dependencies here | |
}, | |
"devDependencies": { | |
// comments are execial to quickly assert the state of a dependency | |
"xdiff": "^0.2.11", | |
// we still need grunt | |
"grunt": "^0.4.5" | |
} | |
}; |
sorry, missed your comment.
simple, you destribute the script with the package.json prebuild, its just a build script anyway
Interesting idea. But what do you do when you install a new package with eg. --save-dev
and your package.json is updated directly?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
how do you ensure the very first run? Means how do you pull grunt itself since the package.json is missing?