diff --git a/.gitignore b/.gitignore index 793da69..106df38 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ npm-debug.log gyp-mac-tool .node_pre_gyprc /.idea +.pre-publish-info diff --git a/bin/pre-publish.js b/bin/pre-publish.js new file mode 100755 index 0000000..849214a --- /dev/null +++ b/bin/pre-publish.js @@ -0,0 +1,30 @@ +#!/usr/bin/env node +'use strict'; +var spawnSync = require('child_process').spawnSync; +var fs = require('fs'); +var semver = require('semver'); + +// Log the packaging environment to be included in the npm bundle +var lsExit = spawnSync('npm', ['ls']).status; +var npmVersion = spawnSync('npm', ['-v']).stdout.toString().trim(); + +var info = { + 'versions': process.versions, + 'platform': process.platform, + 'arch': process.arch, + 'npm ls exit code': lsExit, + 'npm version': npmVersion +}; + +fs.writeFileSync('.pre-publish-info', JSON.stringify(info, null, 2) + '\n'); + +if (lsExit !== 0) { + console.error('ls exited with a', lsExit); + process.exit(1); +} + +// if (!semver.gt(npmVersion, '3.0.0') && !process.env.CI) { +// console.log('npm version must be above 3.0.0 <', npmVersion); +// process.exit(1); +// } + diff --git a/package.json b/package.json index 38eda45..f74dee1 100644 --- a/package.json +++ b/package.json @@ -72,10 +72,11 @@ "mocha": "^2.4.5", "node-pre-gyp-github": "^1.1.2", "sandboxed-module": "^2.0.3", + "semver": "^5.1.0", "sinon": "^1.17.3", "sinon-chai": "^2.8.0" }, - "bundledDependencies":[ + "bundledDependencies": [ "node-pre-gyp" ], "engines": { @@ -92,7 +93,8 @@ "gyp-rebuild": "node-gyp rebuild", "stress": "mocha --no-timeouts test/arduinoTest/stress.js", "grunt": "grunt", - "test": "grunt --verbose" + "test": "grunt --verbose", + "prepublish": "node bin/pre-publish.js" }, "gypfile": true }