Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"dev": "babel-node src",
"lint": "eslint src tests",
"pretest": "npm run -s build",
"postinstall": "node lib/lib/check-engine.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",
Expand Down Expand Up @@ -115,8 +116,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",
Expand Down
3 changes: 3 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 './lib/check-engine';

global.Promise = require('promise-polyfill');

checkVersion();

installHooks();

yargs
Expand Down
30 changes: 30 additions & 0 deletions src/lib/check-engine.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { execSync } from "child_process";

import semver from "semver";
import colors from "chalk";
import pkg from "./../../package.json";

const platformSuffix = process.platform === "win32" ? ".cmd" : "";
const node = "node" + platformSuffix;

export default function checkVersion() {
const requirements = pkg.engines;
const nodeVersion = execSync(node + " --version").toString() || '';

if ( !(semver.satisfies(nodeVersion, requirements.node)) ) {
const errorMessage = colors.yellow(
"\n⚠️ " +
"preact-cli requires at least " +
"node@" +
requirements.node +
"\n\n" +
"Your node version is " +
nodeVersion +
"\n"
);
process.stdout.write(errorMessage) + '\n';
process.exit(1);
}

return true;
}