elrh-cosca 0.3.4 → 0.3.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.
Files changed (61) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +281 -265
  3. package/dist/elrh-cosca.mjs +14305 -16595
  4. package/dist/types/index.d.ts +1 -1
  5. package/dist/types/src/checks/has-text.d.ts +10 -0
  6. package/dist/types/src/functions/remove-from-text-file.d.ts +11 -0
  7. package/dist/types/{main.d.ts → src/main.d.ts} +2 -1
  8. package/dist/types/test/checks-get-package-manager.test.d.ts +1 -0
  9. package/dist/types/test/checks-has-json-key.test.d.ts +1 -0
  10. package/dist/types/test/checks-has-text.test.d.ts +1 -0
  11. package/dist/types/test/checks-path-exists.test.d.ts +1 -0
  12. package/dist/types/test/cosca-test-setup.d.ts +1 -0
  13. package/dist/types/test/cosca-test-utils.d.ts +45 -0
  14. package/dist/types/test/fixtures/config-file-default.d.ts +10 -0
  15. package/dist/types/test/fixtures/config-file-named.d.ts +9 -0
  16. package/dist/types/test/functions-create-file-from-template.test.d.ts +1 -0
  17. package/dist/types/test/functions-create-file-from-web-template.test.d.ts +1 -0
  18. package/dist/types/test/functions-delete-path.test.d.ts +1 -0
  19. package/dist/types/test/functions-remove-from-json-file.test.d.ts +1 -0
  20. package/dist/types/test/functions-remove-from-text-file.test.d.ts +1 -0
  21. package/dist/types/test/functions-update-config-file.test.d.ts +1 -0
  22. package/dist/types/test/functions-update-json-file.test.d.ts +1 -0
  23. package/dist/types/test/functions-update-text-file.test.d.ts +1 -0
  24. package/dist/types/test/private-check-path.test.d.ts +1 -0
  25. package/dist/types/test/snapshots/updated-config-file-default-1.d.ts +13 -0
  26. package/dist/types/test/snapshots/updated-config-file-default-2.d.ts +14 -0
  27. package/dist/types/test/snapshots/updated-config-file-default-3.d.ts +16 -0
  28. package/dist/types/test/snapshots/updated-config-file-default-4.d.ts +18 -0
  29. package/dist/types/test/snapshots/updated-config-file-named-1.d.ts +12 -0
  30. package/dist/types/test/snapshots/updated-config-file-named-2.d.ts +13 -0
  31. package/dist/types/test/snapshots/updated-config-file-named-3.d.ts +15 -0
  32. package/dist/types/test/snapshots/updated-config-file-named-4.d.ts +17 -0
  33. package/dist/types/test/terminal-prompt-user.test.d.ts +1 -0
  34. package/dist/types/test/terninal-show-error.test.d.ts +1 -0
  35. package/dist/types/test/terninal-show-message.test.d.ts +1 -0
  36. package/dist/types/test/utils-get-env-value.test.d.ts +1 -0
  37. package/dist/types/test/utils-parse-qualified-path.test.d.ts +1 -0
  38. package/dist/types/test/utils-resolve-package-path.test.d.ts +1 -0
  39. package/package.json +6 -6
  40. package/test/cosca-test.js +55 -55
  41. package/dist/types/checks/has-text.d.ts +0 -9
  42. /package/dist/types/{_private → src/_private}/check-path.d.ts +0 -0
  43. /package/dist/types/{_private → src/_private}/deep-merge-object.d.ts +0 -0
  44. /package/dist/types/{_private → src/_private}/fetch-file.d.ts +0 -0
  45. /package/dist/types/{checks → src/checks}/get-package-manager.d.ts +0 -0
  46. /package/dist/types/{checks → src/checks}/has-json-key.d.ts +0 -0
  47. /package/dist/types/{checks → src/checks}/path-exists.d.ts +0 -0
  48. /package/dist/types/{functions → src/functions}/create-file-from-template.d.ts +0 -0
  49. /package/dist/types/{functions → src/functions}/create-file-from-web-template.d.ts +0 -0
  50. /package/dist/types/{functions → src/functions}/delete-path.d.ts +0 -0
  51. /package/dist/types/{functions → src/functions}/remove-from-json-file.d.ts +0 -0
  52. /package/dist/types/{functions → src/functions}/update-config-file.d.ts +0 -0
  53. /package/dist/types/{functions → src/functions}/update-json-file.d.ts +0 -0
  54. /package/dist/types/{functions → src/functions}/update-text-file.d.ts +0 -0
  55. /package/dist/types/{terminal → src/terminal}/prompt-user.d.ts +0 -0
  56. /package/dist/types/{terminal → src/terminal}/show-error.d.ts +0 -0
  57. /package/dist/types/{terminal → src/terminal}/show-message.d.ts +0 -0
  58. /package/dist/types/{types → src/types}/json.d.ts +0 -0
  59. /package/dist/types/{utils → src/utils}/get-env-value.d.ts +0 -0
  60. /package/dist/types/{utils → src/utils}/parse-qualified-path.d.ts +0 -0
  61. /package/dist/types/{utils → src/utils}/resolve-package-path.d.ts +0 -0
