elrh-cosca 0.3.6 → 0.4.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.
Files changed (39) hide show
  1. package/README.md +237 -99
  2. package/dist/chunks/magicast-B0ixXlDw.mjs +14033 -0
  3. package/dist/chunks/rolldown-runtime-Dqa2HsxW.mjs +20 -0
  4. package/dist/chunks/yaml-BwPmYYDT.mjs +4297 -0
  5. package/dist/elrh-cosca.mjs +328 -14157
  6. package/dist/types/src/_private/fetch-file.d.ts +1 -1
  7. package/dist/types/src/checks/get-package-manager.d.ts +2 -2
  8. package/dist/types/src/checks/has-json-key.d.ts +5 -3
  9. package/dist/types/src/checks/has-text.d.ts +6 -4
  10. package/dist/types/src/checks/has-yaml-key.d.ts +11 -0
  11. package/dist/types/src/checks/path-exists.d.ts +6 -4
  12. package/dist/types/src/functions/create-file-from-template.d.ts +10 -8
  13. package/dist/types/src/functions/create-file-from-web-template.d.ts +10 -8
  14. package/dist/types/src/functions/delete-path.d.ts +9 -7
  15. package/dist/types/src/functions/remove-from-json-file.d.ts +8 -6
  16. package/dist/types/src/functions/remove-from-text-file.d.ts +8 -6
  17. package/dist/types/src/functions/remove-from-yaml-file.d.ts +13 -0
  18. package/dist/types/src/functions/update-config-file.d.ts +13 -7
  19. package/dist/types/src/functions/update-json-file.d.ts +12 -10
  20. package/dist/types/src/functions/update-text-file.d.ts +11 -7
  21. package/dist/types/src/functions/update-yaml-file.d.ts +15 -0
  22. package/dist/types/src/main.d.ts +5 -1
  23. package/dist/types/src/terminal/prompt-user.d.ts +8 -8
  24. package/dist/types/src/terminal/show-error.d.ts +5 -3
  25. package/dist/types/src/terminal/show-message.d.ts +5 -3
  26. package/dist/types/src/types/data.d.ts +6 -0
  27. package/dist/types/src/types/functions.d.ts +99 -0
  28. package/dist/types/src/utils/get-env-value.d.ts +6 -4
  29. package/dist/types/src/utils/parse-qualified-path.d.ts +4 -2
  30. package/dist/types/src/utils/resolve-package-path.d.ts +7 -5
  31. package/dist/types/test/checks-has-yaml-key.test.d.ts +1 -0
  32. package/dist/types/test/functions-remove-from-yaml-file.test.d.ts +1 -0
  33. package/dist/types/test/functions-update-yaml-file.test.d.ts +1 -0
  34. package/dist/types/test/private-deep-merge-object.test.d.ts +1 -0
  35. package/dist/types/test/private-fetch-file.test.d.ts +1 -0
  36. package/dist/types/test/snapshots/created-config-file.d.ts +7 -0
  37. package/package.json +15 -11
  38. package/test/cosca-test.js +17 -17
  39. package/dist/types/src/types/json.d.ts +0 -6
@@ -1 +1 @@
1
- export declare function fetchFile(url: string): Promise<string>;
1
+ export declare function fetchFile(url: string, redirectsLeft?: number): Promise<string>;
@@ -1,6 +1,6 @@
1
1
  /**
2
- * Checks what package manager was used to execute the current command.
2
+ * Checks what package manager/runtime was used to execute the current command.
3
3
  *
4
- * @returns {string} The name of the package manager used ('npm', 'yarn', 'pnpm', 'deno' or 'bun').
4
+ * @returns {'npm' | 'yarn' | 'pnpm' | 'deno' | 'bun'} The name of the package manager used (falls back to 'npm' if detection failed).
5
5
  */
6
6
  export declare function getPackageManager(): 'npm' | 'yarn' | 'pnpm' | 'deno' | 'bun';
@@ -1,9 +1,11 @@
1
+ import { HasJsonKeyOptions } from '../types/functions.js';
1
2
  /**
2
3
  * Checks if a JSON file contains specified key.
3
4
  *
4
- * @param {string} targetFile - The path to the JSON file to be checked (relative to CWD).
5
- * @param {string} jsonKey - The key in the JSON file to be checked for existence (may use dot notation for nested keys).
5
+ * @param {HasJsonKeyOptions} opts - Options for this operation.
6
+ * @param {string} opts.targetFile - The path to the JSON file to be checked (relative to CWD).
7
+ * @param {string} opts.jsonKey - The key in the JSON file to be checked for existence (may use dot notation for nested keys).
6
8
  * @returns {boolean} True if the key exists in target file, false otherwise.
7
9
  * @throws Will throw an error if the path is invalid, file does not exist or cannot be parsed as JSON.
8
10
  */
