function initialize()

in lib/index.js [108:139]


function initialize(libraryOptions) {
  libraryOptions = libraryOptions || {};
  const resolvers = libraryOptions.resolvers || createDefaultResolvers(libraryOptions);
  if (!resolvers) {
    throw new Error('No resolvers provided.');
  }
  const environmentProvider = resolvers.environment;
  return {
    resolve: async function (options) {
      if (typeof(options) === 'function') {
        const deprecatedCallback = options;
        return deprecatedCallback(new Error('This library no longer supports callbacks. Please use native JavaScript promises, i.e. const config = await painlessConfigResolver.resolve();'));
      }
      options = options || {};
      // Find, build or dynamically generate the configuration graph
      const graph = await getConfigGraph(libraryOptions, options, environmentProvider);
      if (!graph) {
        throw new Error('No configuration "graph" provided as an option to this library. Unless using a configuration graph provider, the graph option must be included.');
      }
      try {
      // Synchronously, in order, resolve the graph
        for (const resolver of resolvers) {
          await resolver(graph);
        }
      } catch (resolveConfigurationError) {
        console.warn(`Error while resolving the graph with a resolver: ${resolveConfigurationError}`);
        throw resolveConfigurationError;
      }
      return graph;
    },
  };
}