diff --git a/core/server/index.js b/core/server/index.js index 9e9928aad8..ebab0734e1 100644 --- a/core/server/index.js +++ b/core/server/index.js @@ -5,7 +5,6 @@ var express = require('express'), hbs = require('express-hbs'), compress = require('compression'), - fs = require('fs'), uuid = require('node-uuid'), Promise = require('bluebird'), i18n = require('./i18n'), @@ -46,49 +45,6 @@ function initDbHashAndFirstRun() { }); } -// Checks for the existence of the "built" javascript files from grunt concat. -// Returns a promise that will be resolved if all files exist or rejected if -// any are missing. -function builtFilesExist() { - var deferreds = [], - location = config.paths.clientAssets, - fileNames = ['ghost.js', 'vendor.js', 'ghost.css', 'vendor.css']; - - if (process.env.NODE_ENV === 'production') { - // Production uses `.min` files - fileNames = fileNames.map(function (file) { - return file.replace('.', '.min.'); - }); - } - - function checkExist(fileName) { - var errorMessage = i18n.t('errors.index.javascriptFilesNotBuilt.error'), - errorHelp = i18n.t('errors.index.javascriptFilesNotBuilt.help', {link: '\nhttps://github.com/TryGhost/Ghost#getting-started'}); - - return new Promise(function (resolve, reject) { - fs.stat(fileName, function (statErr) { - var exists = (statErr) ? false : true, - err; - - if (exists) { - resolve(true); - } else { - err = new Error(errorMessage); - - err.help = errorHelp; - reject(err); - } - }); - }); - } - - fileNames.forEach(function (fileName) { - deferreds.push(checkExist(location + fileName)); - }); - - return Promise.all(deferreds); -} - // ## Initialise Ghost // Sets up the express server instances, runs init on a bunch of stuff, configures views, helpers, routes and more // Finally it returns an instance of GhostServer @@ -108,9 +64,6 @@ function init(options) { // Load our config.js file from the local file system. return config.load(options.config).then(function () { return config.checkDeprecated(); - }).then(function () { - // Make sure javascript files have been built via grunt concat - return builtFilesExist(); }).then(function () { // Initialise the models return models.init(); diff --git a/core/server/translations/en.json b/core/server/translations/en.json index 8da80a8a91..d034ab1169 100644 --- a/core/server/translations/en.json +++ b/core/server/translations/en.json @@ -184,12 +184,6 @@ "help": "Please use the error code above to search for a solution." } }, - "index": { - "javascriptFilesNotBuilt": { - "error": "Javascript files have not been built.", - "help": "\nPlease read the getting started instructions at: {link}" - } - }, "mail": { "incompleteMessageData": { "error": "Error: Incomplete message data." diff --git a/core/server/utils/startup-check.js b/core/server/utils/startup-check.js index 0f7fec0e3d..135c02f406 100644 --- a/core/server/utils/startup-check.js +++ b/core/server/utils/startup-check.js @@ -12,7 +12,8 @@ var packages = require('../../../package.json'), DEPENDENCIES_MISSING: 233, CONTENT_PATH_NOT_ACCESSIBLE: 234, CONTENT_PATH_NOT_WRITABLE: 235, - SQLITE_DB_NOT_WRITABLE: 236 + SQLITE_DB_NOT_WRITABLE: 236, + BUILT_FILES_DO_NOT_EXIST: 237 }; checks = { @@ -23,6 +24,7 @@ checks = { this.contentPath(); this.mail(); this.sqlite(); + this.builtFilesExist(); }, // Make sure the node version is supported @@ -227,6 +229,48 @@ checks = { console.error('\x1B[31mWARNING: Ghost is attempting to use a direct method to send email. \nIt is recommended that you explicitly configure an email service.\033[0m'); console.error('\x1B[32mHelp and documentation can be found at http://support.ghost.org/mail.\033[0m\n'); } + }, + + builtFilesExist: function builtFilesExist() { + var configFile, + config, + location, + fileNames = ['ghost.js', 'vendor.js', 'ghost.css', 'vendor.css']; + + try { + configFile = require(configFilePath); + config = configFile[mode]; + + if (config.paths && config.paths.clientAssets) { + location = config.paths.clientAssets; + } else { + location = path.join(appRoot, '/core/built/assets/'); + } + } catch (e) { + location = path.join(appRoot, '/core/built/assets/'); + } + + if (process.env.NODE_ENV === 'production') { + // Production uses `.min` files + fileNames = fileNames.map(function (file) { + return file.replace('.', '.min.'); + }); + } + + function checkExist(fileName) { + try { + fs.statSync(fileName); + } catch (e) { + console.error('\x1B[31mERROR: Javascript files have not been built.\033[0m'); + console.error('\n\x1B[32mPlease read the getting started instructions at:'); + console.error('https://github.com/TryGhost/Ghost#getting-started\033[0m'); + process.exit(exitCodes.BUILT_FILES_DO_NOT_EXIST); + } + } + + fileNames.forEach(function (fileName) { + checkExist(location + fileName); + }); } };