elrh-cosca 0.3.5 → 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 (92) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +419 -265
  3. package/dist/chunks/magicast-B0ixXlDw.mjs +14033 -0
  4. package/dist/chunks/rolldown-runtime-Dqa2HsxW.mjs +20 -0
  5. package/dist/chunks/yaml-BwPmYYDT.mjs +4297 -0
  6. package/dist/elrh-cosca.mjs +489 -15390
  7. package/dist/types/index.d.ts +1 -1
  8. package/dist/types/src/_private/fetch-file.d.ts +1 -0
  9. package/dist/types/src/checks/get-package-manager.d.ts +6 -0
  10. package/dist/types/src/checks/has-json-key.d.ts +11 -0
  11. package/dist/types/src/checks/has-text.d.ts +12 -0
  12. package/dist/types/src/checks/has-yaml-key.d.ts +11 -0
  13. package/dist/types/src/checks/path-exists.d.ts +10 -0
  14. package/dist/types/src/functions/create-file-from-template.d.ts +13 -0
  15. package/dist/types/src/functions/create-file-from-web-template.d.ts +13 -0
  16. package/dist/types/src/functions/delete-path.d.ts +12 -0
  17. package/dist/types/src/functions/remove-from-json-file.d.ts +13 -0
  18. package/dist/types/src/functions/remove-from-text-file.d.ts +13 -0
  19. package/dist/types/src/functions/remove-from-yaml-file.d.ts +13 -0
  20. package/dist/types/src/functions/update-config-file.d.ts +20 -0
  21. package/dist/types/src/functions/update-json-file.d.ts +15 -0
  22. package/dist/types/src/functions/update-text-file.d.ts +15 -0
  23. package/dist/types/src/functions/update-yaml-file.d.ts +15 -0
  24. package/dist/types/src/main.d.ts +23 -0
  25. package/dist/types/src/terminal/prompt-user.d.ts +11 -0
  26. package/dist/types/src/terminal/show-error.d.ts +9 -0
  27. package/dist/types/src/terminal/show-message.d.ts +9 -0
  28. package/dist/types/src/types/data.d.ts +6 -0
  29. package/dist/types/src/types/functions.d.ts +99 -0
  30. package/dist/types/src/utils/get-env-value.d.ts +10 -0
  31. package/dist/types/{utils → src/utils}/parse-qualified-path.d.ts +4 -2
  32. package/dist/types/src/utils/resolve-package-path.d.ts +12 -0
  33. package/dist/types/test/checks-get-package-manager.test.d.ts +1 -0
  34. package/dist/types/test/checks-has-json-key.test.d.ts +1 -0
  35. package/dist/types/test/checks-has-text.test.d.ts +1 -0
  36. package/dist/types/test/checks-has-yaml-key.test.d.ts +1 -0
  37. package/dist/types/test/checks-path-exists.test.d.ts +1 -0
  38. package/dist/types/test/cosca-test-setup.d.ts +1 -0
  39. package/dist/types/test/cosca-test-utils.d.ts +45 -0
  40. package/dist/types/test/fixtures/config-file-default.d.ts +10 -0
  41. package/dist/types/test/fixtures/config-file-named.d.ts +9 -0
  42. package/dist/types/test/functions-create-file-from-template.test.d.ts +1 -0
  43. package/dist/types/test/functions-create-file-from-web-template.test.d.ts +1 -0
  44. package/dist/types/test/functions-delete-path.test.d.ts +1 -0
  45. package/dist/types/test/functions-remove-from-json-file.test.d.ts +1 -0
  46. package/dist/types/test/functions-remove-from-text-file.test.d.ts +1 -0
  47. package/dist/types/test/functions-remove-from-yaml-file.test.d.ts +1 -0
  48. package/dist/types/test/functions-update-config-file.test.d.ts +1 -0
  49. package/dist/types/test/functions-update-json-file.test.d.ts +1 -0
  50. package/dist/types/test/functions-update-text-file.test.d.ts +1 -0
  51. package/dist/types/test/functions-update-yaml-file.test.d.ts +1 -0
  52. package/dist/types/test/private-check-path.test.d.ts +1 -0
  53. package/dist/types/test/private-deep-merge-object.test.d.ts +1 -0
  54. package/dist/types/test/private-fetch-file.test.d.ts +1 -0
  55. package/dist/types/test/snapshots/created-config-file.d.ts +7 -0
  56. package/dist/types/test/snapshots/updated-config-file-default-1.d.ts +13 -0
  57. package/dist/types/test/snapshots/updated-config-file-default-2.d.ts +14 -0
  58. package/dist/types/test/snapshots/updated-config-file-default-3.d.ts +16 -0
  59. package/dist/types/test/snapshots/updated-config-file-default-4.d.ts +18 -0
  60. package/dist/types/test/snapshots/updated-config-file-named-1.d.ts +12 -0
  61. package/dist/types/test/snapshots/updated-config-file-named-2.d.ts +13 -0
  62. package/dist/types/test/snapshots/updated-config-file-named-3.d.ts +15 -0
  63. package/dist/types/test/snapshots/updated-config-file-named-4.d.ts +17 -0
  64. package/dist/types/test/terminal-prompt-user.test.d.ts +1 -0
  65. package/dist/types/test/terninal-show-error.test.d.ts +1 -0
  66. package/dist/types/test/terninal-show-message.test.d.ts +1 -0
  67. package/dist/types/test/utils-get-env-value.test.d.ts +1 -0
  68. package/dist/types/test/utils-parse-qualified-path.test.d.ts +1 -0
  69. package/dist/types/test/utils-resolve-package-path.test.d.ts +1 -0
  70. package/package.json +15 -11
  71. package/test/cosca-test.js +55 -55
  72. package/dist/types/_private/fetch-file.d.ts +0 -1
  73. package/dist/types/checks/get-package-manager.d.ts +0 -6
  74. package/dist/types/checks/has-json-key.d.ts +0 -9
  75. package/dist/types/checks/has-text.d.ts +0 -10
  76. package/dist/types/checks/path-exists.d.ts +0 -8
  77. package/dist/types/functions/create-file-from-template.d.ts +0 -11
  78. package/dist/types/functions/create-file-from-web-template.d.ts +0 -11
  79. package/dist/types/functions/delete-path.d.ts +0 -10
  80. package/dist/types/functions/remove-from-json-file.d.ts +0 -11
  81. package/dist/types/functions/update-config-file.d.ts +0 -14
  82. package/dist/types/functions/update-json-file.d.ts +0 -13
  83. package/dist/types/functions/update-text-file.d.ts +0 -11
  84. package/dist/types/main.d.ts +0 -18
  85. package/dist/types/terminal/prompt-user.d.ts +0 -11
  86. package/dist/types/terminal/show-error.d.ts +0 -7
  87. package/dist/types/terminal/show-message.d.ts +0 -7
  88. package/dist/types/types/json.d.ts +0 -6
  89. package/dist/types/utils/get-env-value.d.ts +0 -8
  90. package/dist/types/utils/resolve-package-path.d.ts +0 -10
  91. /package/dist/types/{_private → src/_private}/check-path.d.ts +0 -0
  92. /package/dist/types/{_private → src/_private}/deep-merge-object.d.ts +0 -0
