0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-10 23:36:14 -05:00
ghost/core/server/lib/fs/package-json/parse.js
kirrg001 132df78940 Updated docs links
refs #9742

- Ghost 2.0 is coming
- all doc links in 1.0 must use concrete links e.g. docs.ghost.org/v1 or themes.ghost.org/v1.23.0/
- if we release Ghost 2.0, docs.ghost.org will show 2.0 docs
2018-07-20 23:49:16 +02:00

53 lines
1.5 KiB
JavaScript

/**
* Dependencies
*/
var Promise = require('bluebird'),
fs = require('fs-extra'),
common = require('../../common');
/**
* Parse package.json and validate it has
* all the required fields
*/
function parsePackageJson(path) {
return fs.readFile(path)
.catch(function () {
var err = new Error(common.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(common.i18n.t('errors.utils.parsepackagejson.nameOrVersionMissing'));
err.context = path;
err.help = common.i18n.t('errors.utils.parsepackagejson.willBeRequired', {url: 'http://themes.ghost.org/v1.23.0/'});
return Promise.reject(err);
}
return json;
} catch (parseError) {
err = new Error(common.i18n.t('errors.utils.parsepackagejson.themeFileIsMalformed'));
err.context = path;
err.help = common.i18n.t('errors.utils.parsepackagejson.willBeRequired', {url: 'http://themes.ghost.org/v1.23.0/'});
return Promise.reject(err);
}
});
}
/**
* Expose `parsePackageJson`
*/
module.exports = parsePackageJson;