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 +50 -10
- package/dist/elrh-cosca.mjs +847 -801
- package/dist/types/_private/fetch-file.d.ts +1 -0
- package/dist/types/functions/create-file-from-web-template.d.ts +1 -0
- package/dist/types/main.d.ts +9 -6
- package/dist/types/utils/parse-qualified-path.d.ts +8 -0
- package/dist/types/utils/resolve-package-path.d.ts +6 -0
- package/package.json +1 -3
- package/test/cosca-test.js +11 -12
- package/dist/types/utils/resolve-package.d.ts +0 -14
- package/dist/types/utils/resolve-path.d.ts +0 -12
- /package/dist/types/{utils/better-deep-merge.d.ts → _private/deep-merge-object.d.ts} +0 -0
- /package/dist/types/{lib → functions}/create-file-from-template.d.ts +0 -0
- /package/dist/types/{lib → functions}/update-config-file.d.ts +0 -0
- /package/dist/types/{lib → functions}/update-json-file.d.ts +0 -0
- /package/dist/types/{lib → functions}/update-text-file.d.ts +0 -0
- /package/dist/types/{lib → terminal}/prompt-user.d.ts +0 -0
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
|
-
|
|
14
|
+
### List of file-manipulation functions
|
|
13
15
|
|
|
14
|
-
|
|
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
|
-
|
|
32
|
+
#### `createFileFromWebTemplate`
|
|
31
33
|
|
|
32
34
|
```ts
|
|
33
|
-
|
|
35
|
+
async function createFileWebFromTemplate(
|
|
36
|
+
url: string, targetFile: string, force: boolean = false
|
|
37
|
+
): Promise<void>
|
|
34
38
|
```
|
|
35
39
|
|
|
36
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
96
|
+
#### `updateTextFile`
|
|
87
97
|
|
|
88
98
|
```ts
|
|
89
|
-
|
|
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:
|