9
- export declare function hasJsonKey(targetFile: string, jsonKey: string): boolean;
11
+ export declare function hasJsonKey(opts: HasJsonKeyOptions): boolean;
@@ -1,10 +1,12 @@
1
+ import { HasTextOptions } from '../types/functions.js';
1
2
  /**
2
3
  * Checks if a text file contains specified text.
3
4
  *
4
- * @param {string} targetFile - The path to the text file to be checked (relative to CWD).
5
- * @param {string | RegExp} pattern - The text or regular expression pattern to search for.
6
- * @param {boolean} exact - If true, requires exact line match (default: false for partial matching).
5
+ * @param {HasTextOptions} opts - Options for this operation.
6
+ * @param {string} opts.targetFile - The path to the text file to be checked (relative to CWD).
7
+ * @param {string | RegExp} opts.pattern - The text or regular expression pattern to search for (lines and text pattern are trimmed before matching).
8
+ * @param {boolean} [opts.exact] - If true, a text pattern must match a whole line; ignored for RegExp patterns (default: false).
7
9
  * @returns {boolean} True if the pattern is found in target file, false otherwise.
8
10
  * @throws Will throw an error if the path is invalid or the file does not exist.
9
11
  */
10
- export declare function hasText(targetFile: string, pattern: string | RegExp, exact?: boolean): boolean;
12
+ export declare function hasText(opts: HasTextOptions): boolean;
@@ -0,0 +1,11 @@
1
+ import { HasYamlKeyOptions } from '../types/functions.js';
2
+ /**
3
+ * Checks if a YAML file contains specified key.
4
+ *
5
+ * @param {HasYamlKeyOptions} opts - Options for this operation.
6
+ * @param {string} opts.targetFile - The path to the YAML file to be checked (relative to CWD).
7
+ * @param {string} opts.yamlKey - The key in the YAML file to be checked for existence (may use dot notation for nested keys).
8
+ * @returns {Promise<boolean>} A promise resolving to true if the key exists in target file, false otherwise.
9
+ * @throws Will throw an error if the path is invalid, file does not exist or cannot be parsed as YAML.
10
+ */
11
+ export declare function hasYamlKey(opts: HasYamlKeyOptions): Promise<boolean>;
@@ -1,8 +1,10 @@
1
+ import { PathExistsOptions } from '../types/functions.js';
1
2
  /**
2
- * Checks if the specified path exists on FS.
3
+ * Checks if the specified path exists on FS. The search is limited to CWD.
3
4
  *
4
- * @param {string} targetPath - The path on FS to be checked (relative to CWD).
5
+ * @param {PathExistsOptions} opts - Options for this operation.
6
+ * @param {string} opts.targetPath - The path to the file or directory to be checked (relative to CWD).
5
7
  * @returns {boolean} True if the path exists, false otherwise.
6
- * @throws Will throw an error if the path is invalid (can't traverse past CWD).
8
+ * @throws Will throw an error if the path is invalid.
7
9
  */
8
- export declare function pathExists(targetPath: string): boolean;
10
+ export declare function pathExists(opts: PathExistsOptions): boolean;
@@ -1,11 +1,13 @@
1
+ import { CreateFileFromTemplateOptions } from '../types/functions.js';
1
2
  /**
2
- * Creates a new copy of given file from a local template.
3
+ * Creates a new file as a copy of a template file from an installed package.
3
4
  *
4
- * @param {string} templateFile - The path to the template file (prefixed with package name).
5
- * @param {string} targetFile - The path to the target file to create (relative to CWD). Can overwrite existing files if confirmed.
6
- * @param {boolean} force - Whether to force creation 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 created.
9
- * @throws Will throw an error if the path is invalid, the template file cannot be found or the target file failed to be created.
5
+ * @param {CreateFileFromTemplateOptions} opts - Options for this operation.
6
+ * @param {string} opts.templateFile - The path to the template file in `package:relative/path/to/file` format (relative to the package root).
7
+ * @param {string} opts.targetFile - The path to the file to create (relative to CWD). Existing file is overwritten after confirmation.
8
+ * @param {boolean} [opts.force] - If true, skips all confirmation prompts (default: false).
9
+ * @param {string} [opts.prompt] - Custom text of the initial confirmation question (default: built-in question).
10
+ * @returns {Promise<void>} A promise that resolves when the operation is finished or skipped.
11
+ * @throws Will throw an error if the path is invalid, the template path cannot be parsed, the package or the template file cannot be found or the target file failed to be created.
10
12
  */
