mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-24 11:22:19 +03:00
7abcc43907
closes #5617 - Replace all hard-coded server-side strings with i18n translations
56 lines
1.5 KiB
JavaScript
56 lines
1.5 KiB
JavaScript
/**
|
|
* Dependencies
|
|
*/
|
|
|
|
var Promise = require('bluebird'),
|
|
fs = require('fs'),
|
|
i18n = require('../i18n'),
|
|
|
|
readFile = Promise.promisify(fs.readFile);
|
|
|
|
/**
|
|
* Parse package.json and validate it has
|
|
* all the required fields
|
|
*/
|
|
|
|
function parsePackageJson(path) {
|
|
return readFile(path)
|
|
.catch(function () {
|
|
var err = new Error(i18n.t('errors.utils.parsepackagejson.couldNotReadPackage'));
|
|
err.context = path;
|
|
|
|
return Promise.reject(err);
|
|
})
|
|
.then(function (source) {
|
|
var hasRequiredKeys, json, err;
|
|
|
|
try {
|
|
json = JSON.parse(source);
|
|
|
|
hasRequiredKeys = json.name && json.version;
|
|
|
|
if (!hasRequiredKeys) {
|
|
err = new Error(i18n.t('errors.utils.parsepackagejson.nameOrVersionMissing'));
|
|
err.context = path;
|
|
err.help = i18n.t('errors.utils.parsepackagejson.willBeRequired', {url: 'http://docs.ghost.org/themes/'});
|
|
|
|
return Promise.reject(err);
|
|
}
|
|
|
|
return json;
|
|
} catch (parseError) {
|
|
err = new Error(i18n.t('errors.utils.parsepackagejson.themeFileIsMalformed'));
|
|
err.context = path;
|
|
err.help = i18n.t('errors.utils.parsepackagejson.willBeRequired', {url: 'http://docs.ghost.org/themes/'});
|
|
|
|
return Promise.reject(err);
|
|
}
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Expose `parsePackageJson`
|
|
*/
|
|
|
|
module.exports = parsePackageJson;
|