@@ -1,2 +1,2 @@
1
- export * from './main'
1
+ export * from './src/main.js'
2
2
  export {}
@@ -0,0 +1 @@
1
+ export declare function fetchFile(url: string, redirectsLeft?: number): Promise<string>;
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Checks what package manager/runtime was used to execute the current command.
3
+ *
4
+ * @returns {'npm' | 'yarn' | 'pnpm' | 'deno' | 'bun'} The name of the package manager used (falls back to 'npm' if detection failed).
5
+ */
6
+ export declare function getPackageManager(): 'npm' | 'yarn' | 'pnpm' | 'deno' | 'bun';
@@ -0,0 +1,11 @@
1
+ import { HasJsonKeyOptions } from '../types/functions.js';
2
+ /**
3
+ * Checks if a JSON file contains specified key.
4
+ *
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).
8
+ * @returns {boolean} 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 JSON.
10
+ */
11
+ export declare function hasJsonKey(opts: HasJsonKeyOptions): boolean;
@@ -0,0 +1,12 @@
1
+ import { HasTextOptions } from '../types/functions.js';
2
+ /**
3
+ * Checks if a text file contains specified text.
4
+ *
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).
9
+ * @returns {boolean} True if the pattern is found in target file, false otherwise.
10
+ * @throws Will throw an error if the path is invalid or the file does not exist.
11
+ */
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>;
@@ -0,0 +1,10 @@
1
+ import { PathExistsOptions } from '../types/functions.js';
2
+ /**
3
+ * Checks if the specified path exists on FS. The search is limited to CWD.
4
+ *
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).
7
+ * @returns {boolean} True if the path exists, false otherwise.
8
+ * @throws Will throw an error if the path is invalid.
9
+ */
10
+ export declare function pathExists(opts: PathExistsOptions): boolean;
@@ -0,0 +1,13 @@
1
+ import { CreateFileFromTemplateOptions } from '../types/functions.js';
2
+ /**
3
+ * Creates a new file as a copy of a template file from an installed package.
4
+ *
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.
12
+ */
13
+ export declare function createFileFromTemplate(opts: CreateFileFromTemplateOptions): Promise<void>;
@@ -0,0 +1,13 @@
1
+ import { CreateFileFromWebTemplateOptions } from '../types/functions.js';
2
+ /**
3
+ * Creates a new file as a copy of a template file downloaded from the web.
4
+ *
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.
12
+ */
13
+ export declare function createFileFromWebTemplate(opts: CreateFileFromWebTemplateOptions): Promise<void>;
@@ -0,0 +1,12 @@
1
+ import { DeletePathOptions } from '../types/functions.js';
2
+ /**
3
+ * Deletes a file or a directory (recursively) from FS.
4
+ *
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.
11
+ */
12
+ export declare function deletePath(opts: DeletePathOptions): Promise<void>;
@@ -0,0 +1,13 @@
1
+ import { RemoveFromJsonFileOptions } from '../types/functions.js';
2
+ /**
3
+ * Updates a JSON file by deleting a specified key.
4
+ *
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.
11
+ * @throws Will throw an error if the path is invalid, the file does not exist or cannot be parsed as JSON.
12
+ */
13
+ export declare function removeFromJsonFile(opts: RemoveFromJsonFileOptions): Promise<void>;
@@ -0,0 +1,13 @@
1
+ import { RemoveFromTextFileOptions } from '../types/functions.js';
2
+ /**
3
+ * Removes lines from a text file that include the given search text.
4
+ *
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.
11
+ * @throws Will throw an error if the path is invalid or the file does not exist.
12
+ */
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>;
@@ -0,0 +1,20 @@
1
+ import { UpdateConfigFileOptions } from '../types/functions.js';
2
+ /**
3
+ * Updates the config object exported from a JS/TS config file.
4
+ *
5
+ * The function:
6
+ * - Reads and edits the file as code (no execution).
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.
9
+ * - Applies the merged result back onto the AST to preserve TS/ESM structure.
10
+ *
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.
19
+ */
20
+ export declare function updateConfigFile(opts: UpdateConfigFileOptions): Promise<void>;
@@ -0,0 +1,15 @@
1
+ import { UpdateJsonFileOptions } from '../types/functions.js';
2
+ /**
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
+ *
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.
14
+ */
15
+ export declare function updateJsonFile(opts: UpdateJsonFileOptions): Promise<void>;
@@ -0,0 +1,15 @@
1
+ import { UpdateTextFileOptions } from '../types/functions.js';
2
+ /**
3
+ * Updates a text file by adding new rows.
4
+ *
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).
14
+ */
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>;
@@ -0,0 +1,23 @@
1
+ import { getPackageManager } from './checks/get-package-manager';
2
+ import { hasJsonKey } from './checks/has-json-key';
3
+ import { hasText } from './checks/has-text';
4
+ import { hasYamlKey } from './checks/has-yaml-key';
5
+ import { pathExists } from './checks/path-exists';
6
+ import { createFileFromTemplate } from './functions/create-file-from-template';
7
+ import { createFileFromWebTemplate } from './functions/create-file-from-web-template';
8
+ import { deletePath } from './functions/delete-path';
9
+ import { removeFromJsonFile } from './functions/remove-from-json-file';
10
+ import { removeFromTextFile } from './functions/remove-from-text-file';
11
+ import { removeFromYamlFile } from './functions/remove-from-yaml-file';
12
+ import { updateConfigFile } from './functions/update-config-file';
13
+ import { updateJsonFile } from './functions/update-json-file';
14
+ import { updateTextFile } from './functions/update-text-file';
15
+ import { updateYamlFile } from './functions/update-yaml-file';
16
+ import { promptUser } from './terminal/prompt-user';
17
+ import { showError } from './terminal/show-error';
18
+ import { showMessage } from './terminal/show-message';
19
+ import { getEnvValue } from './utils/get-env-value';
20
+ import { parseQualifiedPath } from './utils/parse-qualified-path';
21
+ import { resolvePackagePath } from './utils/resolve-package-path';
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, };
@@ -0,0 +1,11 @@
1
+ import { PromptUserOptions } from '../types/functions.js';
2
+ /**
3
+ * Prompts the user with a yes/no question (` (y/N): ` is appended) and returns their response.
4
+ *
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.
10
+ */
11
+ export declare function promptUser(opts: PromptUserOptions): Promise<boolean>;
@@ -0,0 +1,9 @@
1
+ import { ShowErrorOptions } from '../types/functions.js';
2
+ /**
3
+ * Prints error message into stderr with specified number of newlines after it.
4
+ *
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).
8
+ */
9
+ export declare function showError(opts: ShowErrorOptions): void;
@@ -0,0 +1,9 @@
1
+ import { ShowMessageOptions } from '../types/functions.js';
2
+ /**
3
+ * Prints message into stdout with specified number of newlines after it.
4
+ *
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).
8
+ */
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 {};
@@ -0,0 +1,10 @@
1
+ import { GetEnvValueOptions } from '../types/functions.js';
2
+ /**
3
+ * Retrieves the value of an environment variable from a .env file.
4
+ *
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.
9
+ */
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
  };