11
- export declare function createFileFromTemplate(templateFile: string, targetFile: string, force?: boolean, prompt?: string): Promise<void>;
13
+ export declare function createFileFromTemplate(opts: CreateFileFromTemplateOptions): Promise<void>;
@@ -1,11 +1,13 @@
1
+ import { CreateFileFromWebTemplateOptions } from '../types/functions.js';
1
2
  /**
2
- * Creates a new copy of given file from a web template.
3
+ * Creates a new file as a copy of a template file downloaded from the web.
3
4
  *
4
- * @param {string} url - The URL to the template file (must be accessible via `node:https.get` and return raw text data).
5
- * @param {string} targetFile - The path to the target file to create (relative to CWD). Can overwrite existing files if confirmed.
6
- * @param {boolean} force - Whether to force creation 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 created.
9
- * @throws Will throw an error if the path is invalid, the remote template cannot be fetched or the target file failed to be created.
5
+ * @param {CreateFileFromWebTemplateOptions} opts - Options for this operation.
6
+ * @param {string} opts.url - The URL of the template file (must be accessible via `node:https.get` and return raw text data; HTTPS redirects are followed).
7
+ * @param {string} opts.targetFile - The path to the file to create (relative to CWD). Existing file is overwritten after confirmation.
8
+ * @param {boolean} [opts.force] - If true, skips all confirmation prompts (default: false).
9
+ * @param {string} [opts.prompt] - Custom text of the initial confirmation question (default: built-in question).
10
+ * @returns {Promise<void>} A promise that resolves when the operation is finished or skipped.
11
+ * @throws Will throw an error if the path is invalid, the template file cannot be fetched or the target file failed to be created.
10
12
  */
11
- export declare function createFileFromWebTemplate(url: string, targetFile: string, force?: boolean, prompt?: string): Promise<void>;
13
+ export declare function createFileFromWebTemplate(opts: CreateFileFromWebTemplateOptions): Promise<void>;
@@ -1,10 +1,12 @@
1
+ import { DeletePathOptions } from '../types/functions.js';
1
2
  /**
2
- * Deletes given path from FS.
3
+ * Deletes a file or a directory (recursively) from FS.
3
4
  *
4
- * @param {string} targetPath - The path to delete (relative to CWD).
5
- * @param {boolean} force - Whether to force the deletion without prompting.
6
- * @param {string} prompt - Custom prompt message displayed in terminal.
7
- * @returns {Promise<void>} An empty promise that resolves when the path is deleted.
8
- * @throws Will throw an error if the path is invalid.
5
+ * @param {DeletePathOptions} opts - Options for this operation.
6
+ * @param {string} opts.targetPath - The path to the file or directory to delete (relative to CWD).
7
+ * @param {boolean} [opts.force] - If true, skips all confirmation prompts (default: false).
8
+ * @param {string} [opts.prompt] - Custom text of the initial confirmation question (default: built-in question).
9
+ * @returns {Promise<void>} A promise that resolves when the operation is finished or skipped.
10
+ * @throws Will throw an error if the path is invalid or the path failed to be deleted.
9
11
  */
10
- export declare function deletePath(targetPath: string, force?: boolean, prompt?: string): Promise<void>;
12
+ export declare function deletePath(opts: DeletePathOptions): Promise<void>;
@@ -1,11 +1,13 @@
1
+ import { RemoveFromJsonFileOptions } from '../types/functions.js';
1
2
  /**
2
3
  * Updates a JSON file by deleting a specified key.
3
4
  *
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.
5
+ * @param {RemoveFromJsonFileOptions} opts - Options for this operation.
6
+ * @param {string} opts.targetFile - The path to the JSON file to update (relative to CWD).
7
+ * @param {string} opts.jsonKey - The key in the JSON file to be deleted (may use dot notation for nested keys).
8
+ * @param {boolean} [opts.force] - If true, skips all confirmation prompts (default: false).
9
+ * @param {string} [opts.prompt] - Custom text of the initial confirmation question (default: built-in question).
10
+ * @returns {Promise<void>} A promise that resolves when the operation is finished or skipped.
9
11
  * @throws Will throw an error if the path is invalid, the file does not exist or cannot be parsed as JSON.
10
12
  */