@@ -1,2 +1,2 @@
1
- export * from './main'
1
+ export * from './src/main.js'
2
2
  export {}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Checks if a text file contains specified text.
3
+ *
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).
7
+ * @returns {boolean} True if the pattern is found in target file, false otherwise.
8
+ * @throws Will throw an error if the path is invalid or the file does not exist.
9
+ */
10
+ export declare function hasText(targetFile: string, pattern: string | RegExp, exact?: boolean): boolean;
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Removes lines from a text file that include the given search text.
3
+ *
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.
9
+ * @throws Will throw an error if the path is invalid or the file does not exist.
10
+ */
11
+ export declare function removeFromTextFile(targetFile: string, searchText: string, force?: boolean, prompt?: string): Promise<void>;
@@ -6,6 +6,7 @@ import { createFileFromTemplate } from './functions/create-file-from-template';
6
6
  import { createFileFromWebTemplate } from './functions/create-file-from-web-template';
7
7
  import { deletePath } from './functions/delete-path';
8
8
  import { removeFromJsonFile } from './functions/remove-from-json-file';
9
+ import { removeFromTextFile } from './functions/remove-from-text-file';
9
10
  import { updateConfigFile } from './functions/update-config-file';
10
11
  import { updateJsonFile } from './functions/update-json-file';
11
12
  import { updateTextFile } from './functions/update-text-file';
@@ -15,4 +16,4 @@ import { showMessage } from './terminal/show-message';
15
16
  import { getEnvValue } from './utils/get-env-value';
16
17
  import { parseQualifiedPath } from './utils/parse-qualified-path';
17
18
  import { resolvePackagePath } from './utils/resolve-package-path';
18
- export { getPackageManager, hasJsonKey, hasText, pathExists, createFileFromTemplate, createFileFromWebTemplate, deletePath, removeFromJsonFile, updateConfigFile, updateJsonFile, updateTextFile, promptUser, showError, showMessage, getEnvValue, parseQualifiedPath, resolvePackagePath, };
19
+ export { getPackageManager, hasJsonKey, hasText, pathExists, createFileFromTemplate, createFileFromWebTemplate, deletePath, removeFromJsonFile, removeFromTextFile, updateConfigFile, updateJsonFile, updateTextFile, promptUser, showError, showMessage, getEnvValue, parseQualifiedPath, resolvePackagePath, };
@@ -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,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;
@@ -0,0 +1,18 @@
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: {
14
+ deeper: boolean;
15
+ };
16
+ };
17
+ };
18
+ export default _default;
@@ -0,0 +1,12 @@
1
+ export declare const config: {
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
+ };
@@ -0,0 +1,13 @@
1
+ export declare const config: {
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
+ };
@@ -0,0 +1,15 @@
1
+ export declare const config: {
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
+ };
@@ -0,0 +1,17 @@
1
+ export declare const config: {
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: {
14
+ deeper: boolean;
15
+ };
16
+ };
17
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "elrh-cosca",
3
- "version": "0.3.4",
3
+ "version": "0.3.6",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist"
@@ -18,12 +18,12 @@
18
18
  "module": "./dist/elrh-cosca.mjs",
19
19
  "types": "./dist/types/index.d.ts",
20
20
  "devDependencies": {
21
- "@types/node": "^24.6.0",
22
- "magicast": "^0.3.5",
21
+ "@types/node": "^25.9.0",
22
+ "magicast": "^0.5.3",
23
23
  "typescript": "^5.9.3",
24
- "vite": "^7.1.8",
25
- "vite-plugin-dts": "^4.5.4",
26
- "vitest": "^3.2.4"
24
+ "vite": "^8.0.0",
25
+ "vite-plugin-dts": "^5.0.0",
26
+ "vitest": "^4.1.0"
27
27
  },
