From f6d65270b81e939fa88d6b0fa70833ccc681d180 Mon Sep 17 00:00:00 2001 From: MagdaPuch Date: Thu, 22 Aug 2024 13:28:14 +0200 Subject: [PATCH 01/15] Redesign Readme.md --- Readme.md | 146 ++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 119 insertions(+), 27 deletions(-) diff --git a/Readme.md b/Readme.md index cf0a1d8..cffd0df 100644 --- a/Readme.md +++ b/Readme.md @@ -1,37 +1,53 @@ -# Config maker +### CONFIG MAKER ![Vector 902 (Stroke) (1)](https://github.com/user-attachments/assets/18e2f31f-a70f-4c3e-b284-3b66c989a15f) +This is the config manager to use for your interactive CLI. -Config manager for your CLI. When you are making +
Features: -- make and consume JSON config files -- give 4 chances to input the value: as an cli option, as user input, as an autocomplete prompt, as an environment variable +- Making and consuming JSON config files +- Inputing the value in 4 different ways: + - as a cli option + - as user input + - as an autocomplete prompt + - as an environment variable -## How values are fetched +
+ +## 📤 How the Values Are Fetched ```mermaid graph LR - A[Option from command line] --> AY[Exists] - AY --> R[Return value] - A --Not present---> + A[Option from the Command Line] --> AY[Exists] + AY --> R[Return Value] + A --Not Present---> D[Environment Variable] --> AY - D --Not present---> + D --Not Present---> E[In Config File] --> AY - E --Not present---> - F[Prompt for input] --> R + E --Not Present---> + F[Prompt for the Input] --> R + ``` -## Where to use -If you are making interactive CLI you can use config-maker. +
+ -## How to use +## 📖 How to - a Step by Step Guide -First of all install the config-maker package +#### 1. Install the config-maker package ```sh npm i config-maker + ``` -then create a config instance somewhere. For example in `config.ts` file. +#### 2. Create a config instance somewhere + +As an example, you can do that in the `config.ts` file. + +`ProjectOptions` is the first generic parameter we are dealing with. It is what will be held inside the config json file in the project folder while using your CLI. + +Then `myConfig` is the config file name. It will be stored in users who is using the CLI that uses `config-maker`. + ```ts import { ConfigMaker } from 'config-maker'; @@ -41,12 +57,27 @@ type ProjectOptions = { }; export const config = new ConfigMaker('myConfig', { + +``` + +#### 3. (Optional)Add Decoders +**`decoders`** - are only needed when a value is different type that string, but we want to encode it in the config. + +```ts + decoders: { vv: { decode: (v) => parseInt(v), encode: (v) => v + '', }, }, + +``` + +#### 4. (Optional) Add Prompts +**`prompt`** - are optional messages that are used in text and/or in `autocomplete` prompts. + +```ts // messages to be used for prompts prompts: { vv: { @@ -60,6 +91,13 @@ export const config = new ConfigMaker('myConfig', { defaultValues: { vv: 1, }, + +``` + +#### 5. Autocomplete +**`autocomplete`** - functions returning an array of strings to be used inside autocomplete + +```ts config: { // Autocomplete functions returns possible options autocomplete: { @@ -78,19 +116,10 @@ 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. - -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. - -**`prompt`** - are optional messages that are used in text and/or in `autocomplete` prompts. -**`autocomplete`** - functions returning an array of strings to be used inside autocomplete -Then to use the value from the config you can use two functions of the config object. +#### 6. Then to use the value from the config you can use two functions of the config object. **`getValue`** - get the value by key. Just to remind - it will be resolved this way: 1. Get from CMD line option if exist @@ -107,4 +136,67 @@ const value = config.getValue('url') ``` -**`getValueOrThrow`** - same as `getValue` but throws an error if value is not provided \ No newline at end of file +**`getValueOrThrow`** - same as `getValue` but throws an error if value is not provided + + +### Here's What the Full Code Should Look Like: + +```sh +npm i config-maker +``` + +```ts +import { ConfigMaker } from 'config-maker'; + +type ProjectOptions = { + urlOrPath: string; + vv: number; +}; + +export const config = new ConfigMaker('myConfig', { + decoders: { + vv: { + decode: (v) => parseInt(v), + encode: (v) => v + '', + }, + }, + // messages to be used for prompts + prompts: { + vv: { + message: 'Package version', + }, + urlOrPath: { + message: 'Provide url or path to the file', + }, + }, + // default initial values + defaultValues: { + vv: 1, + }, + config: { + // Autocomplete functions returns possible options + autocomplete: { + urlOrPath: async (p) => { + // if the property vv is already set + if (p.options.vv === 1) { + return ['https://aexol.com', 'https://space.com']; + } + return ['https://github.com', 'https://news.hacker.com']; + }, + }, + environment: { + // check if this env value exists + urlOrPath: 'URL_PATH', + }, + }, +}); + +``` + +```ts +//Import your created config +import {config} from './config.js' +//Get type safe value type is value type or undefined if user won't provide any input +const value = config.getValue('url') + +``` From ad66fd00aa6f5a372aff7bf53453ff82e18cc4ee Mon Sep 17 00:00:00 2001 From: MagdaPuch Date: Thu, 22 Aug 2024 14:23:13 +0200 Subject: [PATCH 02/15] Redesign Readme.md --- Readme.md | 65 +++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 42 insertions(+), 23 deletions(-) diff --git a/Readme.md b/Readme.md index cffd0df..2269446 100644 --- a/Readme.md +++ b/Readme.md @@ -40,13 +40,12 @@ npm i config-maker ``` +
+ #### 2. Create a config instance somewhere As an example, you can do that in the `config.ts` file. -`ProjectOptions` is the first generic parameter we are dealing with. It is what will be held inside the config json file in the project folder while using your CLI. - -Then `myConfig` is the config file name. It will be stored in users who is using the CLI that uses `config-maker`. ```ts import { ConfigMaker } from 'config-maker'; @@ -59,9 +58,16 @@ type ProjectOptions = { export const config = new ConfigMaker('myConfig', { ``` +
+ +`ProjectOptions` is the first generic parameter you'll be dealing with. It is what will be stored inside the config json file in the project folder while using your CLI. -#### 3. (Optional)Add Decoders -**`decoders`** - are only needed when a value is different type that string, but we want to encode it in the config. +`myConfig` is the name of the config file. It will be stored in the Users folder for those who use the CLI with the setting `config-maker`. + +
+ +#### 3. (Optional) Add Decoders +**`decoders`** - are only needed when you use non-string values, but you still want to encode them in the config. ```ts @@ -74,6 +80,8 @@ export const config = new ConfigMaker('myConfig', { ``` +
+ #### 4. (Optional) Add Prompts **`prompt`** - are optional messages that are used in text and/or in `autocomplete` prompts. @@ -94,12 +102,14 @@ export const config = new ConfigMaker('myConfig', { ``` -#### 5. Autocomplete -**`autocomplete`** - functions returning an array of strings to be used inside autocomplete +
+ +#### 5. Add the Autocomplete Function +**`autocomplete`** - are functions that return an array of strings to be used inside autocomplete ```ts config: { - // Autocomplete functions returns possible options + // autocomplete functions returns possible options autocomplete: { urlOrPath: async (p) => { // if the property vv is already set @@ -118,28 +128,37 @@ export const config = new ConfigMaker('myConfig', { ``` +
+ +#### 6. Use the Values from the Config + +To use the value from the config, you can use two functions of the config object. -#### 6. Then to use the value from the config you can use two functions of the config object. +![arrow-top](https://github.com/user-attachments/assets/3632196c-f2f8-46a2-9d3d-4a8071ca1908#gh-dark-mode-only) ![arrow-top-dark](https://github.com/user-attachments/assets/496077a7-85a9-44dc-8770-5a248d63886d#gh-light-mode-only) **`getValue`** - get the value by its key -**`getValue`** - get the value by key. Just to remind - it will be resolved this way: -1. Get from CMD line option if exist -2. Get from environment variable if provided -3. Get from current config if exist in -4. Get from text or autocomplete input if provided -5. If still now value - return `undefined` +> [!TIP] +> As a reminder, it will be resolved this way: +> 1. Get from CMD line option if exist +> 2. Get from environment variable if provided +> 3. Get from current config if exist in +> 4. Get from text or autocomplete input if provided +> 5. If still now value - return `undefined` + +
+ +![arrow-top](https://github.com/user-attachments/assets/3632196c-f2f8-46a2-9d3d-4a8071ca1908#gh-dark-mode-only) ![arrow-top-dark](https://github.com/user-attachments/assets/496077a7-85a9-44dc-8770-5a248d63886d#gh-light-mode-only) **`getValueOrThrow`** - is the same as `getValue` but additionally throws an error if a value is not provided ```ts -//Import your created config +// import your created config import {config} from './config.js' -//Get type safe value type is value type or undefined if user won't provide any input +// get type-safe; if the user won't provide any input, the value type is by default: value type or undefined const value = config.getValue('url') ``` -**`getValueOrThrow`** - same as `getValue` but throws an error if value is not provided - +
-### Here's What the Full Code Should Look Like: +## 💬 Full Code ```sh npm i config-maker @@ -174,7 +193,7 @@ export const config = new ConfigMaker('myConfig', { vv: 1, }, config: { - // Autocomplete functions returns possible options + // autocomplete functions returns possible options autocomplete: { urlOrPath: async (p) => { // if the property vv is already set @@ -194,9 +213,9 @@ export const config = new ConfigMaker('myConfig', { ``` ```ts -//Import your created config +// import your created config import {config} from './config.js' -//Get type safe value type is value type or undefined if user won't provide any input +// get type-safe; if the user won't provide any input, the value type is by default: value type or undefined const value = config.getValue('url') ``` From 9cb31df0b05fc2f866a99a4f4f504831b4ad89cc Mon Sep 17 00:00:00 2001 From: MagdaPuch Date: Mon, 26 Aug 2024 10:15:47 +0200 Subject: [PATCH 03/15] Redesign Readme.md --- Readme.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Readme.md b/Readme.md index 2269446..cdd5481 100644 --- a/Readme.md +++ b/Readme.md @@ -151,7 +151,7 @@ To use the value from the config, you can use two functions of the config object ```ts // import your created config import {config} from './config.js' -// get type-safe; if the user won't provide any input, the value type is by default: value type or undefined +// get type-safe; if no input is provided, the value type defaults to: value type or undefined const value = config.getValue('url') ``` @@ -215,7 +215,7 @@ export const config = new ConfigMaker('myConfig', { ```ts // import your created config import {config} from './config.js' -// get type-safe; if the user won't provide any input, the value type is by default: value type or undefined +// get type-safe; if no input is provided, the value type defaults to: value type or undefined const value = config.getValue('url') ``` From b1d6a1d1252b959ae134db35bb2ab8cc5d59968e Mon Sep 17 00:00:00 2001 From: MagdaPuch Date: Mon, 26 Aug 2024 10:35:20 +0200 Subject: [PATCH 04/15] Redesign Readme.md --- Readme.md | 42 ++++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/Readme.md b/Readme.md index cdd5481..06c7ba5 100644 --- a/Readme.md +++ b/Readme.md @@ -1,19 +1,19 @@ ### CONFIG MAKER ![Vector 902 (Stroke) (1)](https://github.com/user-attachments/assets/18e2f31f-a70f-4c3e-b284-3b66c989a15f) -This is the config manager to use for your interactive CLI. +Config Maker is a config manager to use for your interactive CLI.
-Features: +## 📋 Features: - Making and consuming JSON config files -- Inputing the value in 4 different ways: - - as a cli option +- Inputing the value in four different ways: + - as a CLI option - as user input - as an autocomplete prompt - as an environment variable
-## 📤 How the Values Are Fetched +## 📤 How Values Are Fetched ```mermaid graph LR @@ -31,9 +31,9 @@ graph LR
-## 📖 How to - a Step by Step Guide +## 📖 Step-by-Step Guide to Using Config Maker -#### 1. Install the config-maker package +### 1. Install the config-maker package ```sh npm i config-maker @@ -42,10 +42,9 @@ npm i config-maker
-#### 2. Create a config instance somewhere - -As an example, you can do that in the `config.ts` file. +### 2. Create a config instance +You can create the config instance anywhere, for example, in the `config.ts` file. ```ts import { ConfigMaker } from 'config-maker'; @@ -60,13 +59,12 @@ export const config = new ConfigMaker('myConfig', { ```
-`ProjectOptions` is the first generic parameter you'll be dealing with. It is what will be stored inside the config json file in the project folder while using your CLI. - -`myConfig` is the name of the config file. It will be stored in the Users folder for those who use the CLI with the setting `config-maker`. +The first generic paremeter you will be dealing with is `ProjectOptions`. This will be stored inside the config json file in the project folder while using your CLI. +The config file is named `myConfig`. THis will be stored in the Users-folder for those use the CLI with the setting `config-maker`.
-#### 3. (Optional) Add Decoders +### 3. (Optional) Add Decoders **`decoders`** - are only needed when you use non-string values, but you still want to encode them in the config. ```ts @@ -82,7 +80,7 @@ export const config = new ConfigMaker('myConfig', {
-#### 4. (Optional) Add Prompts +### 4. (Optional) Add Prompts **`prompt`** - are optional messages that are used in text and/or in `autocomplete` prompts. ```ts @@ -104,7 +102,7 @@ export const config = new ConfigMaker('myConfig', {
-#### 5. Add the Autocomplete Function +### 5. Add the Autocomplete Function **`autocomplete`** - are functions that return an array of strings to be used inside autocomplete ```ts @@ -130,11 +128,14 @@ export const config = new ConfigMaker('myConfig', {
-#### 6. Use the Values from the Config +### 6. Use the Values from the Config -To use the value from the config, you can use two functions of the config object. +The config object has two functions for retrieving values from the config. + +
-![arrow-top](https://github.com/user-attachments/assets/3632196c-f2f8-46a2-9d3d-4a8071ca1908#gh-dark-mode-only) ![arrow-top-dark](https://github.com/user-attachments/assets/496077a7-85a9-44dc-8770-5a248d63886d#gh-light-mode-only) **`getValue`** - get the value by its key +#### ![arrow-top](https://github.com/user-attachments/assets/3632196c-f2f8-46a2-9d3d-4a8071ca1908#gh-dark-mode-only) ![arrow-top-dark](https://github.com/user-attachments/assets/496077a7-85a9-44dc-8770-5a248d63886d#gh-light-mode-only) OPTION 1: +The `getValue` function retrieves the value by it's key. > [!TIP] > As a reminder, it will be resolved this way: @@ -146,7 +147,8 @@ To use the value from the config, you can use two functions of the config object
-![arrow-top](https://github.com/user-attachments/assets/3632196c-f2f8-46a2-9d3d-4a8071ca1908#gh-dark-mode-only) ![arrow-top-dark](https://github.com/user-attachments/assets/496077a7-85a9-44dc-8770-5a248d63886d#gh-light-mode-only) **`getValueOrThrow`** - is the same as `getValue` but additionally throws an error if a value is not provided +#### ![arrow-top](https://github.com/user-attachments/assets/3632196c-f2f8-46a2-9d3d-4a8071ca1908#gh-dark-mode-only) ![arrow-top-dark](https://github.com/user-attachments/assets/496077a7-85a9-44dc-8770-5a248d63886d#gh-light-mode-only) OPTION 2: +The `getValueOrThrow` function works the same as `getValue` but additionally throws an error if a value is not provided. ```ts // import your created config From 43c1d6b51f443389b0a3eb4ed69ca43f47d84e9f Mon Sep 17 00:00:00 2001 From: MagdaPuch Date: Tue, 27 Aug 2024 11:42:52 +0200 Subject: [PATCH 05/15] Redesign Readme.md --- Readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Readme.md b/Readme.md index 06c7ba5..071d09b 100644 --- a/Readme.md +++ b/Readme.md @@ -135,7 +135,7 @@ The config object has two functions for retrieving values from the config.
#### ![arrow-top](https://github.com/user-attachments/assets/3632196c-f2f8-46a2-9d3d-4a8071ca1908#gh-dark-mode-only) ![arrow-top-dark](https://github.com/user-attachments/assets/496077a7-85a9-44dc-8770-5a248d63886d#gh-light-mode-only) OPTION 1: -The `getValue` function retrieves the value by it's key. +The `getValue` function retrieves the value by its key. > [!TIP] > As a reminder, it will be resolved this way: From 4c1e2e086a041a84aa4016d870d37f67a3e21319 Mon Sep 17 00:00:00 2001 From: MagdaPuch Date: Tue, 27 Aug 2024 14:46:58 +0200 Subject: [PATCH 06/15] Redesign Readme.md --- Readme.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Readme.md b/Readme.md index 071d09b..a4be895 100644 --- a/Readme.md +++ b/Readme.md @@ -59,8 +59,8 @@ export const config = new ConfigMaker('myConfig', { ```
-The first generic paremeter you will be dealing with is `ProjectOptions`. This will be stored inside the config json file in the project folder while using your CLI. -The config file is named `myConfig`. THis will be stored in the Users-folder for those use the CLI with the setting `config-maker`. +The first generic paremeter you will be dealing with is `ProjectOptions`. It will be stored inside the config json file in the project folder while using your CLI. +The config file is named `myConfig`. It will be stored in the Users folder for those who use the CLI with the setting `config-maker`.
@@ -130,7 +130,7 @@ The config file is named `myConfig`. THis will be stored in the Users-folder for ### 6. Use the Values from the Config -The config object has two functions for retrieving values from the config. +The config object has two ways of retrieving values from the config.
From 8524e4597c86e21749350e092c9f5ddadb8e3f7e Mon Sep 17 00:00:00 2001 From: MagdaPuch Date: Wed, 28 Aug 2024 10:24:31 +0200 Subject: [PATCH 07/15] Redesign Readme.md --- Readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Readme.md b/Readme.md index a4be895..fb9fefd 100644 --- a/Readme.md +++ b/Readme.md @@ -1,4 +1,4 @@ -### CONFIG MAKER ![Vector 902 (Stroke) (1)](https://github.com/user-attachments/assets/18e2f31f-a70f-4c3e-b284-3b66c989a15f) +### CONFIG MAKER ![Vector 902 (Stroke) (1)](https://github.com/user-attachments/assets/93e38773-7467-4374-a9e8-13387aa5b076) Config Maker is a config manager to use for your interactive CLI.
From 792503019b3b8d1bc738e29eee611ed4f0c58d94 Mon Sep 17 00:00:00 2001 From: MagdaPuch Date: Wed, 28 Aug 2024 11:34:57 +0200 Subject: [PATCH 08/15] Redesign Readme.md --- Readme.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Readme.md b/Readme.md index fb9fefd..b4a5b0e 100644 --- a/Readme.md +++ b/Readme.md @@ -134,7 +134,7 @@ The config object has two ways of retrieving values from the config.
-#### ![arrow-top](https://github.com/user-attachments/assets/3632196c-f2f8-46a2-9d3d-4a8071ca1908#gh-dark-mode-only) ![arrow-top-dark](https://github.com/user-attachments/assets/496077a7-85a9-44dc-8770-5a248d63886d#gh-light-mode-only) OPTION 1: +#### OPTION 1: The `getValue` function retrieves the value by its key. > [!TIP] @@ -147,7 +147,7 @@ The `getValue` function retrieves the value by its key.
-#### ![arrow-top](https://github.com/user-attachments/assets/3632196c-f2f8-46a2-9d3d-4a8071ca1908#gh-dark-mode-only) ![arrow-top-dark](https://github.com/user-attachments/assets/496077a7-85a9-44dc-8770-5a248d63886d#gh-light-mode-only) OPTION 2: +#### OPTION 2: The `getValueOrThrow` function works the same as `getValue` but additionally throws an error if a value is not provided. ```ts From 71a41a189b4900b1b4156f94541ae2f0b703056e Mon Sep 17 00:00:00 2001 From: MagdaPuch Date: Wed, 28 Aug 2024 13:02:18 +0200 Subject: [PATCH 09/15] Redesign Readme.md --- Readme.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Readme.md b/Readme.md index b4a5b0e..f449d93 100644 --- a/Readme.md +++ b/Readme.md @@ -3,7 +3,7 @@ Config Maker is a config manager to use for your interactive CLI.
-## 📋 Features: +## 📋  Features: - Making and consuming JSON config files - Inputing the value in four different ways: - as a CLI option @@ -13,7 +13,7 @@ Config Maker is a config manager to use for your interactive CLI.
-## 📤 How Values Are Fetched +## 📤  How Values Are Fetched ```mermaid graph LR @@ -31,7 +31,7 @@ graph LR
-## 📖 Step-by-Step Guide to Using Config Maker +## 📖  Step-by-Step Guide to Using Config Maker ### 1. Install the config-maker package @@ -160,7 +160,7 @@ const value = config.getValue('url')
-## 💬 Full Code +## 💬  Full Code ```sh npm i config-maker From f0e7a01ea8625ba43e5aa8131e655891a2801d53 Mon Sep 17 00:00:00 2001 From: MagdaPuch Date: Wed, 28 Aug 2024 13:51:43 +0200 Subject: [PATCH 10/15] Redesign Readme.md --- Readme.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Readme.md b/Readme.md index f449d93..6633bb1 100644 --- a/Readme.md +++ b/Readme.md @@ -1,4 +1,5 @@ -### CONFIG MAKER ![Vector 902 (Stroke) (1)](https://github.com/user-attachments/assets/93e38773-7467-4374-a9e8-13387aa5b076) +### ![config maker idea](https://github.com/user-attachments/assets/66851261-87e1-41d2-8ed2-6201ae658d50) ![Vector 902 (Stroke) (1)](https://github.com/user-attachments/assets/93e38773-7467-4374-a9e8-13387aa5b076) + Config Maker is a config manager to use for your interactive CLI.
From 56b28359fddee688355d2688b8fc959f9ba18ef3 Mon Sep 17 00:00:00 2001 From: MagdaPuch Date: Wed, 28 Aug 2024 14:30:43 +0200 Subject: [PATCH 11/15] Redesign Readme.md --- Readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Readme.md b/Readme.md index 6633bb1..4d6b027 100644 --- a/Readme.md +++ b/Readme.md @@ -4,7 +4,7 @@ Config Maker is a config manager to use for your interactive CLI.
-## 📋  Features: +## 📋  Features - Making and consuming JSON config files - Inputing the value in four different ways: - as a CLI option From 3b3186b41cd7d50f513f5289f8dfaf38ceb2d28a Mon Sep 17 00:00:00 2001 From: MagdaPuch Date: Thu, 29 Aug 2024 15:07:36 +0200 Subject: [PATCH 12/15] Redesign Readme.md --- Readme.md | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/Readme.md b/Readme.md index 4d6b027..ac11fee 100644 --- a/Readme.md +++ b/Readme.md @@ -34,7 +34,7 @@ graph LR ## 📖  Step-by-Step Guide to Using Config Maker -### 1. Install the config-maker package +**1.** Install the config-maker package ```sh npm i config-maker @@ -43,7 +43,7 @@ npm i config-maker
-### 2. Create a config instance +**2.** Create a config instance You can create the config instance anywhere, for example, in the `config.ts` file. @@ -65,7 +65,8 @@ The config file is named `myConfig`. It will be stored in the Users folder for t
-### 3. (Optional) Add Decoders +**3.** (Optional) Add Decoders + **`decoders`** - are only needed when you use non-string values, but you still want to encode them in the config. ```ts @@ -81,7 +82,8 @@ The config file is named `myConfig`. It will be stored in the Users folder for t
-### 4. (Optional) Add Prompts +**4.** (Optional) Add Prompts + **`prompt`** - are optional messages that are used in text and/or in `autocomplete` prompts. ```ts @@ -103,7 +105,8 @@ The config file is named `myConfig`. It will be stored in the Users folder for t
-### 5. Add the Autocomplete Function +**5.** Add the Autocomplete Function + **`autocomplete`** - are functions that return an array of strings to be used inside autocomplete ```ts @@ -129,13 +132,13 @@ The config file is named `myConfig`. It will be stored in the Users folder for t
-### 6. Use the Values from the Config +**6.** Use the Values from the Config The config object has two ways of retrieving values from the config.
-#### OPTION 1: +- #### OPTION 1: The `getValue` function retrieves the value by its key. > [!TIP] @@ -148,7 +151,7 @@ The `getValue` function retrieves the value by its key.
-#### OPTION 2: +- #### OPTION 2: The `getValueOrThrow` function works the same as `getValue` but additionally throws an error if a value is not provided. ```ts From 17d920c664e9b298d3c48df7d018370d666ae813 Mon Sep 17 00:00:00 2001 From: mic <114925174+michal-aexol@users.noreply.github.com> Date: Fri, 30 Aug 2024 18:19:36 +0200 Subject: [PATCH 13/15] Update Readme.md --- Readme.md | 132 +++++++++++++++++++++++------------------------------- 1 file changed, 57 insertions(+), 75 deletions(-) diff --git a/Readme.md b/Readme.md index ac11fee..3dcd42c 100644 --- a/Readme.md +++ b/Readme.md @@ -34,7 +34,7 @@ graph LR ## 📖  Step-by-Step Guide to Using Config Maker -**1.** Install the config-maker package +First lets install the config-maker package ```sh npm i config-maker @@ -43,7 +43,7 @@ npm i config-maker
-**2.** Create a config instance +Now we need to create a config instance You can create the config instance anywhere, for example, in the `config.ts` file. @@ -56,37 +56,12 @@ type ProjectOptions = { }; export const config = new ConfigMaker('myConfig', { - -``` -
- -The first generic paremeter you will be dealing with is `ProjectOptions`. It will be stored inside the config json file in the project folder while using your CLI. -The config file is named `myConfig`. It will be stored in the Users folder for those who use the CLI with the setting `config-maker`. - -
- -**3.** (Optional) Add Decoders - -**`decoders`** - are only needed when you use non-string values, but you still want to encode them in the config. - -```ts - decoders: { vv: { decode: (v) => parseInt(v), encode: (v) => v + '', }, }, - -``` - -
- -**4.** (Optional) Add Prompts - -**`prompt`** - are optional messages that are used in text and/or in `autocomplete` prompts. - -```ts // messages to be used for prompts prompts: { vv: { @@ -100,18 +75,8 @@ The config file is named `myConfig`. It will be stored in the Users folder for t defaultValues: { vv: 1, }, - -``` - -
- -**5.** Add the Autocomplete Function - -**`autocomplete`** - are functions that return an array of strings to be used inside autocomplete - -```ts config: { - // autocomplete functions returns possible options + // Autocomplete functions returns possible options autocomplete: { urlOrPath: async (p) => { // if the property vv is already set @@ -129,62 +94,45 @@ The config file is named `myConfig`. It will be stored in the Users folder for t }); ``` - -
- -**6.** Use the Values from the Config - -The config object has two ways of retrieving values from the config. - -
- -- #### OPTION 1: -The `getValue` function retrieves the value by its key. - -> [!TIP] -> As a reminder, it will be resolved this way: -> 1. Get from CMD line option if exist -> 2. Get from environment variable if provided -> 3. Get from current config if exist in -> 4. Get from text or autocomplete input if provided -> 5. If still now value - return `undefined` -
-- #### OPTION 2: -The `getValueOrThrow` function works the same as `getValue` but additionally throws an error if a value is not provided. +**Now let's go through the config step by step:** +**1.** The first generic paremeter you will be dealing with is `ProjectOptions`. It will be stored inside the config json file in the project folder while using your CLI. +`myConfig` is the config file name. It will be stored in the users folder for those who use the CLI with the setting `config-maker`. ```ts -// import your created config -import {config} from './config.js' -// get type-safe; if no input is provided, the value type defaults to: value type or undefined -const value = config.getValue('url') +import { ConfigMaker } from 'config-maker'; +type ProjectOptions = { + urlOrPath: string; + vv: number; +}; ```
-## 💬  Full Code +**2.** Decoders -```sh -npm i config-maker -``` +**`decoders`** - are only needed when a value is of a different type than that string, but we want to encode it in the config. ```ts -import { ConfigMaker } from 'config-maker'; - -type ProjectOptions = { - urlOrPath: string; - vv: number; -}; -export const config = new ConfigMaker('myConfig', { decoders: { vv: { decode: (v) => parseInt(v), encode: (v) => v + '', }, }, + +``` + +
+ +**3.** Prompts + +**`prompts`** - are optional messages that are used in text and/or in `autocomplete` prompts. + +```ts // messages to be used for prompts prompts: { vv: { @@ -198,6 +146,16 @@ export const config = new ConfigMaker('myConfig', { defaultValues: { vv: 1, }, + +``` + +
+ +**4.** Autocomplete + +**`autocomplete`** - are functions that return an array of strings to be used inside autocomplete + +```ts config: { // autocomplete functions returns possible options autocomplete: { @@ -218,6 +176,30 @@ export const config = new ConfigMaker('myConfig', { ``` +
+ +## **Using the Values from the Config** + +The config object has two ways of retrieving values from the config. + +
+ +- #### OPTION 1: +The `getValue` function retrieves the value by its key. + +> [!TIP] +> As a reminder, it will be resolved this way: +> 1. Get from CMD line option if it exists +> 2. Get from environment variable if provided +> 3. Get from current config if exists in it +> 4. Get from text or autocomplete input if provided +> 5. If still no value - return `undefined` + +
+ +- #### OPTION 2: +The `getValueOrThrow` function works the same as `getValue` but additionally throws an error if a value is not provided. + ```ts // import your created config import {config} from './config.js' From 225e178aa8a960fd37e227a5d4a61d7927d96ef0 Mon Sep 17 00:00:00 2001 From: MagdaPuch Date: Mon, 2 Sep 2024 12:44:36 +0200 Subject: [PATCH 14/15] Redesign Readme.md --- Readme.md | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/Readme.md b/Readme.md index 3dcd42c..5e52c83 100644 --- a/Readme.md +++ b/Readme.md @@ -1,5 +1,4 @@ -### ![config maker idea](https://github.com/user-attachments/assets/66851261-87e1-41d2-8ed2-6201ae658d50) ![Vector 902 (Stroke) (1)](https://github.com/user-attachments/assets/93e38773-7467-4374-a9e8-13387aa5b076) - +### ![config maker idea](https://github.com/user-attachments/assets/95c8e7b4-5a9b-4d98-906a-b9fcc6a2f216) ![Vector 902 (Stroke) (1)](https://github.com/user-attachments/assets/93e38773-7467-4374-a9e8-13387aa5b076#gh-dark-mode-only) ![Vector 902 (Stroke) (1)](https://github.com/user-attachments/assets/51b16a12-11c3-4b72-8f87-d78afdbe9c83#gh-light-mode-only) Config Maker is a config manager to use for your interactive CLI.
@@ -34,7 +33,13 @@ graph LR ## 📖  Step-by-Step Guide to Using Config Maker -First lets install the config-maker package + +> [!IMPORTANT] +> Before you start, you need to set up a few things. + +
+ +First, install the config-maker package: ```sh npm i config-maker @@ -43,10 +48,13 @@ npm i config-maker
-Now we need to create a config instance +Second, you need to create a config instance. + +You can create the config instance anywhere. For example, that can be done in the `config.ts` file. -You can create the config instance anywhere, for example, in the `config.ts` file. +
+### See the full code below: ```ts import { ConfigMaker } from 'config-maker'; @@ -96,7 +104,7 @@ export const config = new ConfigMaker('myConfig', { ```
-**Now let's go through the config step by step:** +### Follow the step-by-step tutorial for more details: **1.** The first generic paremeter you will be dealing with is `ProjectOptions`. It will be stored inside the config json file in the project folder while using your CLI. `myConfig` is the config file name. It will be stored in the users folder for those who use the CLI with the setting `config-maker`. @@ -113,7 +121,7 @@ type ProjectOptions = { **2.** Decoders -**`decoders`** - are only needed when a value is of a different type than that string, but we want to encode it in the config. +They are only needed when a value is of a different type than that string, but we want to encode it in the config. ```ts @@ -130,7 +138,7 @@ type ProjectOptions = { **3.** Prompts -**`prompts`** - are optional messages that are used in text and/or in `autocomplete` prompts. +They are are optional messages that are used in text and/or in `autocomplete` prompts. ```ts // messages to be used for prompts @@ -153,7 +161,7 @@ type ProjectOptions = { **4.** Autocomplete -**`autocomplete`** - are functions that return an array of strings to be used inside autocomplete +These functions are used to return an array of strings to be used inside autocomplete. ```ts config: { @@ -178,7 +186,7 @@ type ProjectOptions = {
-## **Using the Values from the Config** +## Using the Values from the Config The config object has two ways of retrieving values from the config. From 4da6f7998f06fb28a9ae7d23f2795a82b0d16f3c Mon Sep 17 00:00:00 2001 From: MagdaPuch Date: Mon, 2 Sep 2024 13:37:00 +0200 Subject: [PATCH 15/15] Redesign Readme.md --- Readme.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Readme.md b/Readme.md index 5e52c83..27ae865 100644 --- a/Readme.md +++ b/Readme.md @@ -16,16 +16,16 @@ Config Maker is a config manager to use for your interactive CLI. ## 📤  How Values Are Fetched ```mermaid -graph LR - A[Option from the Command Line] --> AY[Exists] - AY --> R[Return Value] +flowchart TD + A[Option from the Command Line] --Present--> R[Return Value] A --Not Present---> - D[Environment Variable] --> AY + D[Environment Variable] --Present--> R D --Not Present---> - E[In Config File] --> AY + E[Variable In Config File] --Present--> R E --Not Present---> - F[Prompt for the Input] --> R + F[Prompt User for Input] --> R + style R fill:#244d0e ```