yeoman / configstore

Easily load and persist config without having to think about where and how
BSD 2-Clause "Simplified" License
868 stars 56 forks source link

Question: Check if config exists? #47

Closed amilajack closed 8 years ago

amilajack commented 8 years ago

Is there a proper, cross-platform way to check if the config file already exists?

sindresorhus commented 8 years ago

What problem are you trying to solve?

amilajack commented 8 years ago

I'm trying to check if a configuration already exists. new Configstore() will create a new store and I want to avoid that if I one was already created.

sindresorhus commented 8 years ago

Configstore merges in the existing store, so no need to check.

amilajack commented 8 years ago

I'm also trying to initialize some values upon creation. For example,

// Initialize config store values
if (configDoesNotExist) {
  return new ConfigStore('popcorn-time-experimental', {
    favorites: { items: [] },
    recentlyWatched: { items: [] },
    watchList: { items: [] },
    state: {}
  });
}

// Initialize config store values
else {
   return new ConfigStore('popcorn-time-experimental');
}
sindresorhus commented 8 years ago

That's what the defaults option is for.

amilajack commented 8 years ago

Thanks for clarifying!