elrh-cosca 0.2.4 → 0.2.6

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.
@@ -1 +1,11 @@
1
- export declare function createFileFromTemplate(templateFile: string, targetFile: string, force?: boolean): Promise<void>;
1
+ /**
2
+ * Creates a new copy of given file from a local template.
3
+ *
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 template file cannot be found or the target file failed to be created.
10
+ */
11
+ export declare function createFileFromTemplate(templateFile: string, targetFile: string, force?: boolean, prompt?: string): Promise<void>;
@@ -1 +1,11 @@
1
- export declare function createFileFromWebTemplate(url: string, targetFile: string, force?: boolean): Promise<void>;
1
+ /**
2
+ * Creates a new copy of given file from a web template.
3
+ *
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 remote template cannot be fetched or the target file failed to be created.
10
+ */
11
+ export declare function createFileFromWebTemplate(url: string, targetFile: string, force?: boolean, prompt?: string): Promise<void>;
@@ -8,6 +8,7 @@
8
8
  *
9
9
  * @param {string} pathToFile - Path to file, relative to project root (process.cwd()).
10
10
  * @param {object} newConfig - Config to merge in (takes precedence).
11
- * @returns {Promise<void>}
11
+ * @returns {Promise<void>} An empty promise that resolves when the file is updated.
12
+ * @throws Will throw an error if no config export is found or it cannot be processed.
12
13
  */
13
- export declare function updateConfigFile(pathToFile: string, newConfig: Record<string | number | symbol, any>, force?: boolean): Promise<void>;
14
+ export declare function updateConfigFile(pathToFile: string, newConfig: Record<string | number | symbol, any>, force?: boolean, prompt?: string): Promise<void>;
@@ -1 +1,12 @@
1
- export declare function updateJsonFile(pathToFile: string, jsonKey: string, newValues: Record<string | number | symbol, any>, force?: boolean): Promise<void>;
1
+ /**
2
+ * Updates a JSON file by modifying a specific key with new values.
3
+ *
4
+ * @param {string} pathToFile - The path to the JSON file to update (relative to CWD).
5
+ * @param {string} jsonKey - The key in the JSON file to update (can be new or existing).
6
+ * @param {Record<string | number | symbol, any>} newValues - The new values to set for the specified key.
7
+ * @param {boolean} force - Whether to force the update without prompting.
8
+ * @param {string} prompt - Custom prompt message displayed in terminal.
9
+ * @returns {Promise<void>} An empty promise that resolves when the file is updated.
10
+ * @throws Will throw an error if the file does not exist or cannot be parsed as JSON.
11
+ */
12
+ export declare function updateJsonFile(pathToFile: string, jsonKey: string, newValues: Record<string | number | symbol, any>, force?: boolean, prompt?: string): Promise<void>;
@@ -1 +1,11 @@
1
- export declare function updateTextFile(pathToFile: string, rowsToAdd: string[], force?: boolean): Promise<void>;
1
+ /**
2
+ * Updates a text file by adding new rows.
3
+ *
4
+ * @param {string} pathToFile - 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 file does not exist.
10
+ */
11
+ export declare function updateTextFile(pathToFile: string, rowsToAdd: string[], force?: boolean, prompt?: string): Promise<void>;
@@ -6,6 +6,7 @@ import { updateTextFile } from './functions/update-text-file';
6
6
  import { promptUser } from './terminal/prompt-user';
7
7
  import { showError } from './terminal/show-error';
8
8
  import { showMessage } from './terminal/show-message';
9
+ import { getEnvValue } from './utils/get-env-value';
9
10
  import { parseQualifiedPath } from './utils/parse-qualified-path';
10
11
  import { resolvePackagePath } from './utils/resolve-package-path';
11
- export { createFileFromTemplate, createFileFromWebTemplate, updateConfigFile, updateJsonFile, updateTextFile, promptUser, showError, showMessage, parseQualifiedPath, resolvePackagePath, };
12
+ export { createFileFromTemplate, createFileFromWebTemplate, updateConfigFile, updateJsonFile, updateTextFile, promptUser, showError, showMessage, getEnvValue, parseQualifiedPath, resolvePackagePath, };
@@ -1 +1,11 @@
1
- export declare function promptUser(question: string): Promise<boolean>;
1
+ /**
2
+ * Prompts the user with a question and returns their response.
3
+ *
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
7
+ */
8
+ export declare function promptUser(question: string, options?: {
9
+ input?: NodeJS.ReadableStream;
10
+ output?: NodeJS.WritableStream;
11
+ }): Promise<boolean>;
@@ -1 +1,7 @@
1
+ /**
2
+ * Prints error message into stderr with specified number of newlines after it.
3
+ *
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).
6
+ */
1
7
  export declare function showError(message: string, linesAfter?: number): void;
@@ -1 +1,7 @@
1
+ /**
2
+ * Prints message into stdout with specified number of newlines after it.
3
+ *
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).
6
+ */
1
7
  export declare function showMessage(message: string, linesAfter?: number): void;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Retrieves the value of an environment variable from a .env file.
3
+ *
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.
7
+ */
8
+ export declare function getEnvValue(key: string, envFilePath?: string): string | undefined;
@@ -1,6 +1,10 @@
1
1
  /**
2
2
  * Expects path to file in `"package:relative/path/to/file"` format and splits it into `{ pkg, file }`.
3
- * The package name can be scoped (e.g. `@scope/package`). Throws error on invalid input.
3
+ * The package name can be scoped (e.g. `@scope/package`).
4
+ *
5
+ * @param {string} path - The qualified path string to parse.
6
+ * @returns {{ pkg: string; file: string }} An object containing the package name and the relative file path.
7
+ * @throws Will throw an error if the input format is invalid.
4
8
  */
5
9
  export declare function parseQualifiedPath(path: string): {
6
10
  pkg: string;
@@ -2,5 +2,9 @@
2
2
  * Resolve a package's installed root directory *from the target app*.
3
3
  * Package name can be scoped (e.g. `@scope/package`).
4
4
  * Works with npm/yarn/pnpm, hoisting or not.
5
+ *
6
+ * @param {string} packageName - The name of the package to resolve.
7
+ * @returns {string} The absolute path to the package's root directory.
8
+ * @throws Will throw an error if the package cannot be found or accessed.
5
9
  */
6
10
  export declare function resolvePackagePath(packageName: string): string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "elrh-cosca",
3
- "version": "0.2.4",
3
+ "version": "0.2.6",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist"
@@ -4,7 +4,7 @@
4
4
 
5
5
  import {
6
6
  createFileFromTemplate, createFileFromWebTemplate, promptUser, showError, showMessage,
7
- updateConfigFile, updateJsonFile, updateTextFile
7
+ updateConfigFile, getEnvValue, updateJsonFile, updateTextFile
8
8
  } from '../dist/elrh-cosca.mjs'
9
9
 
10
10
  async function main() {
@@ -13,6 +13,14 @@ async function main() {
13
13
  console.log('Test showMessage')
14
14
  showError('ERROR!')
15
15
 
16
+ console.log('Test getEnvValue')
17
+ const a = getEnvValue('A')
18
+ const b = getEnvValue('B')
19
+ const c = getEnvValue('C')
20
+ const d = getEnvValue('D')
21
+ const e = getEnvValue('E')
22
+ console.log(a, b, c, d, e)
23
+
16
24
  console.log('Test promptUser')
17
25
  const input = await promptUser('Is it today?')
18
26
  console.log('User input:', input)