@@ -0,0 +1,12 @@
1
+ import { ResolvePackagePathOptions } from '../types/functions.js';
2
+ /**
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`).
6
+ *
7
+ * @param {ResolvePackagePathOptions} opts - Options for this operation.
8
+ * @param {string} opts.packageName - The name of the package to resolve.
9
+ * @returns {string} The absolute path to the package's root directory.
10
+ * @throws Will throw an error if the package cannot be found or accessed.
11
+ */
12
+ export declare function resolvePackagePath(opts: ResolvePackagePathOptions): string;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export default function (): Promise<() => void>;
@@ -0,0 +1,45 @@
1
+ import * as promptModule from '../src/terminal/prompt-user';
2
+ /**
3
+ * Reads a (text) file into the string array.
4
+ * @param dir path to directory
5
+ * @param file name of the (text) file (must exist in `dir`)
6
+ * @returns array of read lines
7
+ */
8
+ export declare function readNormalizedFile(dir: string, file: string): string;
9
+ /**
10
+ * Mocks console logging methods in order to spy on the passed arguments.
11
+ * @param logLevel which console log method should be mocked
12
+ * @returns mocked console log method
13
+ */
14
+ export declare function getConsoleSpy(logLevel: 'log' | 'debug' | 'info' | 'warn' | 'error'): import('vitest').MockInstance<((...data: any[]) => void) | ((...data: any[]) => void) | ((...data: any[]) => void) | ((...data: any[]) => void) | ((...data: any[]) => void)> & {
15
+ (...args: any[]): void;
16
+ new (...args: any[]): void;
17
+ } & {};
18
+ /**
19
+ * Mocks user input(s) for the `readline.question` method.
20
+ * @param input array of 1+ expected values from the user
21
+ * @returns mocked terminal input
22
+ */
23
+ export declare function setPromptSpy(inputs: string[]): void;
24
+ /**
25
+ * Mocks logging into stdout to spy on the passed arguments.
26
+ * @returns mocked stdout log method
27
+ */
28
+ export declare function getStdoutSpy(): import('vitest').Mock<{
29
+ (buffer: Uint8Array | string, cb?: (err?: Error | null) => void): boolean;
30
+ (str: Uint8Array | string, encoding?: BufferEncoding, cb?: (err?: Error | null) => void): boolean;
31
+ }>;
32
+ /**
33
+ * Mocks logging into stderr to spy on the passed arguments.
34
+ * @returns mocked stderr log method
35
+ */
36
+ export declare function getStderrSpy(): import('vitest').Mock<{
37
+ (buffer: Uint8Array | string, cb?: (err?: Error | null) => void): boolean;
38
+ (str: Uint8Array | string, encoding?: BufferEncoding, cb?: (err?: Error | null) => void): boolean;
39
+ }>;
40
+ /**
41
+ * Mocks call of the promptUser function to capture the displayed question.
42
+ * @param expectedResult how should the prompt being resolved (default: false)
43
+ * @returns mocked promptUser function
44
+ */
45
+ export declare function getPromptUserSpy(expectedResult?: boolean): import('vitest').Mock<typeof promptModule.promptUser>;
@@ -0,0 +1,10 @@
1
+ declare const _default: {
2
+ stringKey: string;
3
+ numberKey: number;
4
+ boolKey: boolean;
5
+ arrayKey: string[];
6
+ objectKey: {
7
+ nestedKey: string;
8
+ };
9
+ };
10
+ export default _default;
@@ -0,0 +1,9 @@
1
+ export declare const config: {
2
+ stringKey: string;
3
+ numberKey: number;
4
+ boolKey: boolean;
5
+ arrayKey: string[];
6
+ objectKey: {
7
+ nestedKey: string;
8
+ };
9
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -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;
@@ -0,0 +1,13 @@
1
+ declare const _default: {
2
+ stringKey: string;
3
+ numberKey: number;
4
+ boolKey: boolean;
5
+ arrayKey: string[];
6
+ objectKey: {
7
+ nestedKey: string;
8
+ };
9
+ testKey1: string;
10
+ testKey2: number;
11
+ testKey3: boolean;
12
+ };
13
+ export default _default;
@@ -0,0 +1,14 @@
1
+ declare const _default: {
2
+ stringKey: string;
3
+ numberKey: number;
4
+ boolKey: boolean;
5
+ arrayKey: string[];
6
+ objectKey: {
7
+ nestedKey: string;
8
+ };
9
+ testKey1: string;
10
+ testKey2: number;
11
+ testKey3: boolean;
12
+ testKey4: string;
13
+ };
14
+ export default _default;
@@ -0,0 +1,16 @@
1
+ declare const _default: {
2
+ stringKey: string;
3
+ numberKey: number;
4
+ boolKey: boolean;
5
+ arrayKey: string[];
6
+ objectKey: {
7
+ nestedKey: string;
8
+ };
9
+ testKey1: string;
10
+ testKey2: number;
11
+ testKey3: boolean;
12
+ testKey4: {
13
+ nestedKey: string;
14
+ };
15
+ };
16
+ export default _default;