mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-13 22:41:32 -05:00
20fec74c73
closes #5492 - remove core/server/require-tree.js and split it into modules - add read-directory module to recursively read directories - add validate-themes module to scan themes and return errors/warnings - add parse-package-json module to parse json and validate requirements - rewrite core/server/models/index.js to manually require models
54 lines
1.4 KiB
JavaScript
54 lines
1.4 KiB
JavaScript
/**
|
|
* Dependencies
|
|
*/
|
|
|
|
var Promise = require('bluebird'),
|
|
fs = require('fs'),
|
|
|
|
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('Could not read package.json file');
|
|
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('"name" or "version" is missing from theme package.json file.');
|
|
err.context = path;
|
|
err.help = 'This will be required in future. Please see http://docs.ghost.org/themes/';
|
|
|
|
return Promise.reject(err);
|
|
}
|
|
|
|
return json;
|
|
} catch (_) {
|
|
err = new Error('Theme package.json file is malformed');
|
|
err.context = path;
|
|
err.help = 'This will be required in future. Please see http://docs.ghost.org/themes/';
|
|
|
|
return Promise.reject(err);
|
|
}
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Expose `parsePackageJson`
|
|
*/
|
|
|
|
module.exports = parsePackageJson;
|