mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-06 22:40:14 -05:00
Moves builFilesExist to startup-checks
Fixes #6493 * moved function to startup checks * flipped file system checks to sync versions * exits on first sign of trouble
This commit is contained in:
parent
21c272b03f
commit
7691b03d5a
3 changed files with 45 additions and 54 deletions
|
@ -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();
|
||||
|
|
|
@ -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."
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue