elrh-cosca 0.2.3 → 0.2.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -17,7 +17,7 @@ The **"COSCA"** abbreviation stands for **CO**de **SCA**ffolding which points ou
17
17
 
18
18
  ```ts
19
19
  async function createFileFromTemplate(
20
- templateFile: string, targetFile: string, force: boolean = false
20
+ templateFile: string, targetFile: string, force: boolean = false, prompt: string = ''
21
21
  ): Promise<void>
22
22
  ```
23
23
 
@@ -27,13 +27,13 @@ Path to `templateFile` must be prefixed with the package name to allow proper re
27
27
 
28
28
  Path to `targetFile` is relative to `process.cwd()` which allows consumers to run `npx your-script` in their project roots during development.
29
29
 
30
- By default the function asks for confirmation before attempting to create the file and if the file with the same name as `targetFile` is detected. Setting the last optional parameter `force` to `true` will suppress manual confirmation prompts.
30
+ By default the function asks for confirmation before attempting to create the file and if the file with the same name as `targetFile` is detected. Setting the last optional parameter `force` to `true` will suppress manual confirmation prompts. Passsing a custom `prompt` allows tailoring your own question to the user.
31
31
 
32
32
  #### `createFileFromWebTemplate`
33
33
 
34
34
  ```ts
35
35
  async function createFileWebFromTemplate(
36
- url: string, targetFile: string, force: boolean = false
36
+ url: string, targetFile: string, force: boolean = false, prompt: string = ''
37
37
  ): Promise<void>
38
38
  ```
39
39
 
@@ -43,23 +43,14 @@ Contents of `url` must be accessible via `node:https.get` function and will be f
43
43
 
44
44
  Path to `targetFile` is relative to `process.cwd()` which allows consumers to run `npx your-script` in their project roots during development.
45
45
 
46
- By default the function asks for confirmation before attempting to create the file and if the file with the same name as `targetFile` is detected. Setting the last optional parameter `force` to `true` will suppress manual confirmation prompts.
46
+ By default the function asks for confirmation before attempting to create the file and if the file with the same name as `targetFile` is detected. Setting the last optional parameter `force` to `true` will suppress manual confirmation prompts. Passsing a custom `prompt` allows tailoring your own question to the user.
47
47
 
48
48
  #### `updateConfigFile`
49
49
 
50
50
  ```ts
51
51
  async function updateConfigFile(
52
- pathToFile: string, newConfig: Record<string | number | symbol, any>, force: boolean = false
53
- ): Promise<void>
54
- ```
55
-
56
- Prints out a `question` to the console and waits for the input. Returns `true` when `y` is pressed and `false` otherwise.
57
-
58
- #### `updateConfigFile`
59
-
60
- ```ts
61
- async function updateConfigFile(
62
- pathToFile: string, newConfig: Record<string | number | symbol, any>, force: boolean = false
52
+ pathToFile: string, newConfig: Record<string | number | symbol, any>,
53
+ force: boolean = false, prompt: string = ''
63
54
  ): Promise<void>
64
55
  ```
65
56
 
@@ -75,13 +66,14 @@ The merger is performed using [unjs/magicast](https://github.com/unjs/magicast).
75
66
  - create a unique-union in case of arrays
76
67
  Please [report](https://github.com/AloisSeckar/elrh-cosca/issues) any logical flaws and issues of the process.
77
68
 
78
- By default the function asks for confirmation before attempting to alter the `targetFile`. Setting the last optional parameter `force` to `true` will suppress manual confirmation prompts.
69
+ By default the function asks for confirmation before attempting to alter the `targetFile`. Setting the last optional parameter `force` to `true` will suppress manual confirmation prompts. Passsing a custom `prompt` allows tailoring your own question to the user.
79
70
 
80
71
  #### `updateJsonFile`
81
72
 
82
73
  ```ts
83
74
  async function updateJsonFile(
84
- pathToFile: string, jsonKey: string, newValues: Record<string | number | symbol, any>, force: boolean = false
75
+ pathToFile: string, jsonKey: string, newValues: Record<string | number | symbol, any>,
76
+ force: boolean = false, prompt: string = ''
85
77
  ): Promise<void>
86
78
  ```
87
79
 
@@ -91,19 +83,19 @@ Path to `targetFile` is relative to `process.cwd()`. The file must be a valid JS
91
83
 
92
84
  Currently it only allows adding new values under top-level keys. If the `jsonKey` exists, new values are merged into existing ones. Otherwise, new key is added. The function tracks if any real change was made and notifies the user if not.
93
85
 
94
- By default the function asks for confirmation before attempting to alter the `targetFile`. Setting the last optional parameter `force` to `true` will suppress manual confirmation prompts.
86
+ By default the function asks for confirmation before attempting to alter the `targetFile`. Setting the last optional parameter `force` to `true` will suppress manual confirmation prompts. Passsing a custom `prompt` allows tailoring your own question to the user.
95
87
 
96
88
  #### `updateTextFile`
97
89
 
98
90
  ```ts
99
91
  async function updateTextFile(
100
- pathToFile: string, rowsToAdd: string[], force: boolean = false
92
+ pathToFile: string, rowsToAdd: string[], force: boolean = false, prompt: string = ''
101
93
  ): Promise<void>
102
94
  ```
103
95
 
104
96
  Takes a path to a plain text file and injects `rowsToAdd` at the end of the file, **providing they are not already present in the file**. The function tracks if any real change was made and notifies the user if not.
105
97
 
106
- By default the function asks for confirmation before attempting to alter the `targetFile`. Setting the last optional parameter `force` to `true` will suppress manual confirmation prompts.
98
+ By default the function asks for confirmation before attempting to alter the `targetFile`. Setting the last optional parameter `force` to `true` will suppress manual confirmation prompts. Passsing a custom `prompt` allows tailoring your own question to the user.
107
99
 
108
100
  ### List of terminal helpers
109
101
 
@@ -133,6 +125,16 @@ Prints out a `message` to `process.stderr` and adds the specified number of newl
133
125
 
134
126
  ### List of other utils
135
127
 
128
+ #### `getEnvValue`
129
+
130
+ ```ts
131
+ export function getEnvValue(
132
+ key: string, envFilePath: string = resolve(process.cwd(), '.env')
133
+ ): string | undefined
134
+ ```
135
+
136
+ Reads a `.env` file and returns the value of the specified key or `undefined` if key not found. By default it reads from `.env` in the current working directory (usually the root of the project). You can specify a custom path to `.env` file as the second `envFilePath` parameter.
137
+
136
138
  #### `parseQualifiedPath`
137
139
 
138
140
  ```ts