コード例 #1
0
ファイル: index.js プロジェクト: nuintun/gulp-cmd
/**
 * @function initOptions
 * @param {Object} options
 * @returns {Object}
 */
function initOptions(options) {
  gutil.validateOptions(optionsSchemas, options);

  // Init root and base
  options.root = path.resolve(options.root);
  options.base = path.resolve(options.root, options.base);

  // The base out of bounds of root
  if (gutil.isOutBounds(options.base, options.root)) {
    throw new TypeError('Options.base is out bounds of options.root.');
  }

  // Assert css loader
  if (!options.css.loader) {
    throw new TypeError(`Options.css.loader must be a nonempty string.`);
  }

  // Init files cache
  options.cache = new Map();
  // Init loaders cache
  options.loaders = new Map();
  // Init micromatch cache
  options.micromatch = new Map();
  // Init ignore
  options.ignore = Array.from(
    options.ignore.reduce((patterns, pattern) => {
      if (!patterns.has(pattern) && gutil.typpy(pattern, String)) {
        // Preserve the "!" prefix so that micromatch can use it for negation.
        const negate = pattern.startsWith('!');

        if (negate) pattern = pattern.slice(1);

        pattern = gutil.unixify(path.resolve(pattern));

        if (negate) pattern = `!${pattern}`;

        patterns.add(pattern);
      }

      return patterns;
    }, new Set())
  );

  // Init combine
  const combine = options.combine;
  const fnCombine = gutil.typpy(combine, Function);

  options.combine = module => (fnCombine ? combine(module) : combine);

  // Freeze
  options.js = Object.freeze(options.js);
  options.css = Object.freeze(options.css);

  // Can not override js packager
  delete options.packagers.js;

  // Freeze
  return Object.freeze(options);
}
コード例 #2
0
ファイル: index.js プロジェクト: nuintun/gulp-css
/**
 * @function initOptions
 * @param {Object} options
 * @returns {Object}
 */
function initOptions(options) {
  // Init attrs
  gutil.validateOptions(optionsSchemas, options, 'gulp-css');

  // Init root and base
  options.root = path.resolve(options.root);

  // Init files cache
  options.cache = new Map();

  // Init combine
  const combine = options.combine;
  const fnCombine = gutil.typpy(combine, Function);

  options.combine = module => (fnCombine ? combine(module) : combine);

  // Freeze
  return Object.freeze(options);
}