All files resolver.js

100% Statements 19/19
100% Branches 8/8
100% Functions 4/4
100% Lines 19/19
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    1x 1x 1x   1x 7x   7x 4x             3x 2x   2x 2x 1x 1x       2x 1x     1x   1x     2x             1x        
'use strict';
 
var path = require("path");
var join = path.join;
var Promise = require("es6-promise").Promise;
 
module.exports = function resolve(pathOrFiles) {
  return new Promise(function(resolve, reject){
    // legacy and original mode
    if (typeof pathOrFiles === 'string') {
      return resolve({
        path: pathOrFiles,
        src: '**',
      });
    }
 
    // new mode, with a list of files
    else if (Array.isArray(pathOrFiles)) {
      var manifestFile = '';
 
      pathOrFiles.some(function(f){
        if (/(^|\/)manifest.json$/.test(f)) {
          manifestFile = f;
          return true;
        }
      });
 
      if (!manifestFile) {
        return reject(new Error('Unable to locate a manifest file in your list of files.'))
      }
 
      var manifestDir = path.dirname(manifestFile);
 
      return resolve({
        path: path.resolve(manifestDir),
        src: '{' + pathOrFiles.map(function(f){
          return path.relative(manifestDir, f);
        }).join(',') + '}'
      })
    }
 
    //
    else {
      reject(new Error('load path is none of a folder location nor a list of files to pack'))
    }
  });
}