Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}: 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({
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,
};
};