mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-26 12:21:36 +03:00
05f44c4c64
refs #5923 - add read-themes module to get a list of themes - replace readDirectory() usage with readThemes(), where only themes are needed - test read-themes - test read-directory - test validate-themes - test parse-package-json - add tempfile testing utility to generate temporary paths
47 lines
910 B
JavaScript
47 lines
910 B
JavaScript
/**
|
|
* Dependencies
|
|
*/
|
|
|
|
var readDirectory = require('./read-directory'),
|
|
Promise = require('bluebird'),
|
|
join = require('path').join,
|
|
fs = require('fs'),
|
|
|
|
statFile = Promise.promisify(fs.stat);
|
|
|
|
/**
|
|
* Read themes
|
|
*/
|
|
|
|
function readThemes(dir) {
|
|
var originalTree;
|
|
|
|
return readDirectory(dir)
|
|
.tap(function (tree) {
|
|
originalTree = tree;
|
|
})
|
|
.then(Object.keys)
|
|
.filter(function (file) {
|
|
var path = join(dir, file);
|
|
|
|
return statFile(path).then(function (stat) {
|
|
return stat.isDirectory();
|
|
});
|
|
})
|
|
.then(function (directories) {
|
|
var themes = {};
|
|
|
|
directories.forEach(function (name) {
|
|
themes[name] = originalTree[name];
|
|
});
|
|
|
|
return themes;
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Expose `read-themes`
|
|
*/
|
|
|
|
module.exports = readThemes;
|