11
- export declare function removeFromJsonFile(targetFile: string, jsonKey: string, force?: boolean, prompt?: string): Promise<void>;
13
+ export declare function removeFromJsonFile(opts: RemoveFromJsonFileOptions): Promise<void>;
@@ -1,11 +1,13 @@
1
+ import { RemoveFromTextFileOptions } from '../types/functions.js';
1
2
  /**
2
3
  * Removes lines from a text file that include the given search text.
3
4
  *
4
- * @param {string} targetFile - The path to the text file to update (relative to CWD).
5
- * @param {string} searchText - The text to search for; any line that includes this text will be removed.
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.
5
+ * @param {RemoveFromTextFileOptions} opts - Options for this operation.
6
+ * @param {string} opts.targetFile - The path to the text file to update (relative to CWD).
7
+ * @param {string} opts.searchText - The text to search for; any line that includes this text will be removed.
8
+ * @param {boolean} [opts.force] - If true, skips all confirmation prompts (default: false).
9
+ * @param {string} [opts.prompt] - Custom text of the initial confirmation question (default: built-in question).
10
+ * @returns {Promise<void>} A promise that resolves when the operation is finished or skipped.
9
11
  * @throws Will throw an error if the path is invalid or the file does not exist.
10
12
  */
11
- export declare function removeFromTextFile(targetFile: string, searchText: string, force?: boolean, prompt?: string): Promise<void>;
13
+ export declare function removeFromTextFile(opts: RemoveFromTextFileOptions): Promise<void>;
@@ -0,0 +1,13 @@
1
+ import { RemoveFromYamlFileOptions } from '../types/functions.js';
2
+ /**
3
+ * Updates a YAML file by deleting a specified key. Comments and formatting of untouched parts are preserved.
4
+ *
5
+ * @param {RemoveFromYamlFileOptions} opts - Options for this operation.
6
+ * @param {string} opts.targetFile - The path to the YAML file to update (relative to CWD).
7
+ * @param {string} opts.yamlKey - The key in the YAML file to be deleted (may use dot notation for nested keys).
8
+ * @param {boolean} [opts.force] - If true, skips all confirmation prompts (default: false).
9
+ * @param {string} [opts.prompt] - Custom text of the initial confirmation question (default: built-in question).
10
+ * @returns {Promise<void>} A promise that resolves when the operation is finished or skipped.
11
+ * @throws Will throw an error if the path is invalid, the file does not exist or cannot be parsed as YAML.
12
+ */
13
+ export declare function removeFromYamlFile(opts: RemoveFromYamlFileOptions): Promise<void>;
@@ -1,14 +1,20 @@
1
+ import { UpdateConfigFileOptions } from '../types/functions.js';
1
2
  /**
2
- * Update the single object-literal config found in a file.
3
+ * Updates the config object exported from a JS/TS config file.
3
4
  *
4
5
  * The function:
5
6
  * - Reads and edits the file as code (no execution).
6
- * - Uses `defu(newConfig, existingConfig)` so `newConfig` takes precedence.
7
+ * - Uses the default export or a single named export; the config may be a plain object or the first argument of a function call (e.g. `defineConfig({...})`).
8
+ * - Deep-merges `newConfig` into the existing config, so `newConfig` takes precedence; arrays are merged as a unique union.
7
9
  * - Applies the merged result back onto the AST to preserve TS/ESM structure.
8
10
  *
9
- * @param {string} targetFile - Path to file, relative to project root (process.cwd()).
10
- * @param {object} newConfig - Config to merge in (takes precedence).
11
- * @returns {Promise<void>} An empty promise that resolves when the file is updated.
12
- * @throws Will throw an error the path is invalid, the file doesn't exist or no config export is found or it cannot be processed.
11
+ * @param {UpdateConfigFileOptions} opts - Options for this operation.
12
+ * @param {string} opts.targetFile - The path to the config file to update (relative to CWD).
13
+ * @param {Record<string | number | symbol, any>} opts.newConfig - The config to merge in (takes precedence).
14
+ * @param {boolean} [opts.createMissing] - If true, the file is created (with `export default {}`) when it does not exist, after confirmation unless `force` is set (default: false).
15
+ * @param {boolean} [opts.force] - If true, skips all confirmation prompts (default: false).
16
+ * @param {string} [opts.prompt] - Custom text of the initial confirmation question (default: built-in question).
17
+ * @returns {Promise<void>} A promise that resolves when the operation is finished or skipped.
18
+ * @throws Will throw an error if the path is invalid, the file does not exist (and `createMissing` is not set), uses CommonJS `module.exports` or no suitable config export is found or it cannot be processed.
13
19
  */
