index.js
function mergeOptions(pluginOptions) {
  const defaultOptions = {
    config: null,
    debug: false,
    css: {
      file_types: ['.css', '.less', '.sass', '.scss'],
    },
    html: {
      file_types: ['.html'],
    },
    js: {
      file_types: ['.js', '.json'],
    },
  };

  // Load 'file options'
  const explorer = cosmiconfig('jsbeautify');
  let explorerResult;

  if (pluginOptions && pluginOptions.config) {
    explorerResult = explorer.loadSync(path.resolve(pluginOptions.config));
  } else {
    explorerResult = explorer.searchSync();
  }

  let fileOptions;
  if (explorerResult) {
    fileOptions = explorerResult.config;
  }

  // Merge options
  const finalOptions = mergeWith({}, defaultOptions, fileOptions, pluginOptions, (objValue, srcValue) => {
    if (Array.isArray(objValue)) {
      return objValue.concat(srcValue);
    }

    return undefined;
  });

  // Show debug messages
  if (finalOptions.debug) {
    if (fileOptions) {
      log(`File options:\n${JSON.stringify(fileOptions, null, 2)}`);
    }

    log(`Final options:\n${JSON.stringify(finalOptions, null, 2)}`);
  }

  // Delete properties not used
  delete finalOptions.config;
  delete finalOptions.debug;

  return finalOptions;
}
function mergeOptions(pluginOptions) {
  const defaultOptions = {
    config: null,
    debug: false,
    css: {
      file_types: ['.css', '.less', '.sass', '.scss'],
    },
    html: {
      file_types: ['.html'],
    },
    js: {
      file_types: ['.js', '.json'],
    },
  };

  // Load 'file options'
  const explorer = cosmiconfig('jsbeautify');
  let explorerResult;

  if (pluginOptions && pluginOptions.config) {
    explorerResult = explorer.loadSync(path.resolve(pluginOptions.config));
  } else {
    explorerResult = explorer.searchSync();
  }

  let fileOptions;
  if (explorerResult) {
    fileOptions = explorerResult.config;
  }

  // Merge options
  const finalOptions = mergeWith({}, defaultOptions, fileOptions, pluginOptions, (objValue, srcValue) => {
    if (Array.isArray(objValue)) {
      return objValue.concat(srcValue);
    }

    return undefined;
  });

  // Show debug messages
  if (finalOptions.debug) {
    if (fileOptions) {
      log(`File options:\n${JSON.stringify(fileOptions, null, 2)}`);
    }

    log(`Final options:\n${JSON.stringify(finalOptions, null, 2)}`);
  }

  // Delete properties not used
  delete finalOptions.config;
  delete finalOptions.debug;

  return finalOptions;
}
function mergeOptions ( pluginOptions ) { const defaultOptions = { config : null , debug : false , css : { file_types : [ '.css' , '.less' , '.sass' , '.scss' ] , } , html : { file_types : [ '.html' ] , } , js : { file_types : [ '.js' , '.json' ] , } , } ; // Load 'file options' const explorer = cosmiconfig ( 'jsbeautify' ) ; let explorerResult ; if ( pluginOptions && pluginOptions . config ) { explorerResult = explorer . loadSync ( path . resolve ( pluginOptions . config ) ) ; } else { explorerResult = explorer . searchSync ( ) ; } let fileOptions ; if ( explorerResult ) { fileOptions = explorerResult . config ; } // Merge options const finalOptions = mergeWith ( { } , defaultOptions , fileOptions , pluginOptions , ( objValue , srcValue ) => { if ( Array . isArray ( objValue ) ) { return objValue . concat ( srcValue ) ; } return undefined ; } ) ; // Show debug messages if ( finalOptions . debug ) { if ( fileOptions ) { log ( ` \n ${ JSON . stringify ( fileOptions , null , 2 ) } ` ) ; } log ( ` \n ${ JSON . stringify ( finalOptions , null , 2 ) } ` ) ; } // Delete properties not used delete finalOptions . config ; delete finalOptions . debug ; return finalOptions ; }
Merge options from different sources
@param  {Object} pluginOptions The gulp-jsbeautifier options
@return {Object} The options
Merge options from different sources