Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Remove `.postinstall` before publish, re-add after publish.

Closes gh-36.
  • Loading branch information...
commit 75ce3ba1e261e5b5e6c6b3126d1940cdd3b82c00 1 parent ed7ec82
@paulmillr authored
Showing with 64 additions and 20 deletions.
  1. +18 −9 package.json
  2. +46 −11 setup.js
View
27 package.json
@@ -2,7 +2,13 @@
"name": "chokidar",
"description": "A neat wrapper around node.js fs.watch / fs.watchFile.",
"version": "0.5.1",
- "keywords": ["fs", "watch", "watchFile", "watcher", "file"],
+ "keywords": [
+ "fs",
+ "watch",
+ "watchFile",
+ "watcher",
+ "file"
+ ],
"homepage": "https://github.com/paulmillr/chokidar",
"author": "Paul Miller (http://paulmillr.com)",
"repository": {
@@ -12,18 +18,21 @@
"bugs": {
"url": "http://github.com/paulmillr/chokidar/issues"
},
- "licenses": [{
- "type": "MIT",
- "url": "http://github.com/paulmillr/chokidar/raw/master/README.md"
- }],
+ "licenses": [
+ {
+ "type": "MIT",
+ "url": "http://github.com/paulmillr/chokidar/raw/master/README.md"
+ }
+ ],
"main": "./lib/index",
"engines": {
- "node": "~0.6.10 || 0.7 || 0.8"
+ "node": "~0.6.10 || 0.7 || 0.8 || 0.9"
},
"scripts": {
- "prepublish": "coffee -o lib/ src/",
- "postinstall": "node setup.js postinstall",
- "test": "node setup.js test"
+ "prepublish": "node setup.js prepublish",
+ "postpublish": "node setup.js postpublish",
+ "test": "node setup.js test",
+ "postinstall": "node setup.js test"
},
"dependencies": {},
"devDependencies": {
View
57 setup.js
@@ -2,15 +2,18 @@ var exec = require('child_process').exec;
var sysPath = require('path');
var fs = require('fs');
-// Cross-platform npm postinstall & test script.
+// Cross-platform node.js postinstall & test script for coffeescript projects.
var mode = process.argv[2];
var fsExists = fs.exists || sysPath.exists;
-var execute = function(pathParts, params, callback) {
+var getBinaryPath = function(binary) {
+ return sysPath.join('node_modules', '.bin', binary);
+};
+
+var execute = function(path, params, callback) {
if (callback == null) callback = function() {};
- var path = sysPath.join.apply(null, pathParts);
var command = 'node ' + path + ' ' + params;
console.log('Executing', command);
exec(command, function(error, stdout, stderr) {
@@ -19,12 +22,44 @@ var execute = function(pathParts, params, callback) {
});
};
-if (mode === 'postinstall') {
- fsExists(sysPath.join(__dirname, 'lib'), function(exists) {
- if (exists) return;
- execute(['node_modules', 'coffee-script', 'bin', 'coffee'], '-o lib/ src/');
- });
-} else if (mode === 'test') {
- execute(['node_modules', 'mocha', 'bin', 'mocha'],
- '--compilers coffee:coffee-script --require test/common.js --colors');
+var togglePostinstall = function(add) {
+ var pkg = require('./package.json');
+
+ if (add) {
+ if (!pkg.scripts) pkg.scripts = {};
+ pkg.scripts.postinstall = 'node setup.js test';
+ } else if (pkg.scripts && pkg.scripts.postinstall) {
+ delete pkg.scripts.postinstall;
+ }
+
+ fs.writeFileSync('package.json', JSON.stringify(pkg, null, 2) + '\n');
+};
+
+switch (mode) {
+ // Remove `.postinstall` script to prevent stupid npm bugs.
+ case 'prepublish':
+ togglePostinstall(false);
+ execute(getBinaryPath('coffee'), '-o lib/ src/');
+ break;
+
+ // Bring back `.postinstall` script.
+ case 'postpublish':
+ togglePostinstall(true);
+ break;
+
+ // Compile coffeescript for git users.
+ case 'postinstall':
+ fsExists(sysPath.join(__dirname, 'lib'), function(exists) {
+ if (exists) return;
+ execute(getBinaryPath('coffee'), '-o lib/ src/');
+ });
+ break;
+
+ // Run tests.
+ case 'test':
+ execute(
+ getBinaryPath('mocha'),
+ '--compilers coffee:coffee-script --require test/common.js --colors'
+ );
+ break;
}
Please sign in to comment.
Something went wrong with that request. Please try again.