Turn audio into a shareable video. forked from nypublicradio/audiogram

validate-themes.js 1.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. var path = require("path"),
  2. _ = require("underscore"),
  3. fs = require("fs");
  4. module.exports = function(themes) {
  5. if (!themes || !_.keys(_.omit(themes, "default")).length) {
  6. throw new Error("No themes found in settings/themes.json. See https://github.com/nypublicradio/audiogram/blob/master/THEMES.md for details.");
  7. }
  8. for (var key in themes) {
  9. if (key !== "default") {
  10. validateTheme(key, _.extend({}, themes.default || {}, themes[key]));
  11. }
  12. }
  13. };
  14. function validateTheme(name, options) {
  15. var fullBackgroundImagePath;
  16. if (!options || !_.keys(options).length) {
  17. return console.warn("Theme '" + name + "' is not defined.");
  18. }
  19. ["width", "height", "framesPerSecond", "samplesPerFrame"].forEach(function(key){
  20. if (typeof options[key] !== "number") {
  21. console.warn("The required property '" + key +"' is missing from theme '" + name + "' or invalid.");
  22. }
  23. });
  24. if (typeof options.backgroundImage === "string") {
  25. fullBackgroundImagePath = path.join(__dirname, "..", "..", "settings/backgrounds/", options.backgroundImage);
  26. try {
  27. fs.accessSync(fullBackgroundImagePath);
  28. } catch(e) {
  29. console.warn("Background image for theme '" + name + "' (" + fullBackgroundImagePath + ") does not exist or is not readable.");
  30. }
  31. }
  32. }