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

validate-themes.js 1.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. return console.warn("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. return themes;
  14. };
  15. function validateTheme(name, options) {
  16. var fullBackgroundImagePath;
  17. if (!options || !_.keys(options).length) {
  18. return console.warn("Theme '" + name + "' is not defined.");
  19. }
  20. ["width", "height", "framesPerSecond", "samplesPerFrame"].forEach(function(key){
  21. if (typeof options[key] !== "number") {
  22. console.warn("The required property '" + key +"' is missing from theme '" + name + "' or invalid.");
  23. }
  24. });
  25. if (typeof options.backgroundImage === "string") {
  26. fullBackgroundImagePath = options.backgroundImage;
  27. if (!path.isAbsolute(options.backgroundImage)) {
  28. fullBackgroundImagePath = path.join(__dirname, "..", "..", "settings/backgrounds/", options.backgroundImage);
  29. }
  30. try {
  31. fs.accessSync(fullBackgroundImagePath);
  32. } catch(e) {
  33. console.warn("Background image for theme '" + name + "' (" + fullBackgroundImagePath + ") does not exist or is not readable.");
  34. }
  35. }
  36. }