14
- export declare function updateConfigFile(targetFile: string, newConfig: Record<string | number | symbol, any>, force?: boolean, prompt?: string): Promise<void>;
20
+ export declare function updateConfigFile(opts: UpdateConfigFileOptions): Promise<void>;
@@ -1,13 +1,15 @@
1
- import { JsonValue } from '../types/json.js';
1
+ import { UpdateJsonFileOptions } from '../types/functions.js';
2
2
  /**
3
- * Updates a JSON file by modifying a specific key with new values.
3
+ * Updates a JSON file by setting a key with new value(s). The key can be nested and can alter between primitives to objects and arrays as needed.
4
4
  *
5
- * @param {string} targetFile - The path to the JSON file to update (relative to CWD).
6
- * @param {string} jsonKey - The key in the JSON file to update (can be new or existing).
7
- * @param {JsonPrimitive} patch - The new values to set for the specified key.
8
- * @param {boolean} force - Whether to force the update without prompting.
9
- * @param {string} prompt - Custom prompt message displayed in terminal.
10
- * @returns {Promise<void>} An empty promise that resolves when the file is updated.
11
- * @throws Will throw an error if the path is invalid, the file does not exist or cannot be parsed as JSON.
5
+ * @param {UpdateJsonFileOptions} opts - Options for this operation.
6
+ * @param {string} opts.targetFile - The path to the JSON file to update (relative to CWD).
7
+ * @param {string} opts.jsonKey - The key in the JSON file to update (can be new or existing; may use dot notation for nested keys - missing or non-object intermediate levels are replaced with objects).
8
+ * @param {DataValue} opts.patch - The value for the specified key. Objects are shallow-merged into the existing value (a non-object existing value is replaced), other values (primitives, arrays, null) replace it.
9
+ * @param {boolean} [opts.createMissing] - If true, the file is created when it does not exist, after confirmation unless `force` is set (default: false).
10
+ * @param {boolean} [opts.force] - If true, skips all confirmation prompts (default: false).
11
+ * @param {string} [opts.prompt] - Custom text of the initial confirmation question (default: built-in question).
12
+ * @returns {Promise<void>} A promise that resolves when the operation is finished or skipped.
13
+ * @throws Will throw an error if the path or the key is invalid, the file does not exist (and `createMissing` is not set) or cannot be parsed as JSON.
12
14
  */
13
- export declare function updateJsonFile(targetFile: string, jsonKey: string, patch: JsonValue, force?: boolean, prompt?: string): Promise<void>;
15
+ export declare function updateJsonFile(opts: UpdateJsonFileOptions): Promise<void>;
@@ -1,11 +1,15 @@
1
+ import { UpdateTextFileOptions } from '../types/functions.js';
1
2
  /**
2
3
  * Updates a text file by adding new rows.
3
4
  *
4
- * @param {string} targetFile - The path to the text file to update (relative to CWD).
5
- * @param {string[]} rowsToAdd - New rows to be added at the end of the file.
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 path is invalid or the file does not exist.
5
+ * @param {UpdateTextFileOptions} opts - Options for this operation.
6
+ * @param {string} opts.targetFile - The path to the text file to update (relative to CWD).
7
+ * @param {string[]} opts.rowsToAdd - New rows to be added at the end of the file.
8
+ * @param {boolean} [opts.allowDuplicates] - If true, rows are added even if identical lines already exist in the file (default: false).
9
+ * @param {boolean} [opts.createMissing] - If true, the file is created when it does not exist, after confirmation unless `force` is set (default: false).
10
+ * @param {boolean} [opts.force] - If true, skips all confirmation prompts (default: false).
11
+ * @param {string} [opts.prompt] - Custom text of the initial confirmation question (default: built-in question).
12
+ * @returns {Promise<void>} A promise that resolves when the operation is finished or skipped.
13
+ * @throws Will throw an error if the path is invalid or the file does not exist (and `createMissing` is not set).
10
14
  */
11
- export declare function updateTextFile(targetFile: string, rowsToAdd: string[], force?: boolean, prompt?: string): Promise<void>;
15
+ export declare function updateTextFile(opts: UpdateTextFileOptions): Promise<void>;
@@ -0,0 +1,15 @@
1
+ import { UpdateYamlFileOptions } from '../types/functions.js';
2
+ /**
3
+ * Updates a YAML file by setting a key with new value(s). The key can be nested and can alter between primitives to objects and arrays as needed. Comments and formatting of untouched parts are preserved.
4
+ *
5
+ * @param {UpdateYamlFileOptions} opts - Options for this operation.
6
+ * @param {string} opts.targetFile - The path to the YAML file to update (relative to CWD).
7
+ * @param {string} opts.yamlKey - The key in the YAML file to update (can be new or existing; may use dot notation for nested keys - missing or non-map intermediate levels are replaced with maps).
8
+ * @param {DataValue} opts.patch - The value for the specified key. Objects are shallow-merged into the existing value (a non-map existing value is replaced), other values (primitives, arrays, null) replace it.
9
+ * @param {boolean} [opts.createMissing] - If true, the file is created when it does not exist, after confirmation unless `force` is set (default: false).
10
+ * @param {boolean} [opts.force] - If true, skips all confirmation prompts (default: false).
11
+ * @param {string} [opts.prompt] - Custom text of the initial confirmation question (default: built-in question).
12
+ * @returns {Promise<void>} A promise that resolves when the operation is finished or skipped.
13
+ * @throws Will throw an error if the path or the key is invalid, the file does not exist (and `createMissing` is not set), cannot be parsed as YAML or its root is not a map.
14
+ */
15
+ export declare function updateYamlFile(opts: UpdateYamlFileOptions): Promise<void>;
@@ -1,19 +1,23 @@
1
1
  import { getPackageManager } from './checks/get-package-manager';
