elrh-cosca 0.2.0 → 0.2.2

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
@@ -7,11 +7,13 @@ The **"COSCA"** abbreviation stands for **CO**de **SCA**ffolding which points ou
7
7
 
8
8
  ## How to use
9
9
 
10
+ **NOTE:** The library is **ESM only** and it is advised to use with at least **Node 18**.
11
+
10
12
  `npm install elrh-cosca` to include into your project.
11
13
 
12
- **List of available functions:**
14
+ ### List of file-manipulation functions
13
15
 
14
- ### `createFileFromTemplate`
16
+ #### `createFileFromTemplate`
15
17
 
16
18
  ```ts
17
19
  async function createFileFromTemplate(
@@ -27,15 +29,23 @@ Path to `targetFile` is relative to `process.cwd()` which allows consumers to ru
27
29
 
28
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.
29
31
 
30
- ### `promptUser`
32
+ #### `createFileFromWebTemplate`
31
33
 
32
34
  ```ts
33
- export async function promptUser(question: string): Promise<boolean>
35
+ async function createFileWebFromTemplate(
36
+ url: string, targetFile: string, force: boolean = false
37
+ ): Promise<void>
34
38
  ```
35
39
 
36
- Prints out a `question` to the console and waits for the input. Returns `true` when `y` is pressed and `false` otherwise.
40
+ Gets a file definition from given `url` and will create a fresh copy in target project when invoked.
41
+
42
+ Contents of `url` must be accessible via `node:https.get` function and will be fetched as raw string data.
43
+
44
+ Path to `targetFile` is relative to `process.cwd()` which allows consumers to run `npx your-script` in their project roots during development.
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.
37
47
 
38
- ### `updateConfigFile`
48
+ #### `updateConfigFile`
39
49
 
40
50
  ```ts
41
51
  async function updateConfigFile(
@@ -45,7 +55,7 @@ async function updateConfigFile(
45
55
 
46
56
  Prints out a `question` to the console and waits for the input. Returns `true` when `y` is pressed and `false` otherwise.
47
57
 
48
- ### `updateConfigFile`
58
+ #### `updateConfigFile`
49
59
 
50
60
  ```ts
51
61
  async function updateConfigFile(
@@ -67,7 +77,7 @@ Please [report](https://github.com/AloisSeckar/elrh-cosca/issues) any logical fl
67
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
79
 
70
- ### `updateJsonFile`
80
+ #### `updateJsonFile`
71
81
 
72
82
  ```ts
73
83
  async function updateJsonFile(
@@ -83,10 +93,10 @@ Currently it only allows adding new values under top-level keys. If the `jsonKey
83
93
 
84
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.
85
95
 
86
- ### `updateTextFile`
96
+ #### `updateTextFile`
87
97
 
88
98
  ```ts
89
- export async function updateTextFile(
99
+ async function updateTextFile(
90
100
  pathToFile: string, rowsToAdd: string[], force: boolean = false
91
101
  ): Promise<void>
92
102
  ```
@@ -95,6 +105,34 @@ Takes a path to a plain text file and injects `rowsToAdd` at the end of the file
95
105
 
96
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.
97
107
 
108
+ ### List of terminal helpers
109
+
110
+ #### `promptUser`
111
+
112
+ ```ts
113
+ async function promptUser(question: string): Promise<boolean>
114
+ ```
115
+
116
+ Prints out a `question` to the console and waits for the input. Returns `true` when `y` is pressed and `false` otherwise.
117
+
118
+ ### List of other utils
119
+
120
+ #### `parseQualifiedPath`
121
+
122
+ ```ts
123
+ function parseQualifiedPath(path: string): { pkg: string; file: string }
124
+ ```
125
+
126
+ Expects path to file in `"package:relative/path/to/file"` format and splits it into `{ pkg, file }`. The package name can be scoped (e.g. `@scope/package`).
127
+
128
+ #### `resolvePackagePath`
129
+
130
+ ```ts
131
+ function resolvePackagePath(pkg: string): string
132
+ ```
133
+
134
+ Resolve a package's installed root directory *from the target app* - which can be either from within itself during development or from corresponding package dir inside *node_modules*. The package name can be scoped (e.g. `@scope/package`).
135
+
98
136
  ## Tech stack
99
137
 
100
138
  - Developed with [TypeScript](https://www.typescriptlang.org/) in mind
@@ -102,6 +140,8 @@ By default the function asks for confirmation before attempting to alter the `ta
102
140
  - Build with [Vite](https://vitejs.dev/)
103
141
  - Tested with [Vitest](https://vitest.dev/)
104
142
 
143
+ See [Changelog](https://github.com/AloisSeckar/elrh-cosca/blob/main/CHANGELOG.md) for project history and development.
144
+
105
145
  ## Report bugs & contact
106
146
 
107
147
  Use GitHub issues to report bugs / propose enhancements / give feedback: