elrh-cosca 0.2.7 → 0.3.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 +56 -8
- package/dist/elrh-cosca.mjs +3575 -3481
- package/dist/types/_private/check-path.d.ts +4 -0
- package/dist/types/functions/delete-path.d.ts +10 -0
- package/dist/types/functions/remove-from-json-file.d.ts +11 -0
- package/dist/types/functions/update-config-file.d.ts +2 -2
- package/dist/types/functions/update-json-file.d.ts +4 -3
- package/dist/types/functions/update-text-file.d.ts +2 -2
- package/dist/types/main.d.ts +3 -1
- package/dist/types/types/json.d.ts +6 -0
- package/package.json +1 -1
- package/test/cosca-test.js +8 -1
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Deletes given path from FS.
|
|
3
|
+
*
|
|
4
|
+
* @param {string} targetPath - The path to the JSON file to update (relative to CWD).
|
|
5
|
+
* @param {boolean} force - Whether to force the update without prompting.
|
|
6
|
+
* @param {string} prompt - Custom prompt message displayed in terminal.
|
|
7
|
+
* @returns {Promise<void>} An empty promise that resolves when the file is updated.
|
|
8
|
+
* @throws Will throw an error if the file does not exist or cannot be parsed as JSON.
|
|
9
|
+
*/
|
|
10
|
+
export declare function deletePath(targetPath: string, force?: boolean, prompt?: string): Promise<void>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Updates a JSON file by deleting a specified key.
|
|
3
|
+
*
|
|
4
|
+
* @param {string} targetFile - The path to the JSON file to update (relative to CWD).
|
|
5
|
+
* @param {string} jsonKey - The key in the JSON file to be deleted (may use dot notation for nested keys).
|
|
6
|
+
* @param {boolean} force - Whether to force the update without prompting.
|
|
7
|
+
* @param {string} prompt - Custom prompt message displayed in terminal.
|
|
8
|
+
* @returns {Promise<void>} An empty promise that resolves when the file is updated.
|
|
9
|
+
* @throws Will throw an error if the file does not exist or cannot be parsed as JSON.
|
|
10
|
+
*/
|
|
11
|
+
export declare function removeFromJsonFile(targetFile: string, jsonKey: string, force?: boolean, prompt?: string): Promise<void>;
|
|
@@ -6,9 +6,9 @@
|
|
|
6
6
|
* - Uses `defu(newConfig, existingConfig)` so `newConfig` takes precedence.
|
|
7
7
|
* - Applies the merged result back onto the AST to preserve TS/ESM structure.
|
|
8
8
|
*
|
|
9
|
-
* @param {string}
|
|
9
|
+
* @param {string} targetFile - Path to file, relative to project root (process.cwd()).
|
|
10
10
|
* @param {object} newConfig - Config to merge in (takes precedence).
|
|
11
11
|
* @returns {Promise<void>} An empty promise that resolves when the file is updated.
|
|
12
12
|
* @throws Will throw an error if no config export is found or it cannot be processed.
|
|
13
13
|
*/
|
|
14
|
-
export declare function updateConfigFile(
|
|
14
|
+
export declare function updateConfigFile(targetFile: string, newConfig: Record<string | number | symbol, any>, force?: boolean, prompt?: string): Promise<void>;
|
|
@@ -1,12 +1,13 @@
|
|
|
1
|
+
import { JsonValue } from '../types/json.js';
|
|
1
2
|
/**
|
|
2
3
|
* Updates a JSON file by modifying a specific key with new values.
|
|
3
4
|
*
|
|
4
|
-
* @param {string}
|
|
5
|
+
* @param {string} targetFile - The path to the JSON file to update (relative to CWD).
|
|
5
6
|
* @param {string} jsonKey - The key in the JSON file to update (can be new or existing).
|
|
6
|
-
* @param {
|
|
7
|
+
* @param {JsonPrimitive} patch - The new values to set for the specified key.
|
|
7
8
|
* @param {boolean} force - Whether to force the update without prompting.
|
|
8
9
|
* @param {string} prompt - Custom prompt message displayed in terminal.
|
|
9
10
|
* @returns {Promise<void>} An empty promise that resolves when the file is updated.
|
|
10
11
|
* @throws Will throw an error if the file does not exist or cannot be parsed as JSON.
|
|
11
12
|
*/
|
|
12
|
-
export declare function updateJsonFile(
|
|
13
|
+
export declare function updateJsonFile(targetFile: string, jsonKey: string, patch: JsonValue, force?: boolean, prompt?: string): Promise<void>;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Updates a text file by adding new rows.
|
|
3
3
|
*
|
|
4
|
-
* @param {string}
|
|
4
|
+
* @param {string} targetFile - The path to the text file to update (relative to CWD).
|
|
5
5
|
* @param {string[]} rowsToAdd - New rows to be added at the end of the file.
|
|
6
6
|
* @param {boolean} force - Whether to force the update without prompting.
|
|
7
7
|
* @param {string} prompt - Custom prompt message displayed in terminal.
|
|
8
8
|
* @returns {Promise<void>} An empty promise that resolves when the file is updated.
|
|
9
9
|
* @throws Will throw an error if the file does not exist.
|
|
10
10
|
*/
|
|
11
|
-
export declare function updateTextFile(
|
|
11
|
+
export declare function updateTextFile(targetFile: string, rowsToAdd: string[], force?: boolean, prompt?: string): Promise<void>;
|
package/dist/types/main.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { createFileFromTemplate } from './functions/create-file-from-template';
|
|
2
2
|
import { createFileFromWebTemplate } from './functions/create-file-from-web-template';
|
|
3
|
+
import { deletePath } from './functions/delete-path';
|
|
4
|
+
import { removeFromJsonFile } from './functions/remove-from-json-file';
|
|
3
5
|
import { updateConfigFile } from './functions/update-config-file';
|
|
4
6
|
import { updateJsonFile } from './functions/update-json-file';
|
|
5
7
|
import { updateTextFile } from './functions/update-text-file';
|
|
@@ -9,4 +11,4 @@ import { showMessage } from './terminal/show-message';
|
|
|
9
11
|
import { getEnvValue } from './utils/get-env-value';
|
|
10
12
|
import { parseQualifiedPath } from './utils/parse-qualified-path';
|
|
11
13
|
import { resolvePackagePath } from './utils/resolve-package-path';
|
|
12
|
-
export { createFileFromTemplate, createFileFromWebTemplate, updateConfigFile, updateJsonFile, updateTextFile, promptUser, showError, showMessage, getEnvValue, parseQualifiedPath, resolvePackagePath, };
|
|
14
|
+
export { createFileFromTemplate, createFileFromWebTemplate, deletePath, removeFromJsonFile, updateConfigFile, updateJsonFile, updateTextFile, promptUser, showError, showMessage, getEnvValue, parseQualifiedPath, resolvePackagePath, };
|
package/package.json
CHANGED
package/test/cosca-test.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
import {
|
|
6
6
|
createFileFromTemplate, createFileFromWebTemplate, promptUser, showError, showMessage,
|
|
7
|
-
updateConfigFile, getEnvValue, updateJsonFile, updateTextFile
|
|
7
|
+
updateConfigFile, getEnvValue, updateJsonFile, updateTextFile, deletePath, removeFromJsonFile
|
|
8
8
|
} from '../dist/elrh-cosca.mjs'
|
|
9
9
|
|
|
10
10
|
async function main() {
|
|
@@ -37,9 +37,16 @@ async function main() {
|
|
|
37
37
|
|
|
38
38
|
console.log('\nTest updateJsonFile')
|
|
39
39
|
await updateJsonFile('test/fixtures/json-file.json', 'scripts', { 'cosca' : 'cosca' })
|
|
40
|
+
await updateJsonFile('test/fixtures/json-file.json', 'packageManager', 'pnpm' )
|
|
41
|
+
|
|
42
|
+
console.log('\nTest removeFromJsonFile')
|
|
43
|
+
await removeFromJsonFile('test/fixtures/json-file.json', 'cosca')
|
|
40
44
|
|
|
41
45
|
console.log('\nTest updateTextFile')
|
|
42
46
|
await updateTextFile('test/fixtures/text-file.txt', ['# COSCA'])
|
|
47
|
+
|
|
48
|
+
console.log('\nTest deletePath')
|
|
49
|
+
await deletePath('test/snapshots/test.file1')
|
|
43
50
|
}
|
|
44
51
|
|
|
45
52
|
main().catch((err) => {
|