2
2
  import { hasJsonKey } from './checks/has-json-key';
3
3
  import { hasText } from './checks/has-text';
4
+ import { hasYamlKey } from './checks/has-yaml-key';
4
5
  import { pathExists } from './checks/path-exists';
5
6
  import { createFileFromTemplate } from './functions/create-file-from-template';
6
7
  import { createFileFromWebTemplate } from './functions/create-file-from-web-template';
7
8
  import { deletePath } from './functions/delete-path';
8
9
  import { removeFromJsonFile } from './functions/remove-from-json-file';
9
10
  import { removeFromTextFile } from './functions/remove-from-text-file';
11
+ import { removeFromYamlFile } from './functions/remove-from-yaml-file';
10
12
  import { updateConfigFile } from './functions/update-config-file';
11
13
  import { updateJsonFile } from './functions/update-json-file';
12
14
  import { updateTextFile } from './functions/update-text-file';
15
+ import { updateYamlFile } from './functions/update-yaml-file';
13
16
  import { promptUser } from './terminal/prompt-user';
14
17
  import { showError } from './terminal/show-error';
15
18
  import { showMessage } from './terminal/show-message';
16
19
  import { getEnvValue } from './utils/get-env-value';
17
20
  import { parseQualifiedPath } from './utils/parse-qualified-path';
18
21
  import { resolvePackagePath } from './utils/resolve-package-path';
19
- export { getPackageManager, hasJsonKey, hasText, pathExists, createFileFromTemplate, createFileFromWebTemplate, deletePath, removeFromJsonFile, removeFromTextFile, updateConfigFile, updateJsonFile, updateTextFile, promptUser, showError, showMessage, getEnvValue, parseQualifiedPath, resolvePackagePath, };
22
+ export type { HasJsonKeyOptions, HasTextOptions, HasYamlKeyOptions, PathExistsOptions, CreateFileFromTemplateOptions, CreateFileFromWebTemplateOptions, DeletePathOptions, RemoveFromJsonFileOptions, RemoveFromTextFileOptions, RemoveFromYamlFileOptions, UpdateConfigFileOptions, UpdateJsonFileOptions, UpdateTextFileOptions, UpdateYamlFileOptions, PromptUserOptions, ShowErrorOptions, ShowMessageOptions, GetEnvValueOptions, ParseQualifiedPathOptions, ResolvePackagePathOptions, } from './types/functions';
23
+ export { getPackageManager, hasJsonKey, hasText, hasYamlKey, pathExists, createFileFromTemplate, createFileFromWebTemplate, deletePath, removeFromJsonFile, removeFromTextFile, removeFromYamlFile, updateConfigFile, updateJsonFile, updateTextFile, updateYamlFile, promptUser, showError, showMessage, getEnvValue, parseQualifiedPath, resolvePackagePath, };
@@ -1,11 +1,11 @@
1
+ import { PromptUserOptions } from '../types/functions.js';
1
2
  /**
2
- * Prompts the user with a question and returns their response.
3
+ * Prompts the user with a yes/no question (` (y/N): ` is appended) and returns their response.
3
4
  *
4
- * @param {string} question - Question to ask the user
5
- * @param {{ input?: NodeJS.ReadableStream; output?: NodeJS.WritableStream }} options - Optional setting of custom input/output stream
6
- * @returns {Promise<boolean>} - true if the user answered yes (`y`, `Y`, `yes`, `YES`), false otherwise
5
+ * @param {PromptUserOptions} opts - Options for this operation.
6
+ * @param {string} opts.question - The question to ask the user.
7
+ * @param {NodeJS.ReadableStream} [opts.input] - Custom input stream (default: process.stdin).
8
+ * @param {NodeJS.WritableStream} [opts.output] - Custom output stream (default: process.stdout).
9
+ * @returns {Promise<boolean>} True if the user answered yes (`y` or `yes`, case-insensitive), false otherwise.
7
10
  */
8
- export declare function promptUser(question: string, options?: {
9
- input?: NodeJS.ReadableStream;
10
- output?: NodeJS.WritableStream;
11
- }): Promise<boolean>;
11
+ export declare function promptUser(opts: PromptUserOptions): Promise<boolean>;
@@ -1,7 +1,9 @@
1
+ import { ShowErrorOptions } from '../types/functions.js';
1
2
  /**
2
3
  * Prints error message into stderr with specified number of newlines after it.
3
4
  *
4
- * @param {string} message - The error message text to display.
5
- * @param {number} linesAfter - The number of newlines to print after the message (default is 1).
5
+ * @param {ShowErrorOptions} opts - Options for this operation.
6
+ * @param {string} opts.message - The error message text to display.
7
+ * @param {number} [opts.linesAfter] - The number of newlines to print after the message (default: 1).
6
8
  */
7
- export declare function showError(message: string, linesAfter?: number): void;
9
+ export declare function showError(opts: ShowErrorOptions): void;
@@ -1,7 +1,9 @@
1
+ import { ShowMessageOptions } from '../types/functions.js';
1
2
  /**
2
3
  * Prints message into stdout with specified number of newlines after it.
3
4
  *
4
- * @param {string} message - The message text to display.
5
- * @param {number} linesAfter - The number of newlines to print after the message (default is 1).
5
+ * @param {ShowMessageOptions} opts - Options for this operation.
6
+ * @param {string} opts.message - The message text to display.
7
+ * @param {number} [opts.linesAfter] - The number of newlines to print after the message (default: 1).
6
8
  */
7
- export declare function showMessage(message: string, linesAfter?: number): void;
9
+ export declare function showMessage(opts: ShowMessageOptions): void;
@@ -0,0 +1,6 @@
1
+ export type DataPrimitive = string | number | boolean | null;
2
+ export type DataObject = {
3
+ [key: string]: DataValue;
4
+ };
5
+ export type DataArray = DataValue[];
6
+ export type DataValue = DataPrimitive | DataObject | DataArray;
@@ -0,0 +1,99 @@
1
+ import { DataValue } from './data.js';
2
+ interface FileOperationOptions {
3
+ /** Skip confirmation prompts. Defaults to false. */
4
+ force?: boolean;
5
+ /** Custom confirmation question. Defaults to the operation's built-in question. */
6
+ prompt?: string;
7
+ }
8
+ export interface HasJsonKeyOptions {
9
+ targetFile: string;
10
+ jsonKey: string;
11
+ }
12
+ export interface HasYamlKeyOptions {
13
+ targetFile: string;
14
+ yamlKey: string;
15
+ }
16
+ export interface HasTextOptions {
17
+ targetFile: string;
18
+ pattern: string | RegExp;
19
+ /** Require a full-line string match. Defaults to false. */
20
+ exact?: boolean;
21
+ }
22
+ export interface PathExistsOptions {
23
+ targetPath: string;
24
+ }
25
+ export interface CreateFileFromTemplateOptions extends FileOperationOptions {
26
+ templateFile: string;
27
+ targetFile: string;
28
+ }
29
+ export interface CreateFileFromWebTemplateOptions extends FileOperationOptions {
30
+ url: string;
31
+ targetFile: string;
32
+ }
33
+ export interface DeletePathOptions extends FileOperationOptions {
34
+ targetPath: string;
35
+ }
36
+ export interface RemoveFromJsonFileOptions extends FileOperationOptions {
37
+ targetFile: string;
38
+ jsonKey: string;
39
+ }
40
+ export interface RemoveFromTextFileOptions extends FileOperationOptions {
41
+ targetFile: string;
42
+ searchText: string;
43
+ }
44
+ export interface RemoveFromYamlFileOptions extends FileOperationOptions {
45
+ targetFile: string;
46
+ yamlKey: string;
47
+ }
48
+ export interface UpdateConfigFileOptions extends FileOperationOptions {
49
+ targetFile: string;
50
+ newConfig: Record<string | number | symbol, any>;
51
+ createMissing?: boolean;
52
+ }
53
+ export interface UpdateJsonFileOptions extends FileOperationOptions {
54
+ targetFile: string;
55
+ jsonKey: string;
56
+ patch: DataValue;
57
+ createMissing?: boolean;
58
+ }
59
+ export interface UpdateYamlFileOptions extends FileOperationOptions {
60
+ targetFile: string;
61
+ yamlKey: string;
62
+ patch: DataValue;
63
+ createMissing?: boolean;
64
+ }
65
+ export interface UpdateTextFileOptions extends FileOperationOptions {
66
+ targetFile: string;
67
+ rowsToAdd: string[];
68
+ allowDuplicates?: boolean;
69
+ createMissing?: boolean;
70
+ }
71
+ export interface PromptUserOptions {
72
+ question: string;
73
+ /** Defaults to process.stdin. */
74
+ input?: NodeJS.ReadableStream;
75
+ /** Defaults to process.stdout. */
76
+ output?: NodeJS.WritableStream;
77
+ }
78
+ export interface ShowErrorOptions {
79
+ message: string;
80
+ /** Number of trailing newlines. Defaults to 1. */
81
+ linesAfter?: number;
82
+ }
83
+ export interface ShowMessageOptions {
84
+ message: string;
85
+ /** Number of trailing newlines. Defaults to 1. */
86
+ linesAfter?: number;
87
+ }
88
+ export interface GetEnvValueOptions {
89
+ key: string;
90
+ /** Defaults to .env in the current working directory at call time. */
91
+ envFilePath?: string;
92
+ }
93
+ export interface ParseQualifiedPathOptions {
94
+ path: string;
95
+ }
96
+ export interface ResolvePackagePathOptions {
97
+ packageName: string;
98
+ }
99
+ export {};
@@ -1,8 +1,10 @@
1
+ import { GetEnvValueOptions } from '../types/functions.js';
1
2
  /**
2
3
  * Retrieves the value of an environment variable from a .env file.
3
4
  *
4
- * @param {string} key - The name of the environment variable to retrieve.
5
- * @param {string} envFilePath - The path to the .env file (default is the .env file in the project root).
6
- * @returns {string | undefined} - The value of the environment variable, or undefined if not found.
5
+ * @param {GetEnvValueOptions} opts - Options for this operation.
6
+ * @param {string} opts.key - The name of the environment variable to retrieve.
7
+ * @param {string} [opts.envFilePath] - The path to the .env file (default: `.env` in CWD).
8
+ * @returns {string | undefined} The value of the environment variable (without surrounding quotes), or undefined if the file or the variable is not found.
7
9
  */
