From 6dd753212f1b143f0e6729010ff14b914f1bf576 Mon Sep 17 00:00:00 2001 From: ErisDS Date: Tue, 30 Jul 2013 10:02:38 +0100 Subject: [PATCH] Show message and don't start on unsupported node versions closes #292 - added engines and enginestrict properties to package.json - these provide warnings / errors when installing through npm - added our own check using this info on start, throws a useful error and stops the app if the node version is not supported - also switched sqlite3 to the latest version and checked it works with various node versions --- index.js | 16 +++++++++++++++- package.json | 9 +++++++-- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index c6ae7ee824..950f24ae1e 100644 --- a/index.js +++ b/index.js @@ -5,6 +5,7 @@ var express = require('express'), when = require('when'), _ = require('underscore'), colors = require("colors"), + semver = require("semver"), errors = require('./core/server/errorHandling'), admin = require('./core/server/controllers/admin'), frontend = require('./core/server/controllers/frontend'), @@ -14,6 +15,7 @@ var express = require('express'), I18n = require('./core/shared/lang/i18n'), filters = require('./core/server/filters'), helpers = require('./core/server/helpers'), + packageInfo = require('./package.json'), // ## Custom Middleware auth, @@ -199,7 +201,19 @@ when.all([ghost.init(), filters.loadCoreFilters(ghost), helpers.loadCoreHelpers( ghost.app().listen( ghost.config().env[process.env.NODE_ENV || 'development'].url.port, ghost.config().env[process.env.NODE_ENV || 'development'].url.host, - function() { + function () { + + // Tell users if their node version is not supported, and exit + if (!semver.satisfies(process.versions.node, packageInfo.engines.node)) { + console.log( + "\n !!! INVALID NODE VERSION !!!\n".red, + "Ghost requires node version".red, + packageInfo.engines.node.yellow, + "as defined in package.json\n".red + ); + + process.exit(-1); + } // Remove once software becomes suitably 'ready' console.log( diff --git a/package.json b/package.json index 340549f097..63b7e60348 100644 --- a/package.json +++ b/package.json @@ -6,6 +6,10 @@ "start": "node index", "test": "grunt validate --verbose" }, + "engines": { + "node": ">=0.10.* <0.11.4" + }, + "engineStrict": true, "dependencies": { "express": "3.1.2", "express-hbs": "0.2.0", @@ -15,13 +19,14 @@ "moment": "2.0.0", "underscore": "1.4.4", "showdown": "0.3.1", - "sqlite3": "git+https://github.com/developmentseed/node-sqlite3.git#6ae402e", + "sqlite3": "2.1.14", "bookshelf": "0.1.9", "knex": "0.1.7", "when": "2.1.1", "bcrypt-nodejs": "0.0.3", "node-uuid": "1.4.0", - "colors": "~0.6.0-1" + "colors": "~0.6.0-1", + "semver": "2.1.0" }, "devDependencies": { "grunt": "~0.4.1",