Skip to content

Commit

Permalink
Show message and don't start if javascript files have not been built
Browse files Browse the repository at this point in the history
fixes TryGhost#1782
- added builtFilesExist function to check for files during startup.
  If built files do not exist Ghost startup is stopped and a link
  to the documentation is displayed.
- exported a scriptFiles object from server/helpers.
- added a builtScriptPath to the paths module.
- removed "js-msg" about missing javascript from the UI.
  • Loading branch information
jaswilli committed Jan 15, 2014
1 parent c82d2ea commit d7c3dbb
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 28 deletions.
3 changes: 0 additions & 3 deletions core/client/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,6 @@
};

Ghost.init = function () {
// remove the temporary message which appears
$('.js-msg').remove();

Ghost.router = new Ghost.Router();

// This is needed so Backbone recognizes elements already rendered server side
Expand Down
3 changes: 2 additions & 1 deletion core/server/config/paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ function paths() {
'lang': path.join(corePath, '/shared/lang/'),
'debugPath': subdir + '/ghost/debug/',
'availableThemes': availableThemes,
'availablePlugins': availablePlugins
'availablePlugins': availablePlugins,
'builtScriptPath': path.join(corePath, 'built/scripts/')
};
}

Expand Down
34 changes: 17 additions & 17 deletions core/server/helpers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,20 @@ var downsize = require('downsize'),
isProduction = process.env.NODE_ENV === 'production',

coreHelpers = {},
registerHelpers;

registerHelpers,

scriptFiles = {
production: [
'ghost.min.js'
],
development: [
'vendor.js',
'helpers.js',
'templates.js',
'models.js',
'views.js'
]
};

/**
* [ description]
Expand Down Expand Up @@ -262,28 +273,16 @@ coreHelpers.fileStorage = function (context, options) {
};

coreHelpers.ghostScriptTags = function () {
var scriptFiles = [];

if (isProduction) {
scriptFiles.push("ghost.min.js");
} else {
scriptFiles = [
'vendor.js',
'helpers.js',
'templates.js',
'models.js',
'views.js'
];
}
var scriptList = isProduction ? scriptFiles.production : scriptFiles.development;

scriptFiles = _.map(scriptFiles, function (fileName) {
scriptList = _.map(scriptList, function (fileName) {
return scriptTemplate({
source: config.paths().subdir + '/ghost/scripts/' + fileName,
version: coreHelpers.assetHash
});
});

return scriptFiles.join('');
return scriptList.join('');
};

/*
Expand Down Expand Up @@ -677,3 +676,4 @@ module.exports = coreHelpers;
module.exports.loadCoreHelpers = registerHelpers;
module.exports.registerThemeHelper = registerThemeHelper;
module.exports.registerAsyncThemeHelper = registerAsyncThemeHelper;
module.exports.scriptFiles = scriptFiles;
42 changes: 41 additions & 1 deletion core/server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,43 @@ 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().builtScriptPath,

fileNames = process.env.NODE_ENV === 'production' ?
helpers.scriptFiles.production : helpers.scriptFiles.development;

function checkExist(fileName) {
var deferred = when.defer(),
errorMessage = "Javascript files have not been built.",
errorHelp = "\nPlease read the getting started instructions at:" +
"\nhttps://github.com/TryGhost/Ghost#getting-started-guide-for-developers";

fs.exists(fileName, function (exists) {
if (exists) {
deferred.resolve(true);
} else {
var err = new Error(errorMessage);

err.help = errorHelp;
deferred.reject(err);
}
});

return deferred.promise;
}

fileNames.forEach(function (fileName) {
deferreds.push(checkExist(location + fileName));
});

return when.all(deferreds);
}

// Sets up the express server instance.
// Instantiates the ghost singleton,
// helpers, routes, middleware, and plugins.
Expand Down Expand Up @@ -106,6 +143,9 @@ function setup(server) {
// Initialize the permissions actions and objects
permissions.init()
);
}).then(function () {
// Make sure javascript files have been built via grunt concat
return builtFilesExist();
}).then(function () {
// Initialize mail
return mailer.init();
Expand Down Expand Up @@ -230,7 +270,7 @@ function setup(server) {

});
}, function (err) {
errors.logErrorAndExit(err);
errors.logErrorAndExit(err, err.context, err.help);
});
}

Expand Down
5 changes: 0 additions & 5 deletions core/server/views/default.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,6 @@
</aside>

{{{body}}}

<div class="js-msg">
<p>Hello There! Looks like something went wrong with your JavaScript.</p>
<p>Either you need to enable JavaScript, or you haven't built the JavaScript files yet. See the README and CONTRIBUTING files for more info.</p>
</div>
</main>

<div id="modal-container">
Expand Down
3 changes: 2 additions & 1 deletion core/test/unit/config_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,8 @@ describe('Config', function () {
'lang',
'debugPath',
'availableThemes',
'availablePlugins'
'availablePlugins',
'builtScriptPath'
);
});

Expand Down

0 comments on commit d7c3dbb

Please sign in to comment.