elrh-cosca 0.2.4 → 0.2.6

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,49 +17,40 @@ 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
 
24
- Takes a path to a template file from your project and will create a fresh copy in target project when invoked.
24
+ Gets a file definition from given `templateFile` and will create a fresh copy in target project.
25
25
 
26
26
  Path to `templateFile` must be prefixed with the package name to allow proper resolution, e.g. `your-package:path/to/template`. The package name can be scoped.
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
 
40
- Gets a file definition from given `url` and will create a fresh copy in target project when invoked.
40
+ Gets a file definition from given `url` and will create a fresh copy in target project.
41
41
 
42
- Contents of `url` must be accessible via `node:https.get` function and will be fetched as raw string data.
42
+ Contents of `url` must be accessible via `node:https.get` function and will be fetched as raw text data.
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,30 +83,35 @@ 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
 
110
102
  #### `promptUser`
111
103
 
112
104
  ```ts
113
- async function promptUser(question: string): Promise<boolean>
105
+ async function promptUser(
106
+ question: string,
107
+ options?: { input?: NodeJS.ReadableStream; output?: NodeJS.WritableStream }
108
+ ): Promise<boolean>
114
109
  ```
115
110
 
116
111
  Prints out a `question` to the console and waits for the input. Returns `true` when `y` is pressed and `false` otherwise.
117
112
 
113
+ By default it uses `process.stdin` and `process.stdout` streams. To use custom NodeJS streams, `options` object with `input` and `output` properties can be optionally passed.
114
+
118
115
  #### `showMessage`
119
116
 
120
117
  ```ts
@@ -133,6 +130,16 @@ Prints out a `message` to `process.stderr` and adds the specified number of newl
133
130
 
134
131
  ### List of other utils
135
132
 
133
+ #### `getEnvValue`
134
+
135
+ ```ts
136
+ export function getEnvValue(
137
+ key: string, envFilePath: string = resolve(process.cwd(), '.env')
138
+ ): string | undefined
139
+ ```
140
+
141
+ 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.
142
+
136
143
  #### `parseQualifiedPath`
137
144
 
138
145
  ```ts