How to use the conf.default function in conf

To help you get started, we’ve selected a few conf examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github sw-yx / cli-state / src / index.ts View on Github external
}: initCLIStateArgs) => {
  willPrintDebugMessages = printDebugMessages || false;
  // provide some nice defaults for the CLI global settings
  const globalStateDefaults = {
    /* disable stats from being sent home */
    telemetry: 'enabled',
    /* a unique ID for your CLI user */
    cliId: uuidv4(),
  };
  if (!globalConfOptions.defaults) {
    globalConfOptions = {
      ...globalConfOptions,
      defaults: globalStateDefaults,
    };
  }
  globalState = new Conf.default(globalConfOptions);

  // frecency
  if (globalState instanceof Conf.default) {
    const { _options: options } = globalState as typeof globalState & {
      _options: { projectName: string };
    };
    const storageProviderFrecencyFilePath = envPaths(options.projectName).cache; // store frecency in cache, it is disposable
    if (willPrintDebugMessages) {
      console.log({
        storageProviderFrecencyFilePath,
        globalStatePath: globalState.path,
      });
    }
    const storageProvider = new LocalStorage(storageProviderFrecencyFilePath);
    accessGlobalFrecency = key =>
      new Frecency({
github sw-yx / cli-state / src / index.ts View on Github external
storageProviderFrecencyFilePath,
        globalStatePath: globalState.path,
      });
    }
    const storageProvider = new LocalStorage(storageProviderFrecencyFilePath);
    accessGlobalFrecency = key =>
      new Frecency({
        key,
        storageProvider,
        idAttribute: 'value',
        ...frecencyOpts,
      });
  }

  // scope projectConfOptions to cwd
  projectState = new Conf.default({
    ...projectConfOptions,
    cwd: projectStatePath,
  });
  return {
    globalState,
    projectState,
    accessGlobalFrecency,
  };
};