8
- export declare function getEnvValue(key: string, envFilePath?: string): string | undefined;
10
+ export declare function getEnvValue(opts: GetEnvValueOptions): string | undefined;
@@ -1,12 +1,14 @@
1
+ import { ParseQualifiedPathOptions } from '../types/functions.js';
1
2
  /**
2
3
  * Expects path to file in `"package:relative/path/to/file"` format and splits it into `{ pkg, file }`.
3
4
  * The package name can be scoped (e.g. `@scope/package`).
4
5
  *
5
- * @param {string} path - The qualified path string to parse.
6
+ * @param {ParseQualifiedPathOptions} opts - Options for this operation.
7
+ * @param {string} opts.path - The qualified path string to parse.
6
8
  * @returns {{ pkg: string; file: string }} An object containing the package name and the relative file path.
7
9
  * @throws Will throw an error if the input format is invalid.
8
10
  */
9
- export declare function parseQualifiedPath(path: string): {
11
+ export declare function parseQualifiedPath(opts: ParseQualifiedPathOptions): {
10
12
  pkg: string;
11
13
  file: string;
12
14
  };
@@ -1,10 +1,12 @@
1
+ import { ResolvePackagePathOptions } from '../types/functions.js';
1
2
  /**
2
- * Resolve a package's installed root directory *from the target app*.
3
- * Package name can be scoped (e.g. `@scope/package`).
4
- * Works with npm/yarn/pnpm, hoisting or not.
3
+ * Resolves a package's root directory *from the target app* (CWD).
4
+ * Returns CWD itself if its `package.json` has the same name, otherwise looks into `node_modules` in CWD.
5
+ * The package name can be scoped (e.g. `@scope/package`).
5
6
  *
6
- * @param {string} packageName - The name of the package to resolve.
7
+ * @param {ResolvePackagePathOptions} opts - Options for this operation.
8
+ * @param {string} opts.packageName - The name of the package to resolve.
7
9
  * @returns {string} The absolute path to the package's root directory.
8
10
  * @throws Will throw an error if the package cannot be found or accessed.
9
11
  */
10
- export declare function resolvePackagePath(packageName: string): string;
12
+ export declare function resolvePackagePath(opts: ResolvePackagePathOptions): string;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,7 @@
1
+ declare const _default: {
2
+ testKey1: string;
3
+ testKey2: {
4
+ nestedKey: boolean;
5
+ };
6
+ };
7
+ export default _default;