lib/clientlib.js
function normalizeAssets(clientLibPath, assets) {

  var list = assets;

  // transform object to array
  if (!_.isArray(assets)) {
    list = [];
    _.keys(assets).forEach(function (assetKey) {
      var assetItem = assets[assetKey];

      // check/transform short version
      if (_.isArray(assetItem)) {
        assetItem = {
          files: assetItem
        };
      }
      if (!assetItem.base) {
        assetItem.base = assetKey;
      }
      assetItem.type = assetKey;
      list.push(assetItem);
    });
  }

  // transform files to scr-dest mapping
  list.forEach(function (asset) {

    var mapping = [];
    var flatName = typeof asset.flatten !== "boolean" ? true : asset.flatten;
    var assetPath = path.posix.join(clientLibPath, asset.base);
    var globOptions = {};
    if (asset.cwd) {
      globOptions.cwd = asset.cwd;
    }

    asset.files.forEach(function (file) {
      var fileItem = file;

      // convert simple syntax to object
      if (_.isString(file)) {
        fileItem = {
          src: file
        };
      }

      // no magic pattern -> default behaviour
      if (!glob.hasMagic(fileItem.src)) {

        // determine default dest
        if (!fileItem.dest) {
          fileItem.dest = path.posix.basename(file);
        }

        // generate full path
        fileItem.dest = path.posix.join(assetPath, fileItem.dest);
        mapping.push(fileItem);
      }

      // resolve magic pattern
      else {
        var files = glob.sync(fileItem.src, globOptions);
        var hasCwd = !!globOptions.cwd;
        var dest = fileItem.dest ? path.posix.join(assetPath, fileItem.dest) : assetPath;

        files.forEach(function (resolvedFile) {

          // check 'flatten' option -> strip dir name
          var destFile = flatName ? path.posix.basename(resolvedFile) : resolvedFile;

          var item = {
            src: resolvedFile,
            dest: path.posix.join(dest, destFile)
          };

          // check "cwd" option -> rebuild path, because it was stripped by glob.sync()
          if (hasCwd) {
            item.src = path.posix.join(globOptions.cwd, resolvedFile);
          }

          mapping.push(item);
        });
      }
    });

    asset.files = mapping;
  });

  return list;
}
function normalizeAssets(clientLibPath, assets) {

  var list = assets;

  // transform object to array
  if (!_.isArray(assets)) {
    list = [];
    _.keys(assets).forEach(function (assetKey) {
      var assetItem = assets[assetKey];

      // check/transform short version
      if (_.isArray(assetItem)) {
        assetItem = {
          files: assetItem
        };
      }
      if (!assetItem.base) {
        assetItem.base = assetKey;
      }
      assetItem.type = assetKey;
      list.push(assetItem);
    });
  }

  // transform files to scr-dest mapping
  list.forEach(function (asset) {

    var mapping = [];
    var flatName = typeof asset.flatten !== "boolean" ? true : asset.flatten;
    var assetPath = path.posix.join(clientLibPath, asset.base);
    var globOptions = {};
    if (asset.cwd) {
      globOptions.cwd = asset.cwd;
    }

    asset.files.forEach(function (file) {
      var fileItem = file;

      // convert simple syntax to object
      if (_.isString(file)) {
        fileItem = {
          src: file
        };
      }

      // no magic pattern -> default behaviour
      if (!glob.hasMagic(fileItem.src)) {

        // determine default dest
        if (!fileItem.dest) {
          fileItem.dest = path.posix.basename(file);
        }

        // generate full path
        fileItem.dest = path.posix.join(assetPath, fileItem.dest);
        mapping.push(fileItem);
      }

      // resolve magic pattern
      else {
        var files = glob.sync(fileItem.src, globOptions);
        var hasCwd = !!globOptions.cwd;
        var dest = fileItem.dest ? path.posix.join(assetPath, fileItem.dest) : assetPath;

        files.forEach(function (resolvedFile) {

          // check 'flatten' option -> strip dir name
          var destFile = flatName ? path.posix.basename(resolvedFile) : resolvedFile;

          var item = {
            src: resolvedFile,
            dest: path.posix.join(dest, destFile)
          };

          // check "cwd" option -> rebuild path, because it was stripped by glob.sync()
          if (hasCwd) {
            item.src = path.posix.join(globOptions.cwd, resolvedFile);
          }

          mapping.push(item);
        });
      }
    });

    asset.files = mapping;
  });

  return list;
}
function normalizeAssets ( clientLibPath , assets ) { var list = assets ; // transform object to array if ( ! _ . isArray ( assets ) ) { list = [ ] ; _ . keys ( assets ) . forEach ( function ( assetKey ) { var assetItem = assets [ assetKey ] ; // check/transform short version if ( _ . isArray ( assetItem ) ) { assetItem = { files : assetItem } ; } if ( ! assetItem . base ) { assetItem . base = assetKey ; } assetItem . type = assetKey ; list . push ( assetItem ) ; } ) ; } // transform files to scr-dest mapping list . forEach ( function ( asset ) { var mapping = [ ] ; var flatName = typeof asset . flatten !== "boolean" ? true : asset . flatten ; var assetPath = path . posix . join ( clientLibPath , asset . base ) ; var globOptions = { } ; if ( asset . cwd ) { globOptions . cwd = asset . cwd ; } asset . files . forEach ( function ( file ) { var fileItem = file ; // convert simple syntax to object if ( _ . isString ( file ) ) { fileItem = { src : file } ; } // no magic pattern -> default behaviour if ( ! glob . hasMagic ( fileItem . src ) ) { // determine default dest if ( ! fileItem . dest ) { fileItem . dest = path . posix . basename ( file ) ; } // generate full path fileItem . dest = path . posix . join ( assetPath , fileItem . dest ) ; mapping . push ( fileItem ) ; } // resolve magic pattern else { var files = glob . sync ( fileItem . src , globOptions ) ; var hasCwd = ! ! globOptions . cwd ; var dest = fileItem . dest ? path . posix . join ( assetPath , fileItem . dest ) : assetPath ; files . forEach ( function ( resolvedFile ) { // check 'flatten' option -> strip dir name var destFile = flatName ? path . posix . basename ( resolvedFile ) : resolvedFile ; var item = { src : resolvedFile , dest : path . posix . join ( dest , destFile ) } ; // check "cwd" option -> rebuild path, because it was stripped by glob.sync() if ( hasCwd ) { item . src = path . posix . join ( globOptions . cwd , resolvedFile ) ; } mapping . push ( item ) ; } ) ; } } ) ; asset . files = mapping ; } ) ; return list ; }
Normalize different asset configuration options.
@param {String} clientLibPath - clientlib subfolder
@param {Object} assets - asset configuration object
@returns {*}
Normalize different asset configuration options .