All files / ember-web-app/lib/manifest index.js

0% Statements 0/26
0% Branches 0/6
0% Functions 0/13
0% Lines 0/26

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62                                                                                                                           
'use strict';
const validate = require('web-app-manifest-validator');
const BaseManifest = require('../base-manifest');
const hasTarget = require('../utils/has-target');
 
module.exports = class Manifest extends BaseManifest {
  static get name() {
    return 'manifest.webmanifest';
  }
 
  static get selector() {
    return 'link[rel="manifest"]';
  }
 
  static get tag() {
    return '<link rel="manifest" href="{{rootURL}}manifest.webmanifest">';
  }
 
  constructor(app, { ui }) {
    super(app, { name: Manifest.name, selector: Manifest.selector });
    this.ui = ui;
  }
 
  generate() {
    let manifest = {};
 
    this.copy(manifest, this.configuration);
    this.validate(manifest);
 
    let content = JSON.stringify(manifest);
    return `${content}\n`;
  }
 
  copy(manifest, configuration) {
    Object.keys(configuration)
      .filter(key => key !== 'apple' && key !== 'ms')
      .forEach(key => {
        if (key === 'icons') {
          this.icons(manifest, configuration);
        } else {
          manifest[key] = configuration[key];
        }
      });
  }
 
  icons(manifest, configuration) {
    manifest.icons = configuration.icons
      .filter(icon => !icon.targets || hasTarget(icon, 'manifest'))
      .map(icon => {
        let copy = Object.assign({}, icon);
        delete copy.targets;
        return copy;
      });
  }
 
  validate(manifest) {
    validate(manifest).forEach(error =>
      this.ui.writeWarnLine(`${this.name} validation: ${error}`)
    );
  }
};