28
28
  "scripts": {
29
29
  "dev": "vite",
@@ -1,55 +1,55 @@
1
- #!/usr/bin/env node
2
-
3
- // manual test script for COSCA functions
4
-
5
- import {
6
- createFileFromTemplate, createFileFromWebTemplate, promptUser, showError, showMessage,
7
- updateConfigFile, getEnvValue, updateJsonFile, updateTextFile, deletePath, removeFromJsonFile
8
- } from '../dist/elrh-cosca.mjs'
9
-
10
- async function main() {
11
- console.log('Test showMessage')
12
- showMessage('Hello!')
13
- console.log('Test showMessage')
14
- showError('ERROR!')
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
-
24
- console.log('Test promptUser')
25
- const input = await promptUser('Is it today?')
26
- console.log('User input:', input)
27
-
28
- console.log('\nTest createFileFromTemplate')
29
- await createFileFromTemplate('vitest:README.md', 'test/snapshots/test.file1')
30
- await createFileFromTemplate('elrh-cosca:test/fixtures/text-file.txt', 'test/snapshots/test.file2')
31
-
32
- console.log('\nTest createFileFromWebTemplate')
33
- await createFileFromWebTemplate('https://raw.githubusercontent.com/AloisSeckar/nuxt-spec/refs/heads/main/config/vitest.config.ts.template', 'test/snapshots/test.file3')
34
-
35
- console.log('\nTest updateConfigFile')
36
- await updateConfigFile('test/fixtures/config-file-default.ts', { compatibilityDate: '2025-08-26', extends: ['nuxt-iignis'], cosca: { exists: true, data: ['some', 'other'], raw: 'war' } })
37
-
38
- console.log('\nTest updateJsonFile')
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')
44
-
45
- console.log('\nTest updateTextFile')
46
- await updateTextFile('test/fixtures/text-file.txt', ['# COSCA'])
47
-
48
- console.log('\nTest deletePath')
49
- await deletePath('test/snapshots/test.file1')
50
- }
51
-
52
- main().catch((err) => {
53
- console.error(err)
54
- process.exit(1)
55
- })
1
+ #!/usr/bin/env node
2
+
3
+ // manual test script for COSCA functions
4
+
5
+ import {
6
+ createFileFromTemplate, createFileFromWebTemplate, promptUser, showError, showMessage,
7
+ updateConfigFile, getEnvValue, updateJsonFile, updateTextFile, deletePath, removeFromJsonFile
8
+ } from '../dist/elrh-cosca.mjs'
9
+
10
+ async function main() {
11
+ console.log('Test showMessage')
12
+ showMessage('Hello!')
13
+ console.log('Test showMessage')
14
+ showError('ERROR!')
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
+
24
+ console.log('Test promptUser')
25
+ const input = await promptUser('Is it today?')
26
+ console.log('User input:', input)
27
+
28
+ console.log('\nTest createFileFromTemplate')
29
+ await createFileFromTemplate('vitest:README.md', 'test/snapshots/test.file1')
30
+ await createFileFromTemplate('elrh-cosca:test/fixtures/text-file.txt', 'test/snapshots/test.file2')
31
+
32
+ console.log('\nTest createFileFromWebTemplate')
33
+ await createFileFromWebTemplate('https://raw.githubusercontent.com/AloisSeckar/nuxt-spec/refs/heads/main/config/vitest.config.ts.template', 'test/snapshots/test.file3')
34
+
35
+ console.log('\nTest updateConfigFile')
36
+ await updateConfigFile('test/fixtures/config-file-default.ts', { compatibilityDate: '2025-08-26', extends: ['nuxt-iignis'], cosca: { exists: true, data: ['some', 'other'], raw: 'war' } })
37
+
38
+ console.log('\nTest updateJsonFile')
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')
44
+
45
+ console.log('\nTest updateTextFile')
46
+ await updateTextFile('test/fixtures/text-file.txt', ['# COSCA'])
47
+
48
+ console.log('\nTest deletePath')
49
+ await deletePath('test/snapshots/test.file1')
50
+ }
51
+
52
+ main().catch((err) => {
53
+ console.error(err)
54
+ process.exit(1)
55
+ })
@@ -1,9 +0,0 @@
1
- /**
2
- * Checks if a text file contains specified row.
3
- *
4
- * @param {string} targetFile - The path to the text file to be checked (relative to CWD).
5
- * @param {string} row - The text row to be checked for existence.
6
- * @returns {boolean} True if the row exists in target file, false otherwise. Row must be matched completely, but surrounding whitespaces are ignored.
7
- * @throws Will throw an error if the path is invalid or the file does not exist.
8
- */
9
- export declare function hasText(targetFile: string, row: string): boolean;
File without changes