diff --git a/check.js b/check.js new file mode 100644 index 000000000..29d8a96ec --- /dev/null +++ b/check.js @@ -0,0 +1,22 @@ +const colors = require('chalk'); +const pkg = require('./package.json'); + +const version = parseFloat( process.version.substr(1) ); +const minimum = parseFloat( pkg.engines.node.match(/\d+/g).join('.') ); + +module.exports = function () { + if (version >= minimum) { + return true; + } + + const errorMessage = colors.yellow(` + + ⚠️ preact-cli requires at least node@${minimum}! + You have node@${version} + + `); + + // version not supported && exit + process.stdout.write(errorMessage) + '\n'; + process.exit(1); +}; diff --git a/package.json b/package.json index c9ef93728..14bb654b3 100644 --- a/package.json +++ b/package.json @@ -13,6 +13,7 @@ "dev": "babel-node src", "lint": "eslint src tests", "pretest": "npm run -s build", + "postinstall": "node check.js", "test": "tape -r babel-register tests/*.test.js | tap-diff", "test:build": "babel-node src build --cwd examples/root", "test:serve": "npm run -s test:build && babel-node src serve --port 3000 --cwd examples/root", @@ -27,7 +28,8 @@ }, "files": [ "lib", - "examples" + "examples", + "check.js" ], "keywords": [ "preact", @@ -115,8 +117,8 @@ "es6-promisify": "^5.0.0", "file-loader": "^0.11.1", "fs.promised": "^3.0.0", - "html-webpack-plugin": "^2.28.0", "html-webpack-exclude-assets-plugin": "0.0.5", + "html-webpack-plugin": "^2.28.0", "isomorphic-unfetch": "^2.0.0", "json-loader": "^0.5.4", "less": "^2.7.2", diff --git a/src/index.js b/src/index.js index 1c6a6e34d..90215215c 100644 --- a/src/index.js +++ b/src/index.js @@ -8,9 +8,12 @@ import serve from './commands/serve'; import installHooks from './lib/output-hooks'; import pkg from '../package.json'; import logo from './lib/logo'; +import checkVersion from './../check'; global.Promise = require('promise-polyfill'); +checkVersion(); + installHooks(); yargs