From ca368eef793c286a3ae105f5ffcb63686dad1bba Mon Sep 17 00:00:00 2001 From: aexol Date: Thu, 1 Aug 2024 10:37:20 +0200 Subject: [PATCH] removed global opts; --- Readme.md | 8 +---- packages/config-maker/package.json | 2 +- .../config-maker/src/Configuration/index.ts | 35 ++----------------- 3 files changed, 5 insertions(+), 40 deletions(-) diff --git a/Readme.md b/Readme.md index a751067..cf0a1d8 100644 --- a/Readme.md +++ b/Readme.md @@ -35,16 +35,12 @@ then create a config instance somewhere. For example in `config.ts` file. ```ts import { ConfigMaker } from 'config-maker'; -type UserOptions = { - token: string; -}; - type ProjectOptions = { urlOrPath: string; vv: number; }; -export const config = new ConfigMaker('myConfig', { +export const config = new ConfigMaker('myConfig', { decoders: { vv: { decode: (v) => parseInt(v), @@ -86,8 +82,6 @@ export const config = new ConfigMaker('myConfig', { ``` Lets go throught this step by step. First generic parameter which in our case is `ProjectOptions` is what will be held inside config json file in the project folder using your CLI. -Second parameter `UserOptions` is used to store global options inside users `$HOME` folder. - Then `myConfig` is the config file name. It will be stored in users who is using the CLI that uses `config-maker` **`decoders`** - are only needed when a value is different type that string, but we want to encode it in the config. diff --git a/packages/config-maker/package.json b/packages/config-maker/package.json index 8292f8c..873e495 100644 --- a/packages/config-maker/package.json +++ b/packages/config-maker/package.json @@ -1,6 +1,6 @@ { "name": "config-maker", - "version": "0.0.5", + "version": "0.0.6", "description": "Make interactive config for CLIs. Fetch values from command line, file, user options or environment variable.", "main": "lib/index.js", "author": "Artur Czemiel", diff --git a/packages/config-maker/src/Configuration/index.ts b/packages/config-maker/src/Configuration/index.ts index a356f1d..63cccf4 100644 --- a/packages/config-maker/src/Configuration/index.ts +++ b/packages/config-maker/src/Configuration/index.ts @@ -2,7 +2,6 @@ import fs from 'fs'; import path from 'path'; import inquirer, { QuestionCollection } from 'inquirer'; -import Conf from 'conf'; import AutoCompleteInputPrompt from '@/utils/AutoCompleteInputPrompt.js'; import { getEnvValue } from '@/common/envs.js'; @@ -29,16 +28,11 @@ type Coders = { }; }; -type AllOptions = { +type AllOptions = { options: Partial; - globalOptions: Partial; }; -export class ConfigMaker< - ConfigurationOptions extends Record, - GlobalOptions extends Record, -> { +export class ConfigMaker> { private options: Partial = {}; - private globalOptions = new Conf({}); private projectPath = process.cwd(); constructor( public configFileName: string, @@ -56,23 +50,13 @@ export class ConfigMaker< config?: { autocomplete?: { [P in keyof ConfigurationOptions]?: ( - currentConfig: AllOptions, + currentConfig: AllOptions, ) => Promise; }; environment?: { [P in keyof ConfigurationOptions]?: string; }; }; - global?: { - autocomplete?: { - [P in keyof GlobalOptions]?: ( - currentConfig: AllOptions, - ) => Promise; - }; - environment?: { - [P in keyof GlobalOptions]?: string; - }; - }; }, ) { this.projectPath = props?.pathToProject || this.projectPath; @@ -187,7 +171,6 @@ export class ConfigMaker< const result = await AutoCompleteInputPrompt( await autocompleteFunction({ options: this.options, - globalOptions: this.globalOptions.store, }), { message: optionsMessage || 'Autocomplete ' + key, @@ -214,18 +197,6 @@ export class ConfigMaker< return returnValue; }; - // get global options that are usually stored in users $HOME folder - getGlobalOptions = () => this.globalOptions; - getGlobalOptionsValue = (k: T) => - this.globalOptions.get(k); - setGlobalOptions = (opts: GlobalOptions) => this.globalOptions.set(opts); - updateGlobalOptions = (opts?: Partial) => { - if (opts) { - this.globalOptions.set({ ...opts }); - } - }; - clearGlobalOptions = () => this.globalOptions.clear(); - getGlobalOptionsPath = () => this.globalOptions.path; serializeConfigAsString = () => Buffer.from(JSON.stringify(this.options)).toString('base64'); deserializeConfigFromString = (serialized: string) =>