@decaf-ts/utils 0.1.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.
- package/LICENSE.md +157 -0
- package/README.md +95 -0
- package/dist/esm/utils.js +1 -0
- package/dist/types/bin/tag-release.d.ts +1 -0
- package/dist/types/bin/update-scripts.d.ts +1 -0
- package/dist/types/cli/command.d.ts +110 -0
- package/dist/types/cli/commands/index.d.ts +2 -0
- package/dist/types/cli/commands/tag-release.d.ts +105 -0
- package/dist/types/cli/commands/update-scripts.d.ts +211 -0
- package/dist/types/cli/constants.d.ts +73 -0
- package/dist/types/cli/index.d.ts +4 -0
- package/dist/types/cli/types.d.ts +28 -0
- package/dist/types/index.d.ts +39 -0
- package/dist/types/input/index.d.ts +2 -0
- package/dist/types/input/input.d.ts +472 -0
- package/dist/types/input/types.d.ts +76 -0
- package/dist/types/output/common.d.ts +51 -0
- package/dist/types/output/index.d.ts +3 -0
- package/dist/types/output/logging.d.ts +177 -0
- package/dist/types/output/types.d.ts +203 -0
- package/dist/types/utils/accumulator.d.ts +105 -0
- package/dist/types/utils/constants.d.ts +136 -0
- package/dist/types/utils/environment.d.ts +57 -0
- package/dist/types/utils/fs.d.ts +133 -0
- package/dist/types/utils/http.d.ts +41 -0
- package/dist/types/utils/index.d.ts +7 -0
- package/dist/types/utils/md.d.ts +156 -0
- package/dist/types/utils/tests.d.ts +170 -0
- package/dist/types/utils/text.d.ts +106 -0
- package/dist/types/utils/timeout.d.ts +1 -0
- package/dist/types/utils/types.d.ts +81 -0
- package/dist/types/utils/utils.d.ts +91 -0
- package/dist/types/utils/web.d.ts +7 -0
- package/dist/types/writers/OutputWriter.d.ts +49 -0
- package/dist/types/writers/RegexpOutputWriter.d.ts +69 -0
- package/dist/types/writers/StandardOutputWriter.d.ts +91 -0
- package/dist/types/writers/index.d.ts +4 -0
- package/dist/types/writers/types.d.ts +29 -0
- package/dist/utils.js +1 -0
- package/lib/assets/slogans.json +802 -0
- package/lib/bin/tag-release.cjs +12 -0
- package/lib/bin/update-scripts.cjs +12 -0
- package/lib/cli/command.cjs +153 -0
- package/lib/cli/commands/index.cjs +20 -0
- package/lib/cli/commands/tag-release.cjs +168 -0
- package/lib/cli/commands/update-scripts.cjs +511 -0
- package/lib/cli/constants.cjs +80 -0
- package/lib/cli/index.cjs +22 -0
- package/lib/cli/types.cjs +4 -0
- package/lib/esm/assets/slogans.json +802 -0
- package/lib/esm/bin/tag-release.js +10 -0
- package/lib/esm/bin/update-scripts.js +10 -0
- package/lib/esm/cli/command.js +149 -0
- package/lib/esm/cli/commands/index.js +4 -0
- package/lib/esm/cli/commands/tag-release.js +164 -0
- package/lib/esm/cli/commands/update-scripts.js +504 -0
- package/lib/esm/cli/constants.js +77 -0
- package/lib/esm/cli/index.js +6 -0
- package/lib/esm/cli/types.js +3 -0
- package/lib/esm/index.js +41 -0
- package/lib/esm/input/index.js +4 -0
- package/lib/esm/input/input.js +570 -0
- package/lib/esm/input/types.js +3 -0
- package/lib/esm/output/common.js +93 -0
- package/lib/esm/output/index.js +5 -0
- package/lib/esm/output/logging.js +350 -0
- package/lib/esm/output/types.js +3 -0
- package/lib/esm/utils/accumulator.js +145 -0
- package/lib/esm/utils/constants.js +176 -0
- package/lib/esm/utils/environment.js +91 -0
- package/lib/esm/utils/fs.js +271 -0
- package/lib/esm/utils/http.js +70 -0
- package/lib/esm/utils/index.js +9 -0
- package/lib/esm/utils/md.js +3 -0
- package/lib/esm/utils/tests.js +223 -0
- package/lib/esm/utils/text.js +142 -0
- package/lib/esm/utils/timeout.js +5 -0
- package/lib/esm/utils/types.js +3 -0
- package/lib/esm/utils/utils.js +220 -0
- package/lib/esm/utils/web.js +12 -0
- package/lib/esm/writers/OutputWriter.js +3 -0
- package/lib/esm/writers/RegexpOutputWriter.js +98 -0
- package/lib/esm/writers/StandardOutputWriter.js +127 -0
- package/lib/esm/writers/index.js +6 -0
- package/lib/esm/writers/types.js +3 -0
- package/lib/index.cjs +58 -0
- package/lib/input/index.cjs +20 -0
- package/lib/input/input.cjs +577 -0
- package/lib/input/types.cjs +4 -0
- package/lib/output/common.cjs +100 -0
- package/lib/output/index.cjs +21 -0
- package/lib/output/logging.cjs +355 -0
- package/lib/output/types.cjs +4 -0
- package/lib/utils/accumulator.cjs +149 -0
- package/lib/utils/constants.cjs +179 -0
- package/lib/utils/environment.cjs +95 -0
- package/lib/utils/fs.cjs +288 -0
- package/lib/utils/http.cjs +77 -0
- package/lib/utils/index.cjs +25 -0
- package/lib/utils/md.cjs +4 -0
- package/lib/utils/tests.cjs +263 -0
- package/lib/utils/text.cjs +153 -0
- package/lib/utils/timeout.cjs +8 -0
- package/lib/utils/types.cjs +4 -0
- package/lib/utils/utils.cjs +226 -0
- package/lib/utils/web.cjs +15 -0
- package/lib/writers/OutputWriter.cjs +4 -0
- package/lib/writers/RegexpOutputWriter.cjs +102 -0
- package/lib/writers/StandardOutputWriter.cjs +131 -0
- package/lib/writers/index.cjs +22 -0
- package/lib/writers/types.cjs +4 -0
- package/package.json +121 -0
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { DependencyMap, SimpleDependencyMap } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* @description Patches a file with given values.
|
|
4
|
+
* @summary Reads a file, applies patches using TextUtils, and writes the result back to the file.
|
|
5
|
+
*
|
|
6
|
+
* @param {string} path - The path to the file to be patched.
|
|
7
|
+
* @param {Record<string, number | string>} values - The values to patch into the file.
|
|
8
|
+
* @return {void}
|
|
9
|
+
*
|
|
10
|
+
* @function patchFile
|
|
11
|
+
*
|
|
12
|
+
* @mermaid
|
|
13
|
+
* sequenceDiagram
|
|
14
|
+
* participant Caller
|
|
15
|
+
* participant patchFile
|
|
16
|
+
* participant fs
|
|
17
|
+
* participant readFile
|
|
18
|
+
* participant TextUtils
|
|
19
|
+
* participant writeFile
|
|
20
|
+
* Caller->>patchFile: Call with path and values
|
|
21
|
+
* patchFile->>fs: Check if file exists
|
|
22
|
+
* patchFile->>readFile: Read file content
|
|
23
|
+
* readFile->>fs: Read file
|
|
24
|
+
* fs-->>readFile: Return file content
|
|
25
|
+
* readFile-->>patchFile: Return file content
|
|
26
|
+
* patchFile->>TextUtils: Patch string
|
|
27
|
+
* TextUtils-->>patchFile: Return patched content
|
|
28
|
+
* patchFile->>writeFile: Write patched content
|
|
29
|
+
* writeFile->>fs: Write to file
|
|
30
|
+
* fs-->>writeFile: File written
|
|
31
|
+
* writeFile-->>patchFile: File written
|
|
32
|
+
* patchFile-->>Caller: Patching complete
|
|
33
|
+
*
|
|
34
|
+
* @memberOf module:fs-utils
|
|
35
|
+
*/
|
|
36
|
+
export declare function patchFile(path: string, values: Record<string, number | string>): void;
|
|
37
|
+
/**
|
|
38
|
+
* @description Reads a file and returns its content.
|
|
39
|
+
* @summary Reads the content of a file at the specified path and returns it as a string.
|
|
40
|
+
*
|
|
41
|
+
* @param {string} path - The path to the file to be read.
|
|
42
|
+
* @return {string} The content of the file.
|
|
43
|
+
*
|
|
44
|
+
* @function readFile
|
|
45
|
+
*
|
|
46
|
+
* @memberOf module:utils
|
|
47
|
+
*/
|
|
48
|
+
export declare function readFile(path: string): string;
|
|
49
|
+
/**
|
|
50
|
+
* @description Writes data to a file.
|
|
51
|
+
* @summary Writes the provided data to a file at the specified path.
|
|
52
|
+
*
|
|
53
|
+
* @param {string} path - The path to the file to be written.
|
|
54
|
+
* @param {string | Buffer} data - The data to be written to the file.
|
|
55
|
+
* @return {void}
|
|
56
|
+
*
|
|
57
|
+
* @function writeFile
|
|
58
|
+
*
|
|
59
|
+
* @memberOf module:utils
|
|
60
|
+
*/
|
|
61
|
+
export declare function writeFile(path: string, data: string | Buffer): void;
|
|
62
|
+
/**
|
|
63
|
+
* @description Retrieves package information from package.json.
|
|
64
|
+
* @summary Loads and parses the package.json file from a specified directory or the current working directory. Can return the entire package object or a specific property.
|
|
65
|
+
* @param {string} [p=process.cwd()] - The directory path where the package.json file is located.
|
|
66
|
+
* @param {string} [property] - Optional. The specific property to retrieve from package.json.
|
|
67
|
+
* @return {object | string} The parsed contents of package.json or the value of the specified property.
|
|
68
|
+
* @function getPackage
|
|
69
|
+
* @mermaid
|
|
70
|
+
* sequenceDiagram
|
|
71
|
+
* participant Caller
|
|
72
|
+
* participant getPackage
|
|
73
|
+
* participant readFile
|
|
74
|
+
* participant JSON
|
|
75
|
+
* Caller->>getPackage: Call with path and optional property
|
|
76
|
+
* getPackage->>readFile: Read package.json
|
|
77
|
+
* readFile-->>getPackage: Return file content
|
|
78
|
+
* getPackage->>JSON: Parse file content
|
|
79
|
+
* JSON-->>getPackage: Return parsed object
|
|
80
|
+
* alt property specified
|
|
81
|
+
* getPackage->>getPackage: Check if property exists
|
|
82
|
+
* alt property exists
|
|
83
|
+
* getPackage-->>Caller: Return property value
|
|
84
|
+
* else property doesn't exist
|
|
85
|
+
* getPackage-->>Caller: Throw Error
|
|
86
|
+
* end
|
|
87
|
+
* else no property specified
|
|
88
|
+
* getPackage-->>Caller: Return entire package object
|
|
89
|
+
* end
|
|
90
|
+
* @memberOf module:utils
|
|
91
|
+
*/
|
|
92
|
+
export declare function getPackage(p?: string, property?: string): object | string;
|
|
93
|
+
export declare function setPackageAttribute(attr: string, value: string, p?: string): void;
|
|
94
|
+
/**
|
|
95
|
+
* @description Retrieves the version from package.json.
|
|
96
|
+
* @summary A convenience function that calls getPackage to retrieve the "version" property from package.json.
|
|
97
|
+
* @param {string} [p=process.cwd()] - The directory path where the package.json file is located.
|
|
98
|
+
* @return {string} The version string from package.json.
|
|
99
|
+
* @function getPackageVersion
|
|
100
|
+
* @memberOf module:fs-utils
|
|
101
|
+
*/
|
|
102
|
+
export declare function getPackageVersion(p?: string): string;
|
|
103
|
+
/**
|
|
104
|
+
* @description Retrieves all dependencies from the project.
|
|
105
|
+
* @summary Executes 'npm ls --json' command to get a detailed list of all dependencies (production, development, and peer) and their versions.
|
|
106
|
+
* @param {string} [path=process.cwd()] - The directory path of the project.
|
|
107
|
+
* @return {Promise<{prod: Array<{name: string, version: string}>, dev: Array<{name: string, version: string}>, peer: Array<{name: string, version: string}>}>} An object containing arrays of production, development, and peer dependencies.
|
|
108
|
+
* @function getDependencies
|
|
109
|
+
* @mermaid
|
|
110
|
+
* sequenceDiagram
|
|
111
|
+
* participant Caller
|
|
112
|
+
* participant getDependencies
|
|
113
|
+
* participant runCommand
|
|
114
|
+
* participant JSON
|
|
115
|
+
* Caller->>getDependencies: Call with optional path
|
|
116
|
+
* getDependencies->>runCommand: Execute 'npm ls --json'
|
|
117
|
+
* runCommand-->>getDependencies: Return command output
|
|
118
|
+
* getDependencies->>JSON: Parse command output
|
|
119
|
+
* JSON-->>getDependencies: Return parsed object
|
|
120
|
+
* getDependencies->>getDependencies: Process dependencies
|
|
121
|
+
* getDependencies-->>Caller: Return processed dependencies
|
|
122
|
+
* @memberOf module:fs-utils
|
|
123
|
+
*/
|
|
124
|
+
export declare function getDependencies(path?: string): Promise<DependencyMap>;
|
|
125
|
+
export declare function updateDependencies(): Promise<void>;
|
|
126
|
+
export declare function installIfNotAvailable(deps: string[] | string, dependencies?: SimpleDependencyMap): Promise<SimpleDependencyMap>;
|
|
127
|
+
export declare function pushToGit(): Promise<void>;
|
|
128
|
+
export declare function installDependencies(dependencies: {
|
|
129
|
+
prod?: string[];
|
|
130
|
+
dev?: string[];
|
|
131
|
+
peer?: string[];
|
|
132
|
+
}): Promise<void>;
|
|
133
|
+
export declare function normalizeImport<T>(importPromise: Promise<T>): Promise<T>;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @description A simple HTTP client for downloading files.
|
|
3
|
+
* @summary This class provides functionality to download files from HTTPS URLs.
|
|
4
|
+
* It uses Node.js built-in https module to make requests.
|
|
5
|
+
*
|
|
6
|
+
* @class
|
|
7
|
+
*/
|
|
8
|
+
export declare class HttpClient {
|
|
9
|
+
protected static log: import("..").VerbosityLogger;
|
|
10
|
+
/**
|
|
11
|
+
* @description Downloads a file from a given URL.
|
|
12
|
+
* @summary This method sends a GET request to the specified URL and returns the response body as a string.
|
|
13
|
+
* It handles different scenarios such as non-200 status codes and network errors.
|
|
14
|
+
*
|
|
15
|
+
* @param url - The URL of the file to download.
|
|
16
|
+
* @return A promise that resolves with the file content as a string.
|
|
17
|
+
*
|
|
18
|
+
* @mermaid
|
|
19
|
+
* sequenceDiagram
|
|
20
|
+
* participant Client
|
|
21
|
+
* participant HttpClient
|
|
22
|
+
* participant HTTPS
|
|
23
|
+
* participant Server
|
|
24
|
+
* Client->>HttpClient: downloadFile(url)
|
|
25
|
+
* HttpClient->>HTTPS: get(url)
|
|
26
|
+
* HTTPS->>Server: GET request
|
|
27
|
+
* Server-->>HTTPS: Response
|
|
28
|
+
* HTTPS-->>HttpClient: Response object
|
|
29
|
+
* alt Status code is 200
|
|
30
|
+
* loop For each data chunk
|
|
31
|
+
* HTTPS->>HttpClient: 'data' event
|
|
32
|
+
* HttpClient->>HttpClient: Accumulate data
|
|
33
|
+
* end
|
|
34
|
+
* HTTPS->>HttpClient: 'end' event
|
|
35
|
+
* HttpClient-->>Client: Resolve with data
|
|
36
|
+
* else Status code is not 200
|
|
37
|
+
* HttpClient-->>Client: Reject with error
|
|
38
|
+
* end
|
|
39
|
+
*/
|
|
40
|
+
static downloadFile(url: string): Promise<string>;
|
|
41
|
+
}
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @description Single line markdown element type
|
|
3
|
+
* @summary Represents the possible header levels in markdown
|
|
4
|
+
* @typedef {"h1"|"h2"|"h3"|"h4"|"h5"|"h6"} MdSingleLineElement
|
|
5
|
+
* @memberOf @decaf-ts/utils
|
|
6
|
+
*/
|
|
7
|
+
export type MdSingleLineElement = "h1" | "h2" | "h3" | "h4" | "h5" | "h6";
|
|
8
|
+
/**
|
|
9
|
+
* @description Multi-line element types in markdown
|
|
10
|
+
* @summary Defines the available multi-line element types
|
|
11
|
+
* @typedef {"p"|"blockquote"} MdMultiLineElement
|
|
12
|
+
* @memberOf @decaf-ts/utils
|
|
13
|
+
*/
|
|
14
|
+
export type MdMultiLineElement = "p" | "blockquote";
|
|
15
|
+
/**
|
|
16
|
+
* @description List element types in markdown
|
|
17
|
+
* @summary Defines the available list types
|
|
18
|
+
* @typedef {"ul"|"ol"} MdListElement
|
|
19
|
+
* @memberOf @decaf-ts/utils
|
|
20
|
+
*/
|
|
21
|
+
export type MdListElement = "ul" | "ol";
|
|
22
|
+
/**
|
|
23
|
+
* @description List element types in markdown
|
|
24
|
+
* @summary Defines the available list types
|
|
25
|
+
* @typedef {Object} MdSingleLine
|
|
26
|
+
* @property {string} [ul] - unordered list
|
|
27
|
+
* @property {string} [ol] - ordered list
|
|
28
|
+
* @memberOf @decaf-ts/utils
|
|
29
|
+
*/
|
|
30
|
+
export type MdSingleLine = {
|
|
31
|
+
[k in MdSingleLineElement]?: string;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* @description Multi-line markdown element type
|
|
35
|
+
* @summary Represents markdown elements that can contain multiple lines of text
|
|
36
|
+
* @typedef {Object} MdMultiLine
|
|
37
|
+
* @property {string|string[]} [p] - Paragraph content
|
|
38
|
+
* @property {string|string[]} [blockquote] - Blockquote content
|
|
39
|
+
* @memberOf @decaf-ts/utils
|
|
40
|
+
*/
|
|
41
|
+
export type MdMultiLine = {
|
|
42
|
+
[k in MdMultiLineElement]?: string | string[];
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* @description Image definition type in markdown
|
|
46
|
+
* @summary Defines the structure for image elements
|
|
47
|
+
* @typedef {Object} MdImageDefinition
|
|
48
|
+
* @property {string} [title] - Optional image title
|
|
49
|
+
* @property {string} source - Image source URL
|
|
50
|
+
* @property {string} [alt] - Optional alternative text
|
|
51
|
+
* @memberOf @decaf-ts/utils
|
|
52
|
+
*/
|
|
53
|
+
export type MdImageDefinition = {
|
|
54
|
+
title?: string;
|
|
55
|
+
source: string;
|
|
56
|
+
alt?: string;
|
|
57
|
+
};
|
|
58
|
+
/**
|
|
59
|
+
* @description Image element type in markdown
|
|
60
|
+
* @summary Represents an image element with its properties
|
|
61
|
+
* @typedef {Object} MdImage
|
|
62
|
+
* @property {MdImageDefinition} img - The image definition object
|
|
63
|
+
* @memberOf @decaf-ts/utils
|
|
64
|
+
*/
|
|
65
|
+
export type MdImage = {
|
|
66
|
+
img: MdImageDefinition;
|
|
67
|
+
};
|
|
68
|
+
/**
|
|
69
|
+
* @description List item element type in markdown
|
|
70
|
+
* @summary Represents ordered and unordered lists in markdown
|
|
71
|
+
* @typedef {Object} MdListItem
|
|
72
|
+
* @property {string[]} ul - Unordered list items
|
|
73
|
+
* @property {string[]} ol - Ordered list items
|
|
74
|
+
* @memberOf @decaf-ts/utils
|
|
75
|
+
*/
|
|
76
|
+
export type MdListItem = {
|
|
77
|
+
[k in MdListElement]: string[];
|
|
78
|
+
};
|
|
79
|
+
/**
|
|
80
|
+
* @description Table definition type in markdown
|
|
81
|
+
* @summary Defines the structure for table elements
|
|
82
|
+
* @typedef {Object} MdTableDefinition
|
|
83
|
+
* @property {string[]} headers - Array of table header names
|
|
84
|
+
* @property {Object[]} rows - Array of row objects containing column values
|
|
85
|
+
* @memberOf @decaf-ts/utils
|
|
86
|
+
*/
|
|
87
|
+
export type MdTableDefinition = {
|
|
88
|
+
headers: string[];
|
|
89
|
+
rows: {
|
|
90
|
+
[column: string]: string | string[];
|
|
91
|
+
}[];
|
|
92
|
+
};
|
|
93
|
+
/**
|
|
94
|
+
* @description Table element type in markdown
|
|
95
|
+
* @summary Represents a table structure with headers and rows
|
|
96
|
+
* @typedef {Object} MdTable
|
|
97
|
+
* @property {MdTableDefinition} table - The table definition object
|
|
98
|
+
* @memberOf @decaf-ts/utils
|
|
99
|
+
*/
|
|
100
|
+
export type MdTable = {
|
|
101
|
+
table: MdTableDefinition;
|
|
102
|
+
};
|
|
103
|
+
/**
|
|
104
|
+
* @description Code block definition type in markdown
|
|
105
|
+
* @summary Defines the structure for code blocks
|
|
106
|
+
* @typedef {Object} MdCodeDefinition
|
|
107
|
+
* @property {string} [language] - Optional programming language specification
|
|
108
|
+
* @property {string|string[]} content - The code content as string or array of strings
|
|
109
|
+
* @memberOf @decaf-ts/utils
|
|
110
|
+
*/
|
|
111
|
+
export type MdCodeDefinition = {
|
|
112
|
+
language?: string;
|
|
113
|
+
content: string | string[];
|
|
114
|
+
};
|
|
115
|
+
/**
|
|
116
|
+
* @description Code block element type in markdown
|
|
117
|
+
* @summary Represents a code block with optional language specification
|
|
118
|
+
* @typedef {Object} MdCode
|
|
119
|
+
* @property {MdCodeDefinition} code - The code block definition object
|
|
120
|
+
* @memberOf @decaf-ts/utils
|
|
121
|
+
*/
|
|
122
|
+
export type MdCode = {
|
|
123
|
+
code: MdCodeDefinition;
|
|
124
|
+
};
|
|
125
|
+
/**
|
|
126
|
+
* @description Horizontal rule element type in markdown
|
|
127
|
+
* @summary Represents a horizontal rule separator
|
|
128
|
+
* @typedef {Object} MdSeparator
|
|
129
|
+
* @property {string} hr - The horizontal rule representation
|
|
130
|
+
* @memberOf @decaf-ts/utils
|
|
131
|
+
*/
|
|
132
|
+
export type MdSeparator = {
|
|
133
|
+
hr: string;
|
|
134
|
+
};
|
|
135
|
+
/**
|
|
136
|
+
* @description Link element type in markdown
|
|
137
|
+
* @summary Represents a hyperlink with title and source
|
|
138
|
+
* @typedef {Object} MdLink
|
|
139
|
+
* @property {{title: string, source: string}} link - The link definition object
|
|
140
|
+
* @memberOf @decaf-ts/utils
|
|
141
|
+
*/
|
|
142
|
+
export type MdLink = {
|
|
143
|
+
link: {
|
|
144
|
+
title: string;
|
|
145
|
+
source: string;
|
|
146
|
+
};
|
|
147
|
+
};
|
|
148
|
+
/**
|
|
149
|
+
* @description Markdown element type definition
|
|
150
|
+
* @summary Represents all possible markdown elements that can be used in document generation.
|
|
151
|
+
* This type combines various markdown elements including headers, paragraphs, images, lists,
|
|
152
|
+
* tables, code blocks, separators, and links into a union type for flexible markdown content creation.
|
|
153
|
+
* @typedef {(MdSingleLine | MdMultiLine | MdImage | MdListItem | MdTable | MdCode | MdSeparator | MdLink)} MdElements
|
|
154
|
+
* @memberOf @decaf-ts/utils
|
|
155
|
+
*/
|
|
156
|
+
export type MdElements = MdSingleLine | MdMultiLine | MdImage | MdListItem | MdTable | MdCode | MdSeparator | MdLink;
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import { MdTableDefinition } from "./md";
|
|
2
|
+
/**
|
|
3
|
+
* @interface AddAttachParams
|
|
4
|
+
* @description Parameters for adding an attachment to a report
|
|
5
|
+
* @summary Interface for attachment parameters
|
|
6
|
+
* @memberOf module:@decaf-ts/utils
|
|
7
|
+
*/
|
|
8
|
+
export interface AddAttachParams {
|
|
9
|
+
attach: string | Buffer;
|
|
10
|
+
description: string | object;
|
|
11
|
+
context?: any;
|
|
12
|
+
bufferFormat?: string;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* @interface AddMsgParams
|
|
16
|
+
* @description Parameters for adding a message to a report
|
|
17
|
+
* @summary Interface for message parameters
|
|
18
|
+
* @memberOf module:@decaf-ts/utils
|
|
19
|
+
*/
|
|
20
|
+
export interface AddMsgParams {
|
|
21
|
+
message: string | object;
|
|
22
|
+
context?: any;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* @typedef {("json"|"image"|"text"|"md")} PayloadType
|
|
26
|
+
* @description Types of payloads that can be handled
|
|
27
|
+
* @summary Union type for payload types
|
|
28
|
+
* @memberOf module:@decaf-ts/utils
|
|
29
|
+
*/
|
|
30
|
+
export type PayloadType = "json" | "image" | "text" | "md";
|
|
31
|
+
export declare const JestReportersTempPathEnvKey = "JEST_HTML_REPORTERS_TEMP_DIR_PATH";
|
|
32
|
+
/**
|
|
33
|
+
* @description Test reporting utility class for managing test results and evidence
|
|
34
|
+
* @summary A comprehensive test reporter that handles various types of test artifacts including messages,
|
|
35
|
+
* attachments, data, images, tables, and graphs. It provides methods to report and store test evidence
|
|
36
|
+
* in different formats and manages dependencies for reporting functionality.
|
|
37
|
+
*
|
|
38
|
+
* @template T - Type of data being reported
|
|
39
|
+
* @param {string} [testCase="tests"] - Name of the test case
|
|
40
|
+
* @param {string} [basePath] - Base path for storing test reports
|
|
41
|
+
* @class
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```typescript
|
|
45
|
+
* const reporter = new TestReporter('login-test');
|
|
46
|
+
*
|
|
47
|
+
* // Report test messages
|
|
48
|
+
* await reporter.reportMessage('Test Started', 'Login flow initiated');
|
|
49
|
+
*
|
|
50
|
+
* // Report test data
|
|
51
|
+
* await reporter.reportData('user-credentials', { username: 'test' }, 'json');
|
|
52
|
+
*
|
|
53
|
+
* // Report test results table
|
|
54
|
+
* await reporter.reportTable('test-results', {
|
|
55
|
+
* headers: ['Step', 'Status'],
|
|
56
|
+
* rows: [
|
|
57
|
+
* { Step: 'Login', Status: 'Pass' },
|
|
58
|
+
* { Step: 'Validation', Status: 'Pass' }
|
|
59
|
+
* ]
|
|
60
|
+
* });
|
|
61
|
+
*
|
|
62
|
+
* // Report test evidence
|
|
63
|
+
* await reporter.reportAttachment('Screenshot', screenshotBuffer);
|
|
64
|
+
* ```
|
|
65
|
+
*
|
|
66
|
+
* @mermaid
|
|
67
|
+
* sequenceDiagram
|
|
68
|
+
* participant Client
|
|
69
|
+
* participant TestReporter
|
|
70
|
+
* participant FileSystem
|
|
71
|
+
* participant Dependencies
|
|
72
|
+
*
|
|
73
|
+
* Client->>TestReporter: new TestReporter(testCase, basePath)
|
|
74
|
+
* TestReporter->>FileSystem: Create report directory
|
|
75
|
+
*
|
|
76
|
+
* alt Report Message
|
|
77
|
+
* Client->>TestReporter: reportMessage(title, message)
|
|
78
|
+
* TestReporter->>Dependencies: Import helpers
|
|
79
|
+
* TestReporter->>FileSystem: Store message
|
|
80
|
+
* else Report Data
|
|
81
|
+
* Client->>TestReporter: reportData(reference, data, type)
|
|
82
|
+
* TestReporter->>Dependencies: Process data
|
|
83
|
+
* TestReporter->>FileSystem: Store formatted data
|
|
84
|
+
* else Report Table
|
|
85
|
+
* Client->>TestReporter: reportTable(reference, tableDef)
|
|
86
|
+
* TestReporter->>Dependencies: Convert to MD format
|
|
87
|
+
* TestReporter->>FileSystem: Store table
|
|
88
|
+
* end
|
|
89
|
+
*/
|
|
90
|
+
export declare class TestReporter {
|
|
91
|
+
protected testCase: string;
|
|
92
|
+
protected basePath: string;
|
|
93
|
+
/**
|
|
94
|
+
* @description Function for adding messages to the test report
|
|
95
|
+
* @summary Static handler for processing and storing test messages
|
|
96
|
+
* @type {function(AddMsgParams): Promise<void>}
|
|
97
|
+
*/
|
|
98
|
+
protected static addMsgFunction: (params: AddMsgParams) => Promise<void>;
|
|
99
|
+
/**
|
|
100
|
+
* @description Function for adding attachments to the test report
|
|
101
|
+
* @summary Static handler for processing and storing test attachments
|
|
102
|
+
* @type {function(AddAttachParams): Promise<void>}
|
|
103
|
+
*/
|
|
104
|
+
protected static addAttachFunction: (params: AddAttachParams) => Promise<void>;
|
|
105
|
+
/**
|
|
106
|
+
* @description Map of dependencies required by the reporter
|
|
107
|
+
* @summary Stores the current state of dependencies
|
|
108
|
+
* @type {SimpleDependencyMap}
|
|
109
|
+
*/
|
|
110
|
+
private deps?;
|
|
111
|
+
constructor(testCase?: string, basePath?: string);
|
|
112
|
+
/**
|
|
113
|
+
* @description Imports required helper functions
|
|
114
|
+
* @summary Ensures all necessary dependencies are available and imports helper functions
|
|
115
|
+
* @return {Promise<void>} Promise that resolves when helpers are imported
|
|
116
|
+
*/
|
|
117
|
+
private importHelpers;
|
|
118
|
+
/**
|
|
119
|
+
* @description Reports a message to the test report
|
|
120
|
+
* @summary Adds a formatted message to the test report with an optional title
|
|
121
|
+
* @param {string} title - Title of the message
|
|
122
|
+
* @param {string | object} message - Content of the message
|
|
123
|
+
* @return {Promise<void>} Promise that resolves when the message is reported
|
|
124
|
+
*/
|
|
125
|
+
reportMessage(title: string, message: string | object): Promise<void>;
|
|
126
|
+
/**
|
|
127
|
+
* @description Reports an attachment to the test report
|
|
128
|
+
* @summary Adds a formatted message to the test report with an optional title
|
|
129
|
+
* @param {string} title - Title of the message
|
|
130
|
+
* @param {string | Buffer} attachment - Content of the message
|
|
131
|
+
* @return {Promise<void>} Promise that resolves when the message is reported
|
|
132
|
+
*/
|
|
133
|
+
reportAttachment(title: string, attachment: string | Buffer): Promise<void>;
|
|
134
|
+
/**
|
|
135
|
+
* @description Reports data with specified type
|
|
136
|
+
* @summary Processes and stores data in the test report with formatting
|
|
137
|
+
* @param {string} reference - Reference identifier for the data
|
|
138
|
+
* @param {string | number | object} data - Data to be reported
|
|
139
|
+
* @param {PayloadType} type - Type of the payload
|
|
140
|
+
* @param {boolean} [trim=false] - Whether to trim the data
|
|
141
|
+
* @return {Promise<void>} Promise that resolves when data is reported
|
|
142
|
+
*/
|
|
143
|
+
protected report(reference: string, data: string | number | object | Buffer, type: PayloadType, trim?: boolean): Promise<void>;
|
|
144
|
+
reportData(reference: string, data: string | number | object, type?: PayloadType, trim?: boolean): Promise<void>;
|
|
145
|
+
reportObject(reference: string, json: object, trim?: boolean): Promise<void>;
|
|
146
|
+
/**
|
|
147
|
+
* @description Reports a table in markdown format
|
|
148
|
+
* @summary Converts and stores a table definition in markdown format
|
|
149
|
+
* @param {string} reference - Reference identifier for the table
|
|
150
|
+
* @param {MdTableDefinition} tableDef - Table definition object
|
|
151
|
+
* @return {Promise<void>} Promise that resolves when table is reported
|
|
152
|
+
*/
|
|
153
|
+
reportTable(reference: string, tableDef: MdTableDefinition): Promise<void>;
|
|
154
|
+
/**
|
|
155
|
+
* @description Reports a graph using Chart.js
|
|
156
|
+
* @summary Generates and stores a graph visualization
|
|
157
|
+
* @param {string} reference - Reference identifier for the graph
|
|
158
|
+
* @param {any} config - Chart.js configuration object
|
|
159
|
+
* @return {Promise<void>} Promise that resolves when graph is reported
|
|
160
|
+
*/
|
|
161
|
+
reportGraph(reference: string, config: any): Promise<void>;
|
|
162
|
+
/**
|
|
163
|
+
* @description Reports an image to the test report
|
|
164
|
+
* @summary Stores an image buffer in the test report
|
|
165
|
+
* @param {string} reference - Reference identifier for the image
|
|
166
|
+
* @param {Buffer} buffer - Image data buffer
|
|
167
|
+
* @return {Promise<void>} Promise that resolves when image is reported
|
|
168
|
+
*/
|
|
169
|
+
reportImage(reference: string, buffer: Buffer): Promise<void>;
|
|
170
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @description Pads the end of a string with a specified character.
|
|
3
|
+
* @summary Extends the input string to a specified length by adding a padding character to the end.
|
|
4
|
+
* If the input string is already longer than the specified length, it is returned unchanged.
|
|
5
|
+
*
|
|
6
|
+
* @param {string} str - The input string to be padded.
|
|
7
|
+
* @param {number} length - The desired total length of the resulting string.
|
|
8
|
+
* @param {string} [char=" "] - The character to use for padding. Defaults to a space.
|
|
9
|
+
* @return {string} The padded string.
|
|
10
|
+
* @throws {Error} If the padding character is not exactly one character long.
|
|
11
|
+
*
|
|
12
|
+
* @function padEnd
|
|
13
|
+
*
|
|
14
|
+
* @memberOf module:TextUtils
|
|
15
|
+
*/
|
|
16
|
+
export declare function padEnd(str: string, length: number, char?: string): string;
|
|
17
|
+
/**
|
|
18
|
+
* @description Replaces placeholders in a string with provided values.
|
|
19
|
+
* @summary Interpolates a string by replacing placeholders of the form ${variableName}
|
|
20
|
+
* with corresponding values from the provided object. If a placeholder doesn't have
|
|
21
|
+
* a corresponding value, it is left unchanged in the string.
|
|
22
|
+
*
|
|
23
|
+
* @param {string} input - The input string containing placeholders to be replaced.
|
|
24
|
+
* @param {Record<string, number | string>} values - An object containing key-value pairs for replacement.
|
|
25
|
+
* @return {string} The interpolated string with placeholders replaced by their corresponding values.
|
|
26
|
+
*
|
|
27
|
+
* @function patchPlaceholders
|
|
28
|
+
*
|
|
29
|
+
* @mermaid
|
|
30
|
+
* sequenceDiagram
|
|
31
|
+
* participant Caller
|
|
32
|
+
* participant patchString
|
|
33
|
+
* participant String.replace
|
|
34
|
+
* Caller->>patchString: Call with input and values
|
|
35
|
+
* patchString->>String.replace: Call with regex and replacement function
|
|
36
|
+
* String.replace->>patchString: Return replaced string
|
|
37
|
+
* patchString-->>Caller: Return patched string
|
|
38
|
+
*
|
|
39
|
+
* @memberOf module:TextUtils
|
|
40
|
+
*/
|
|
41
|
+
export declare function patchPlaceholders(input: string, values: Record<string, number | string>): string;
|
|
42
|
+
export declare function patchString(input: string, values: Record<string, number | string>, flags?: string): string;
|
|
43
|
+
/**
|
|
44
|
+
* @description Converts a string to camelCase.
|
|
45
|
+
* @summary Transforms the input string into camelCase format, where words are joined without spaces
|
|
46
|
+
* and each word after the first starts with a capital letter.
|
|
47
|
+
*
|
|
48
|
+
* @param {string} text - The input string to be converted.
|
|
49
|
+
* @return {string} The input string converted to camelCase.
|
|
50
|
+
*
|
|
51
|
+
* @function toCamelCase
|
|
52
|
+
*
|
|
53
|
+
* @memberOf module:TextUtils
|
|
54
|
+
*/
|
|
55
|
+
export declare function toCamelCase(text: string): string;
|
|
56
|
+
/**
|
|
57
|
+
* @description Converts a string to ENVIRONMENT_VARIABLE format.
|
|
58
|
+
* @summary Transforms the input string into uppercase with words separated by underscores,
|
|
59
|
+
* typically used for environment variable names.
|
|
60
|
+
*
|
|
61
|
+
* @param {string} text - The input string to be converted.
|
|
62
|
+
* @return {string} The input string converted to ENVIRONMENT_VARIABLE format.
|
|
63
|
+
*
|
|
64
|
+
* @function toENVFormat
|
|
65
|
+
*
|
|
66
|
+
* @memberOf module:TextUtils
|
|
67
|
+
*/
|
|
68
|
+
export declare function toENVFormat(text: string): string;
|
|
69
|
+
/**
|
|
70
|
+
* @description Converts a string to snake_case.
|
|
71
|
+
* @summary Transforms the input string into lowercase with words separated by underscores.
|
|
72
|
+
*
|
|
73
|
+
* @param {string} text - The input string to be converted.
|
|
74
|
+
* @return {string} The input string converted to snake_case.
|
|
75
|
+
*
|
|
76
|
+
* @function toSnakeCase
|
|
77
|
+
*
|
|
78
|
+
* @memberOf module:TextUtils
|
|
79
|
+
*/
|
|
80
|
+
export declare function toSnakeCase(text: string): string;
|
|
81
|
+
/**
|
|
82
|
+
* @description Converts a string to kebab-case.
|
|
83
|
+
* @summary Transforms the input string into lowercase with words separated by hyphens.
|
|
84
|
+
*
|
|
85
|
+
* @param {string} text - The input string to be converted.
|
|
86
|
+
* @return {string} The input string converted to kebab-case.
|
|
87
|
+
*
|
|
88
|
+
* @function toKebabCase
|
|
89
|
+
*
|
|
90
|
+
* @memberOf module:TextUtils
|
|
91
|
+
*/
|
|
92
|
+
export declare function toKebabCase(text: string): string;
|
|
93
|
+
/**
|
|
94
|
+
* @description Converts a string to PascalCase.
|
|
95
|
+
* @summary Transforms the input string into PascalCase format, where words are joined without spaces
|
|
96
|
+
* and each word starts with a capital letter.
|
|
97
|
+
*
|
|
98
|
+
* @param {string} text - The input string to be converted.
|
|
99
|
+
* @return {string} The input string converted to PascalCase.
|
|
100
|
+
*
|
|
101
|
+
* @function toPascalCase
|
|
102
|
+
*
|
|
103
|
+
* @memberOf module:TextUtils
|
|
104
|
+
*/
|
|
105
|
+
export declare function toPascalCase(text: string): string;
|
|
106
|
+
export declare function escapeRegExp(string: string): string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function awaitTimeout(ms: number): Promise<void>;
|