all files / lib/collection/type/ static.js

98.39% Statements 61/62
100% Branches 12/12
100% Functions 8/8
92.86% Lines 13/14
2 statements, 2 branches Ignored     
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           17×         16×               16×                                  
import Promise from 'bluebird';
import fs from 'fs-extra';
Promise.promisifyAll(fs);
import path from 'path';
import isUndefined from 'lodash/isUndefined';
 
import log from '../../log';
import CollectionBase from '../base';
 
export default class StaticCollection extends CollectionBase {
  constructor(name, collectionConfig, getConfig) {
    super(name, collectionConfig, getConfig);
 
    if (!isUndefined(collectionConfig.path)) {
      /**
       * If this is a static collection calculate its destination path.
       * @type {string}
       */
      this.staticDestination = path.resolve(
        this._getConfig().get('path.destination'),
        collectionConfig.path
      );
    }
  }
 
  populate() {
    return this;
  }
 
  /**
   * Writes both files and pages that are in this collection.
   * @return {Promise}
   */
  async write() {
    let promise;
    try {
      promise = await fs.copyAsync(this.path, this.staticDestination);
    } catch (e) {
      log.warn(`Could not copy StaticCollection '${this.path}'.`);
    }
 
    return promise;
  }
}