elrh-cosca 0.1.4 → 0.2.0
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 +87 -6
- package/dist/elrh-cosca.mjs +16333 -68
- package/dist/types/lib/update-config-file.d.ts +13 -0
- package/dist/types/lib/update-json-file.d.ts +1 -1
- package/dist/types/main.d.ts +2 -1
- package/dist/types/utils/better-deep-merge.d.ts +1 -0
- package/dist/types/utils/resolve-package.d.ts +1 -0
- package/package.json +2 -1
- package/test/cosca-test.js +11 -2
- package/dist/elrh-cosca.cjs +0 -4
package/README.md
CHANGED
|
@@ -9,15 +9,96 @@ The **"COSCA"** abbreviation stands for **CO**de **SCA**ffolding which points ou
|
|
|
9
9
|
|
|
10
10
|
`npm install elrh-cosca` to include into your project.
|
|
11
11
|
|
|
12
|
-
List of available functions
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
12
|
+
**List of available functions:**
|
|
13
|
+
|
|
14
|
+
### `createFileFromTemplate`
|
|
15
|
+
|
|
16
|
+
```ts
|
|
17
|
+
async function createFileFromTemplate(
|
|
18
|
+
templateFile: string, targetFile: string, force: boolean = false
|
|
19
|
+
): Promise<void>
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Takes a path to a template file from your project and will create a fresh copy in target project when invoked.
|
|
23
|
+
|
|
24
|
+
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.
|
|
25
|
+
|
|
26
|
+
Path to `targetFile` is relative to `process.cwd()` which allows consumers to run `npx your-script` in their project roots during development.
|
|
27
|
+
|
|
28
|
+
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
|
+
|
|
30
|
+
### `promptUser`
|
|
31
|
+
|
|
32
|
+
```ts
|
|
33
|
+
export async function promptUser(question: string): Promise<boolean>
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Prints out a `question` to the console and waits for the input. Returns `true` when `y` is pressed and `false` otherwise.
|
|
37
|
+
|
|
38
|
+
### `updateConfigFile`
|
|
39
|
+
|
|
40
|
+
```ts
|
|
41
|
+
async function updateConfigFile(
|
|
42
|
+
pathToFile: string, newConfig: Record<string | number | symbol, any>, force: boolean = false
|
|
43
|
+
): Promise<void>
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Prints out a `question` to the console and waits for the input. Returns `true` when `y` is pressed and `false` otherwise.
|
|
47
|
+
|
|
48
|
+
### `updateConfigFile`
|
|
49
|
+
|
|
50
|
+
```ts
|
|
51
|
+
async function updateConfigFile(
|
|
52
|
+
pathToFile: string, newConfig: Record<string | number | symbol, any>, force: boolean = false
|
|
53
|
+
): Promise<void>
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Takes a path to a configuration file and updates it with the provided `newConfig` object.
|
|
57
|
+
|
|
58
|
+
Path to `targetFile` is relative to `process.cwd()`. The file currently must use ESM format with either `default` or named export of **exactly one** configuration object or function call with a configuration object as its argument.
|
|
59
|
+
|
|
60
|
+
The merger is performed using [unjs/magicast](https://github.com/unjs/magicast). It should:
|
|
61
|
+
- preserve comments
|
|
62
|
+
- work recursively to allow deep-merge
|
|
63
|
+
- extend existing object with new keys from `newConfig`
|
|
64
|
+
- overwrite keys with same name with values from `newConfig`
|
|
65
|
+
- create a unique-union in case of arrays
|
|
66
|
+
Please [report](https://github.com/AloisSeckar/elrh-cosca/issues) any logical flaws and issues of the process.
|
|
67
|
+
|
|
68
|
+
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
|
+
|
|
70
|
+
### `updateJsonFile`
|
|
71
|
+
|
|
72
|
+
```ts
|
|
73
|
+
async function updateJsonFile(
|
|
74
|
+
pathToFile: string, jsonKey: string, newValues: Record<string | number | symbol, any>, force: boolean = false
|
|
75
|
+
): Promise<void>
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
Takes a path to a JSON file and injects `newValues` under `jsonKey` key.
|
|
79
|
+
|
|
80
|
+
Path to `targetFile` is relative to `process.cwd()`. The file must be a valid JSON file. It is parsed using plain `JSON.parse`.
|
|
81
|
+
|
|
82
|
+
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.
|
|
83
|
+
|
|
84
|
+
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
|
+
|
|
86
|
+
### `updateTextFile`
|
|
87
|
+
|
|
88
|
+
```ts
|
|
89
|
+
export async function updateTextFile(
|
|
90
|
+
pathToFile: string, rowsToAdd: string[], force: boolean = false
|
|
91
|
+
): Promise<void>
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
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.
|
|
95
|
+
|
|
96
|
+
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.
|
|
17
97
|
|
|
18
98
|
## Tech stack
|
|
19
99
|
|
|
20
|
-
- Developed with [TypeScript](https://www.typescriptlang.org/)
|
|
100
|
+
- Developed with [TypeScript](https://www.typescriptlang.org/) in mind
|
|
101
|
+
- Using [magicast](https://github.com/unjs/magicast) for parsing files
|
|
21
102
|
- Build with [Vite](https://vitejs.dev/)
|
|
22
103
|
- Tested with [Vitest](https://vitest.dev/)
|
|
23
104
|
|