@decaf-ts/utils 1.1.0 → 1.2.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.
- package/README.md +1 -1
- package/dist/utils.cjs +1 -1
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.js +1 -1
- package/dist/utils.js.map +1 -1
- package/lib/cjs/cli/commands/build-scripts.cjs +87 -0
- package/lib/cjs/cli/commands/build-scripts.cjs.map +1 -1
- package/lib/cjs/index.cjs +1 -1
- package/lib/esm/cli/commands/build-scripts.js +87 -0
- package/lib/esm/cli/commands/build-scripts.js.map +1 -1
- package/lib/esm/index.js +1 -1
- package/lib/types/assets/slogans.d.cts +19 -0
- package/lib/types/assets/slogans.d.mts +19 -0
- package/lib/types/bin/build-scripts.d.cts +1 -0
- package/lib/types/bin/build-scripts.d.mts +1 -0
- package/lib/types/bin/release-chain-dispatch.d.cts +1 -0
- package/lib/types/bin/release-chain-dispatch.d.mts +1 -0
- package/lib/types/bin/release-chain.d.cts +1 -0
- package/lib/types/bin/release-chain.d.mts +1 -0
- package/lib/types/bin/tag-release.d.cts +1 -0
- package/lib/types/bin/tag-release.d.mts +1 -0
- package/lib/types/cli/command.d.cts +104 -0
- package/lib/types/cli/command.d.mts +104 -0
- package/lib/types/cli/commands/build-scripts.d.cts +148 -0
- package/lib/types/cli/commands/build-scripts.d.mts +148 -0
- package/lib/types/cli/commands/build-scripts.d.ts +3 -0
- package/lib/types/cli/commands/index.d.cts +3 -0
- package/lib/types/cli/commands/index.d.mts +3 -0
- package/lib/types/cli/commands/release-chain.d.cts +62 -0
- package/lib/types/cli/commands/release-chain.d.mts +62 -0
- package/lib/types/cli/commands/tag-release.d.cts +105 -0
- package/lib/types/cli/commands/tag-release.d.mts +105 -0
- package/lib/types/cli/constants.d.cts +75 -0
- package/lib/types/cli/constants.d.mts +75 -0
- package/lib/types/cli/index.d.cts +4 -0
- package/lib/types/cli/index.d.mts +4 -0
- package/lib/types/cli/types.d.cts +30 -0
- package/lib/types/cli/types.d.mts +30 -0
- package/lib/types/index.d.cts +38 -0
- package/lib/types/index.d.mts +38 -0
- package/lib/types/index.d.ts +1 -1
- package/lib/types/input/index.d.cts +2 -0
- package/lib/types/input/index.d.mts +2 -0
- package/lib/types/input/input.d.cts +517 -0
- package/lib/types/input/input.d.mts +517 -0
- package/lib/types/input/types.d.cts +159 -0
- package/lib/types/input/types.d.mts +159 -0
- package/lib/types/output/common.d.cts +53 -0
- package/lib/types/output/common.d.mts +53 -0
- package/lib/types/output/index.d.cts +1 -0
- package/lib/types/output/index.d.mts +1 -0
- package/lib/types/release-chain/index.d.cts +43 -0
- package/lib/types/release-chain/index.d.mts +43 -0
- package/lib/types/tests/Consumer.d.cts +151 -0
- package/lib/types/tests/Consumer.d.mts +151 -0
- package/lib/types/tests/ProducerChildProcess.d.cts +18 -0
- package/lib/types/tests/ProducerChildProcess.d.mts +18 -0
- package/lib/types/tests/TestReporter.d.cts +245 -0
- package/lib/types/tests/TestReporter.d.mts +245 -0
- package/lib/types/tests/index.d.cts +4 -0
- package/lib/types/tests/index.d.mts +4 -0
- package/lib/types/tests/jestPerformanceRunner.d.cts +37 -0
- package/lib/types/tests/jestPerformanceRunner.d.mts +37 -0
- package/lib/types/tests/utils.d.cts +5 -0
- package/lib/types/tests/utils.d.mts +5 -0
- package/lib/types/utils/constants.d.cts +65 -0
- package/lib/types/utils/constants.d.mts +65 -0
- package/lib/types/utils/fs.d.cts +259 -0
- package/lib/types/utils/fs.d.mts +259 -0
- package/lib/types/utils/http.d.cts +41 -0
- package/lib/types/utils/http.d.mts +41 -0
- package/lib/types/utils/index.d.cts +6 -0
- package/lib/types/utils/index.d.mts +6 -0
- package/lib/types/utils/md.d.cts +156 -0
- package/lib/types/utils/md.d.mts +156 -0
- package/lib/types/utils/performanceRunner.d.cts +129 -0
- package/lib/types/utils/performanceRunner.d.mts +129 -0
- package/lib/types/utils/timeout.d.cts +12 -0
- package/lib/types/utils/timeout.d.mts +12 -0
- package/lib/types/utils/types.d.cts +112 -0
- package/lib/types/utils/types.d.mts +112 -0
- package/lib/types/utils/utils.d.cts +133 -0
- package/lib/types/utils/utils.d.mts +133 -0
- package/lib/types/writers/OutputWriter.d.cts +49 -0
- package/lib/types/writers/OutputWriter.d.mts +49 -0
- package/lib/types/writers/RegexpOutputWriter.d.cts +110 -0
- package/lib/types/writers/RegexpOutputWriter.d.mts +110 -0
- package/lib/types/writers/StandardOutputWriter.d.cts +130 -0
- package/lib/types/writers/StandardOutputWriter.d.mts +130 -0
- package/lib/types/writers/index.d.cts +4 -0
- package/lib/types/writers/index.d.mts +4 -0
- package/lib/types/writers/types.d.cts +29 -0
- package/lib/types/writers/types.d.mts +29 -0
- package/package.json +14 -8
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @description Default encoding for text operations.
|
|
3
|
+
* @summary The standard UTF-8 encoding used for text processing.
|
|
4
|
+
* @const {string} Encoding
|
|
5
|
+
* @memberOf module:utils
|
|
6
|
+
*/
|
|
7
|
+
export declare const Encoding = "utf-8";
|
|
8
|
+
/**
|
|
9
|
+
* @description Regular expression for semantic versioning.
|
|
10
|
+
* @summary A regex pattern to match and parse semantic version strings.
|
|
11
|
+
* @const {RegExp} SemVersionRegex
|
|
12
|
+
* @memberOf module:utils
|
|
13
|
+
*/
|
|
14
|
+
export declare const SemVersionRegex: RegExp;
|
|
15
|
+
/**
|
|
16
|
+
* @description Enum for semantic version components.
|
|
17
|
+
* @summary Defines the three levels of semantic versioning: PATCH, MINOR, and MAJOR.
|
|
18
|
+
* @enum {string}
|
|
19
|
+
* @memberOf module:utils
|
|
20
|
+
*/
|
|
21
|
+
export declare enum SemVersion {
|
|
22
|
+
/** Patch version for backwards-compatible bug fixes. */
|
|
23
|
+
PATCH = "patch",
|
|
24
|
+
/** Minor version for backwards-compatible new features. */
|
|
25
|
+
MINOR = "minor",
|
|
26
|
+
/** Major version for changes that break backwards compatibility. */
|
|
27
|
+
MAJOR = "major"
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* @description Flag to indicate non-CI environment.
|
|
31
|
+
* @summary Used to specify that a command should run outside of a Continuous Integration environment.
|
|
32
|
+
* @const {string} NoCIFLag
|
|
33
|
+
* @memberOf module:utils
|
|
34
|
+
*/
|
|
35
|
+
export declare const NoCIFLag = "-no-ci";
|
|
36
|
+
/**
|
|
37
|
+
* @description Key for the setup script in package.json.
|
|
38
|
+
* @summary Identifies the script that runs after package installation.
|
|
39
|
+
* @const {string} SetupScriptKey
|
|
40
|
+
* @memberOf module:utils
|
|
41
|
+
*/
|
|
42
|
+
export declare const SetupScriptKey = "postinstall";
|
|
43
|
+
/**
|
|
44
|
+
* @description Enum for various authentication tokens.
|
|
45
|
+
* @summary Defines the file names for storing different types of authentication tokens.
|
|
46
|
+
* @enum {string}
|
|
47
|
+
* @memberOf module:utils
|
|
48
|
+
*/
|
|
49
|
+
export declare enum Tokens {
|
|
50
|
+
/** Git authentication token file name. */
|
|
51
|
+
GIT = ".token",
|
|
52
|
+
/** NPM authentication token file name. */
|
|
53
|
+
NPM = ".npmtoken",
|
|
54
|
+
/** Docker authentication token file name. */
|
|
55
|
+
DOCKER = ".dockertoken",
|
|
56
|
+
/** Confluence authentication token file name. */
|
|
57
|
+
CONFLUENCE = ".confluence-token"
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* @description Code used to indicate an operation was aborted.
|
|
61
|
+
* @summary Standard message used when a process is manually terminated.
|
|
62
|
+
* @const {string} AbortCode
|
|
63
|
+
* @memberOf module:utils
|
|
64
|
+
*/
|
|
65
|
+
export declare const AbortCode = "Aborted";
|
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import { DependencyMap, SimpleDependencyMap } from "./types.cjs";
|
|
3
|
+
/**
|
|
4
|
+
* @description Patches a file with given values.
|
|
5
|
+
* @summary Reads a file, applies patches using TextUtils, and writes the result back to the file.
|
|
6
|
+
*
|
|
7
|
+
* @param {string} path - The path to the file to be patched.
|
|
8
|
+
* @param {Record<string, number | string>} values - The values to patch into the file.
|
|
9
|
+
* @return {void}
|
|
10
|
+
*
|
|
11
|
+
* @function patchFile
|
|
12
|
+
*
|
|
13
|
+
* @mermaid
|
|
14
|
+
* sequenceDiagram
|
|
15
|
+
* participant Caller
|
|
16
|
+
* participant patchFile
|
|
17
|
+
* participant fs
|
|
18
|
+
* participant readFile
|
|
19
|
+
* participant TextUtils
|
|
20
|
+
* participant writeFile
|
|
21
|
+
* Caller->>patchFile: Call with path and values
|
|
22
|
+
* patchFile->>fs: Check if file exists
|
|
23
|
+
* patchFile->>readFile: Read file content
|
|
24
|
+
* readFile->>fs: Read file
|
|
25
|
+
* fs-->>readFile: Return file content
|
|
26
|
+
* readFile-->>patchFile: Return file content
|
|
27
|
+
* patchFile->>TextUtils: Patch string
|
|
28
|
+
* TextUtils-->>patchFile: Return patched content
|
|
29
|
+
* patchFile->>writeFile: Write patched content
|
|
30
|
+
* writeFile->>fs: Write to file
|
|
31
|
+
* fs-->>writeFile: File written
|
|
32
|
+
* writeFile-->>patchFile: File written
|
|
33
|
+
* patchFile-->>Caller: Patching complete
|
|
34
|
+
*
|
|
35
|
+
* @memberOf module:utils
|
|
36
|
+
*/
|
|
37
|
+
export declare function patchFile(path: string, values: Record<string, number | string>, filter?: (str: string) => boolean): void;
|
|
38
|
+
/**
|
|
39
|
+
* @description Reads a file and returns its content.
|
|
40
|
+
* @summary Reads the content of a file at the specified path and returns it as a string.
|
|
41
|
+
*
|
|
42
|
+
* @param {string} path - The path to the file to be read.
|
|
43
|
+
* @return {string} The content of the file.
|
|
44
|
+
*
|
|
45
|
+
* @function readFile
|
|
46
|
+
*
|
|
47
|
+
* @memberOf module:utils
|
|
48
|
+
*/
|
|
49
|
+
export declare function readFile(path: string): string;
|
|
50
|
+
/**
|
|
51
|
+
* @description Writes data to a file.
|
|
52
|
+
* @summary Writes the provided data to a file at the specified path.
|
|
53
|
+
*
|
|
54
|
+
* @param {string} path - The path to the file to be written.
|
|
55
|
+
* @param {string | Buffer} data - The data to be written to the file.
|
|
56
|
+
* @return {void}
|
|
57
|
+
*
|
|
58
|
+
* @function writeFile
|
|
59
|
+
*
|
|
60
|
+
* @memberOf module:utils
|
|
61
|
+
*/
|
|
62
|
+
export declare function writeFile(path: string, data: string | Buffer): void;
|
|
63
|
+
/**
|
|
64
|
+
* @description Retrieves all files recursively from a directory.
|
|
65
|
+
* @summary Traverses through directories and subdirectories to collect all file paths.
|
|
66
|
+
*
|
|
67
|
+
* @param {string} p - The path to start searching from.
|
|
68
|
+
* @param {function} [filter] - Optional function to filter files by name or index.
|
|
69
|
+
* @return {string[]} Array of file paths.
|
|
70
|
+
*
|
|
71
|
+
* @function getAllFiles
|
|
72
|
+
*
|
|
73
|
+
* @memberOf module:utils
|
|
74
|
+
*/
|
|
75
|
+
export declare function getAllFiles(p: string, filter?: (f: string, i?: number) => boolean): string[];
|
|
76
|
+
/**
|
|
77
|
+
* @description Renames a file or directory.
|
|
78
|
+
* @summary Moves a file or directory from the source path to the destination path.
|
|
79
|
+
*
|
|
80
|
+
* @param {string} source - The source path of the file or directory.
|
|
81
|
+
* @param {string} dest - The destination path for the file or directory.
|
|
82
|
+
* @return {Promise<void>} A promise that resolves when the rename operation is complete.
|
|
83
|
+
*
|
|
84
|
+
* @function renameFile
|
|
85
|
+
*
|
|
86
|
+
* @memberOf module:utils
|
|
87
|
+
*/
|
|
88
|
+
export declare function renameFile(source: string, dest: string): Promise<void>;
|
|
89
|
+
/**
|
|
90
|
+
* @description Copies a file or directory.
|
|
91
|
+
* @summary Creates a copy of a file or directory from the source path to the destination path.
|
|
92
|
+
*
|
|
93
|
+
* @param {string} source - The source path of the file or directory.
|
|
94
|
+
* @param {string} dest - The destination path for the file or directory.
|
|
95
|
+
* @return {void}
|
|
96
|
+
*
|
|
97
|
+
* @function copyFile
|
|
98
|
+
*
|
|
99
|
+
* @memberOf module:utils
|
|
100
|
+
*/
|
|
101
|
+
export declare function copyFile(source: string, dest: string): void;
|
|
102
|
+
/**
|
|
103
|
+
* @description Deletes a file or directory.
|
|
104
|
+
* @summary Removes a file or directory at the specified path, with recursive and force options enabled.
|
|
105
|
+
*
|
|
106
|
+
* @param {string} p - The path to the file or directory to delete.
|
|
107
|
+
* @return {void}
|
|
108
|
+
*
|
|
109
|
+
* @function deletePath
|
|
110
|
+
*
|
|
111
|
+
* @memberOf module:utils
|
|
112
|
+
*/
|
|
113
|
+
export declare function deletePath(p: string): void;
|
|
114
|
+
/**
|
|
115
|
+
* @description Retrieves package information from package.json.
|
|
116
|
+
* @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.
|
|
117
|
+
* @param {string} [p=process.cwd()] - The directory path where the package.json file is located.
|
|
118
|
+
* @param {string} [property] - Optional. The specific property to retrieve from package.json.
|
|
119
|
+
* @return {object | string} The parsed contents of package.json or the value of the specified property.
|
|
120
|
+
* @function getPackage
|
|
121
|
+
* @mermaid
|
|
122
|
+
* sequenceDiagram
|
|
123
|
+
* participant Caller
|
|
124
|
+
* participant getPackage
|
|
125
|
+
* participant readFile
|
|
126
|
+
* participant JSON
|
|
127
|
+
* Caller->>getPackage: Call with path and optional property
|
|
128
|
+
* getPackage->>readFile: Read package.json
|
|
129
|
+
* readFile-->>getPackage: Return file content
|
|
130
|
+
* getPackage->>JSON: Parse file content
|
|
131
|
+
* JSON-->>getPackage: Return parsed object
|
|
132
|
+
* alt property specified
|
|
133
|
+
* getPackage->>getPackage: Check if property exists
|
|
134
|
+
* alt property exists
|
|
135
|
+
* getPackage-->>Caller: Return property value
|
|
136
|
+
* else property doesn't exist
|
|
137
|
+
* getPackage-->>Caller: Throw Error
|
|
138
|
+
* end
|
|
139
|
+
* else no property specified
|
|
140
|
+
* getPackage-->>Caller: Return entire package object
|
|
141
|
+
* end
|
|
142
|
+
* @memberOf module:utils
|
|
143
|
+
*/
|
|
144
|
+
export declare function getPackage(p?: string, property?: string): object | string;
|
|
145
|
+
/**
|
|
146
|
+
* @description Sets an attribute in the package.json file.
|
|
147
|
+
* @summary Updates a specific attribute in the package.json file with the provided value.
|
|
148
|
+
*
|
|
149
|
+
* @param {string} attr - The attribute name to set in package.json.
|
|
150
|
+
* @param {string | number | object} value - The value to set for the attribute.
|
|
151
|
+
* @param {string} [p=process.cwd()] - The directory path where the package.json file is located.
|
|
152
|
+
* @return {void}
|
|
153
|
+
*
|
|
154
|
+
* @function setPackageAttribute
|
|
155
|
+
*
|
|
156
|
+
* @memberOf module:utils
|
|
157
|
+
*/
|
|
158
|
+
export declare function setPackageAttribute(attr: string, value: string, p?: string): void;
|
|
159
|
+
/**
|
|
160
|
+
* @description Retrieves the version from package.json.
|
|
161
|
+
* @summary A convenience function that calls getPackage to retrieve the "version" property from package.json.
|
|
162
|
+
* @param {string} [p=process.cwd()] - The directory path where the package.json file is located.
|
|
163
|
+
* @return {string} The version string from package.json.
|
|
164
|
+
* @function getPackageVersion
|
|
165
|
+
* @memberOf module:utils
|
|
166
|
+
*/
|
|
167
|
+
export declare function getPackageVersion(p?: string): string;
|
|
168
|
+
/**
|
|
169
|
+
* @description Retrieves all dependencies from the project.
|
|
170
|
+
* @summary Executes 'npm ls --json' command to get a detailed list of all dependencies (production, development, and peer) and their versions.
|
|
171
|
+
* @param {string} [path=process.cwd()] - The directory path of the project.
|
|
172
|
+
* @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.
|
|
173
|
+
* @function getDependencies
|
|
174
|
+
* @mermaid
|
|
175
|
+
* sequenceDiagram
|
|
176
|
+
* participant Caller
|
|
177
|
+
* participant getDependencies
|
|
178
|
+
* participant runCommand
|
|
179
|
+
* participant JSON
|
|
180
|
+
* Caller->>getDependencies: Call with optional path
|
|
181
|
+
* getDependencies->>runCommand: Execute 'npm ls --json'
|
|
182
|
+
* runCommand-->>getDependencies: Return command output
|
|
183
|
+
* getDependencies->>JSON: Parse command output
|
|
184
|
+
* JSON-->>getDependencies: Return parsed object
|
|
185
|
+
* getDependencies->>getDependencies: Process dependencies
|
|
186
|
+
* getDependencies-->>Caller: Return processed dependencies
|
|
187
|
+
* @memberOf module:utils
|
|
188
|
+
*/
|
|
189
|
+
export declare function getDependencies(p?: string): Promise<DependencyMap>;
|
|
190
|
+
/**
|
|
191
|
+
* @description Updates project dependencies to their latest versions.
|
|
192
|
+
* @summary Runs npm-check-updates to update package.json and then installs the updated dependencies.
|
|
193
|
+
*
|
|
194
|
+
* @return {Promise<void>} A promise that resolves when dependencies are updated.
|
|
195
|
+
*
|
|
196
|
+
* @function updateDependencies
|
|
197
|
+
*
|
|
198
|
+
* @memberOf module:utils
|
|
199
|
+
*/
|
|
200
|
+
export declare function updateDependencies(): Promise<void>;
|
|
201
|
+
/**
|
|
202
|
+
* @description Installs dependencies if they are not already available.
|
|
203
|
+
* @summary Checks if specified dependencies are installed and installs any that are missing.
|
|
204
|
+
*
|
|
205
|
+
* @param {string[] | string} deps - The dependencies to check and potentially install.
|
|
206
|
+
* @param {SimpleDependencyMap} [dependencies] - Optional map of existing dependencies.
|
|
207
|
+
* @return {Promise<SimpleDependencyMap>} Updated map of dependencies.
|
|
208
|
+
*
|
|
209
|
+
* @function installIfNotAvailable
|
|
210
|
+
*
|
|
211
|
+
* @memberOf module:utils
|
|
212
|
+
*/
|
|
213
|
+
export declare function installIfNotAvailable(deps: string[] | string, dependencies?: SimpleDependencyMap): Promise<SimpleDependencyMap>;
|
|
214
|
+
/**
|
|
215
|
+
* @description Pushes changes to Git repository.
|
|
216
|
+
* @summary Temporarily changes Git user configuration, commits all changes, pushes to remote, and restores original user configuration.
|
|
217
|
+
*
|
|
218
|
+
* @return {Promise<void>} A promise that resolves when changes are pushed.
|
|
219
|
+
*
|
|
220
|
+
* @function pushToGit
|
|
221
|
+
*
|
|
222
|
+
* @memberOf module:utils
|
|
223
|
+
*/
|
|
224
|
+
export declare function pushToGit(): Promise<void>;
|
|
225
|
+
/**
|
|
226
|
+
* @description Installs project dependencies.
|
|
227
|
+
* @summary Installs production, development, and peer dependencies as specified.
|
|
228
|
+
*
|
|
229
|
+
* @param {object} dependencies - Object containing arrays of dependencies to install.
|
|
230
|
+
* @param {string[]} [dependencies.prod] - Production dependencies to install.
|
|
231
|
+
* @param {string[]} [dependencies.dev] - Development dependencies to install.
|
|
232
|
+
* @param {string[]} [dependencies.peer] - Peer dependencies to install.
|
|
233
|
+
* @return {Promise<void>} A promise that resolves when all dependencies are installed.
|
|
234
|
+
*
|
|
235
|
+
* @function installDependencies
|
|
236
|
+
*
|
|
237
|
+
* @memberOf module:utils
|
|
238
|
+
*/
|
|
239
|
+
export declare function installDependencies(dependencies: {
|
|
240
|
+
prod?: string[];
|
|
241
|
+
dev?: string[];
|
|
242
|
+
peer?: string[];
|
|
243
|
+
}): Promise<void>;
|
|
244
|
+
/**
|
|
245
|
+
* @description Normalizes imports to handle both CommonJS and ESModule formats.
|
|
246
|
+
* @summary Utility function to handle module import differences between formats.
|
|
247
|
+
*
|
|
248
|
+
* @template T - Type of the imported module.
|
|
249
|
+
* @param {Promise<T>} importPromise - Promise returned by dynamic import.
|
|
250
|
+
* @return {Promise<T>} Normalized module.
|
|
251
|
+
*
|
|
252
|
+
* @function normalizeImport
|
|
253
|
+
*
|
|
254
|
+
* @memberOf module:utils
|
|
255
|
+
*/
|
|
256
|
+
export declare function normalizeImport<T>(importPromise: Promise<T>): Promise<T>;
|
|
257
|
+
export declare function getFileSizeZipped(dir: string): Promise<number>;
|
|
258
|
+
export declare function listFolder(basePath?: string, filter?: (name: string, dirent: fs.Dirent) => boolean): string[];
|
|
259
|
+
export declare function listNodeModulesPackages(basePath?: string): string[];
|
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import { DependencyMap, SimpleDependencyMap } from "./types.js";
|
|
3
|
+
/**
|
|
4
|
+
* @description Patches a file with given values.
|
|
5
|
+
* @summary Reads a file, applies patches using TextUtils, and writes the result back to the file.
|
|
6
|
+
*
|
|
7
|
+
* @param {string} path - The path to the file to be patched.
|
|
8
|
+
* @param {Record<string, number | string>} values - The values to patch into the file.
|
|
9
|
+
* @return {void}
|
|
10
|
+
*
|
|
11
|
+
* @function patchFile
|
|
12
|
+
*
|
|
13
|
+
* @mermaid
|
|
14
|
+
* sequenceDiagram
|
|
15
|
+
* participant Caller
|
|
16
|
+
* participant patchFile
|
|
17
|
+
* participant fs
|
|
18
|
+
* participant readFile
|
|
19
|
+
* participant TextUtils
|
|
20
|
+
* participant writeFile
|
|
21
|
+
* Caller->>patchFile: Call with path and values
|
|
22
|
+
* patchFile->>fs: Check if file exists
|
|
23
|
+
* patchFile->>readFile: Read file content
|
|
24
|
+
* readFile->>fs: Read file
|
|
25
|
+
* fs-->>readFile: Return file content
|
|
26
|
+
* readFile-->>patchFile: Return file content
|
|
27
|
+
* patchFile->>TextUtils: Patch string
|
|
28
|
+
* TextUtils-->>patchFile: Return patched content
|
|
29
|
+
* patchFile->>writeFile: Write patched content
|
|
30
|
+
* writeFile->>fs: Write to file
|
|
31
|
+
* fs-->>writeFile: File written
|
|
32
|
+
* writeFile-->>patchFile: File written
|
|
33
|
+
* patchFile-->>Caller: Patching complete
|
|
34
|
+
*
|
|
35
|
+
* @memberOf module:utils
|
|
36
|
+
*/
|
|
37
|
+
export declare function patchFile(path: string, values: Record<string, number | string>, filter?: (str: string) => boolean): void;
|
|
38
|
+
/**
|
|
39
|
+
* @description Reads a file and returns its content.
|
|
40
|
+
* @summary Reads the content of a file at the specified path and returns it as a string.
|
|
41
|
+
*
|
|
42
|
+
* @param {string} path - The path to the file to be read.
|
|
43
|
+
* @return {string} The content of the file.
|
|
44
|
+
*
|
|
45
|
+
* @function readFile
|
|
46
|
+
*
|
|
47
|
+
* @memberOf module:utils
|
|
48
|
+
*/
|
|
49
|
+
export declare function readFile(path: string): string;
|
|
50
|
+
/**
|
|
51
|
+
* @description Writes data to a file.
|
|
52
|
+
* @summary Writes the provided data to a file at the specified path.
|
|
53
|
+
*
|
|
54
|
+
* @param {string} path - The path to the file to be written.
|
|
55
|
+
* @param {string | Buffer} data - The data to be written to the file.
|
|
56
|
+
* @return {void}
|
|
57
|
+
*
|
|
58
|
+
* @function writeFile
|
|
59
|
+
*
|
|
60
|
+
* @memberOf module:utils
|
|
61
|
+
*/
|
|
62
|
+
export declare function writeFile(path: string, data: string | Buffer): void;
|
|
63
|
+
/**
|
|
64
|
+
* @description Retrieves all files recursively from a directory.
|
|
65
|
+
* @summary Traverses through directories and subdirectories to collect all file paths.
|
|
66
|
+
*
|
|
67
|
+
* @param {string} p - The path to start searching from.
|
|
68
|
+
* @param {function} [filter] - Optional function to filter files by name or index.
|
|
69
|
+
* @return {string[]} Array of file paths.
|
|
70
|
+
*
|
|
71
|
+
* @function getAllFiles
|
|
72
|
+
*
|
|
73
|
+
* @memberOf module:utils
|
|
74
|
+
*/
|
|
75
|
+
export declare function getAllFiles(p: string, filter?: (f: string, i?: number) => boolean): string[];
|
|
76
|
+
/**
|
|
77
|
+
* @description Renames a file or directory.
|
|
78
|
+
* @summary Moves a file or directory from the source path to the destination path.
|
|
79
|
+
*
|
|
80
|
+
* @param {string} source - The source path of the file or directory.
|
|
81
|
+
* @param {string} dest - The destination path for the file or directory.
|
|
82
|
+
* @return {Promise<void>} A promise that resolves when the rename operation is complete.
|
|
83
|
+
*
|
|
84
|
+
* @function renameFile
|
|
85
|
+
*
|
|
86
|
+
* @memberOf module:utils
|
|
87
|
+
*/
|
|
88
|
+
export declare function renameFile(source: string, dest: string): Promise<void>;
|
|
89
|
+
/**
|
|
90
|
+
* @description Copies a file or directory.
|
|
91
|
+
* @summary Creates a copy of a file or directory from the source path to the destination path.
|
|
92
|
+
*
|
|
93
|
+
* @param {string} source - The source path of the file or directory.
|
|
94
|
+
* @param {string} dest - The destination path for the file or directory.
|
|
95
|
+
* @return {void}
|
|
96
|
+
*
|
|
97
|
+
* @function copyFile
|
|
98
|
+
*
|
|
99
|
+
* @memberOf module:utils
|
|
100
|
+
*/
|
|
101
|
+
export declare function copyFile(source: string, dest: string): void;
|
|
102
|
+
/**
|
|
103
|
+
* @description Deletes a file or directory.
|
|
104
|
+
* @summary Removes a file or directory at the specified path, with recursive and force options enabled.
|
|
105
|
+
*
|
|
106
|
+
* @param {string} p - The path to the file or directory to delete.
|
|
107
|
+
* @return {void}
|
|
108
|
+
*
|
|
109
|
+
* @function deletePath
|
|
110
|
+
*
|
|
111
|
+
* @memberOf module:utils
|
|
112
|
+
*/
|
|
113
|
+
export declare function deletePath(p: string): void;
|
|
114
|
+
/**
|
|
115
|
+
* @description Retrieves package information from package.json.
|
|
116
|
+
* @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.
|
|
117
|
+
* @param {string} [p=process.cwd()] - The directory path where the package.json file is located.
|
|
118
|
+
* @param {string} [property] - Optional. The specific property to retrieve from package.json.
|
|
119
|
+
* @return {object | string} The parsed contents of package.json or the value of the specified property.
|
|
120
|
+
* @function getPackage
|
|
121
|
+
* @mermaid
|
|
122
|
+
* sequenceDiagram
|
|
123
|
+
* participant Caller
|
|
124
|
+
* participant getPackage
|
|
125
|
+
* participant readFile
|
|
126
|
+
* participant JSON
|
|
127
|
+
* Caller->>getPackage: Call with path and optional property
|
|
128
|
+
* getPackage->>readFile: Read package.json
|
|
129
|
+
* readFile-->>getPackage: Return file content
|
|
130
|
+
* getPackage->>JSON: Parse file content
|
|
131
|
+
* JSON-->>getPackage: Return parsed object
|
|
132
|
+
* alt property specified
|
|
133
|
+
* getPackage->>getPackage: Check if property exists
|
|
134
|
+
* alt property exists
|
|
135
|
+
* getPackage-->>Caller: Return property value
|
|
136
|
+
* else property doesn't exist
|
|
137
|
+
* getPackage-->>Caller: Throw Error
|
|
138
|
+
* end
|
|
139
|
+
* else no property specified
|
|
140
|
+
* getPackage-->>Caller: Return entire package object
|
|
141
|
+
* end
|
|
142
|
+
* @memberOf module:utils
|
|
143
|
+
*/
|
|
144
|
+
export declare function getPackage(p?: string, property?: string): object | string;
|
|
145
|
+
/**
|
|
146
|
+
* @description Sets an attribute in the package.json file.
|
|
147
|
+
* @summary Updates a specific attribute in the package.json file with the provided value.
|
|
148
|
+
*
|
|
149
|
+
* @param {string} attr - The attribute name to set in package.json.
|
|
150
|
+
* @param {string | number | object} value - The value to set for the attribute.
|
|
151
|
+
* @param {string} [p=process.cwd()] - The directory path where the package.json file is located.
|
|
152
|
+
* @return {void}
|
|
153
|
+
*
|
|
154
|
+
* @function setPackageAttribute
|
|
155
|
+
*
|
|
156
|
+
* @memberOf module:utils
|
|
157
|
+
*/
|
|
158
|
+
export declare function setPackageAttribute(attr: string, value: string, p?: string): void;
|
|
159
|
+
/**
|
|
160
|
+
* @description Retrieves the version from package.json.
|
|
161
|
+
* @summary A convenience function that calls getPackage to retrieve the "version" property from package.json.
|
|
162
|
+
* @param {string} [p=process.cwd()] - The directory path where the package.json file is located.
|
|
163
|
+
* @return {string} The version string from package.json.
|
|
164
|
+
* @function getPackageVersion
|
|
165
|
+
* @memberOf module:utils
|
|
166
|
+
*/
|
|
167
|
+
export declare function getPackageVersion(p?: string): string;
|
|
168
|
+
/**
|
|
169
|
+
* @description Retrieves all dependencies from the project.
|
|
170
|
+
* @summary Executes 'npm ls --json' command to get a detailed list of all dependencies (production, development, and peer) and their versions.
|
|
171
|
+
* @param {string} [path=process.cwd()] - The directory path of the project.
|
|
172
|
+
* @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.
|
|
173
|
+
* @function getDependencies
|
|
174
|
+
* @mermaid
|
|
175
|
+
* sequenceDiagram
|
|
176
|
+
* participant Caller
|
|
177
|
+
* participant getDependencies
|
|
178
|
+
* participant runCommand
|
|
179
|
+
* participant JSON
|
|
180
|
+
* Caller->>getDependencies: Call with optional path
|
|
181
|
+
* getDependencies->>runCommand: Execute 'npm ls --json'
|
|
182
|
+
* runCommand-->>getDependencies: Return command output
|
|
183
|
+
* getDependencies->>JSON: Parse command output
|
|
184
|
+
* JSON-->>getDependencies: Return parsed object
|
|
185
|
+
* getDependencies->>getDependencies: Process dependencies
|
|
186
|
+
* getDependencies-->>Caller: Return processed dependencies
|
|
187
|
+
* @memberOf module:utils
|
|
188
|
+
*/
|
|
189
|
+
export declare function getDependencies(p?: string): Promise<DependencyMap>;
|
|
190
|
+
/**
|
|
191
|
+
* @description Updates project dependencies to their latest versions.
|
|
192
|
+
* @summary Runs npm-check-updates to update package.json and then installs the updated dependencies.
|
|
193
|
+
*
|
|
194
|
+
* @return {Promise<void>} A promise that resolves when dependencies are updated.
|
|
195
|
+
*
|
|
196
|
+
* @function updateDependencies
|
|
197
|
+
*
|
|
198
|
+
* @memberOf module:utils
|
|
199
|
+
*/
|
|
200
|
+
export declare function updateDependencies(): Promise<void>;
|
|
201
|
+
/**
|
|
202
|
+
* @description Installs dependencies if they are not already available.
|
|
203
|
+
* @summary Checks if specified dependencies are installed and installs any that are missing.
|
|
204
|
+
*
|
|
205
|
+
* @param {string[] | string} deps - The dependencies to check and potentially install.
|
|
206
|
+
* @param {SimpleDependencyMap} [dependencies] - Optional map of existing dependencies.
|
|
207
|
+
* @return {Promise<SimpleDependencyMap>} Updated map of dependencies.
|
|
208
|
+
*
|
|
209
|
+
* @function installIfNotAvailable
|
|
210
|
+
*
|
|
211
|
+
* @memberOf module:utils
|
|
212
|
+
*/
|
|
213
|
+
export declare function installIfNotAvailable(deps: string[] | string, dependencies?: SimpleDependencyMap): Promise<SimpleDependencyMap>;
|
|
214
|
+
/**
|
|
215
|
+
* @description Pushes changes to Git repository.
|
|
216
|
+
* @summary Temporarily changes Git user configuration, commits all changes, pushes to remote, and restores original user configuration.
|
|
217
|
+
*
|
|
218
|
+
* @return {Promise<void>} A promise that resolves when changes are pushed.
|
|
219
|
+
*
|
|
220
|
+
* @function pushToGit
|
|
221
|
+
*
|
|
222
|
+
* @memberOf module:utils
|
|
223
|
+
*/
|
|
224
|
+
export declare function pushToGit(): Promise<void>;
|
|
225
|
+
/**
|
|
226
|
+
* @description Installs project dependencies.
|
|
227
|
+
* @summary Installs production, development, and peer dependencies as specified.
|
|
228
|
+
*
|
|
229
|
+
* @param {object} dependencies - Object containing arrays of dependencies to install.
|
|
230
|
+
* @param {string[]} [dependencies.prod] - Production dependencies to install.
|
|
231
|
+
* @param {string[]} [dependencies.dev] - Development dependencies to install.
|
|
232
|
+
* @param {string[]} [dependencies.peer] - Peer dependencies to install.
|
|
233
|
+
* @return {Promise<void>} A promise that resolves when all dependencies are installed.
|
|
234
|
+
*
|
|
235
|
+
* @function installDependencies
|
|
236
|
+
*
|
|
237
|
+
* @memberOf module:utils
|
|
238
|
+
*/
|
|
239
|
+
export declare function installDependencies(dependencies: {
|
|
240
|
+
prod?: string[];
|
|
241
|
+
dev?: string[];
|
|
242
|
+
peer?: string[];
|
|
243
|
+
}): Promise<void>;
|
|
244
|
+
/**
|
|
245
|
+
* @description Normalizes imports to handle both CommonJS and ESModule formats.
|
|
246
|
+
* @summary Utility function to handle module import differences between formats.
|
|
247
|
+
*
|
|
248
|
+
* @template T - Type of the imported module.
|
|
249
|
+
* @param {Promise<T>} importPromise - Promise returned by dynamic import.
|
|
250
|
+
* @return {Promise<T>} Normalized module.
|
|
251
|
+
*
|
|
252
|
+
* @function normalizeImport
|
|
253
|
+
*
|
|
254
|
+
* @memberOf module:utils
|
|
255
|
+
*/
|
|
256
|
+
export declare function normalizeImport<T>(importPromise: Promise<T>): Promise<T>;
|
|
257
|
+
export declare function getFileSizeZipped(dir: string): Promise<number>;
|
|
258
|
+
export declare function listFolder(basePath?: string, filter?: (name: string, dirent: fs.Dirent) => boolean): string[];
|
|
259
|
+
export declare function listNodeModulesPackages(basePath?: string): string[];
|
|
@@ -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 HttpClient
|
|
7
|
+
*/
|
|
8
|
+
export declare class HttpClient {
|
|
9
|
+
protected static log: import("@decaf-ts/logging").Logger;
|
|
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,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 HttpClient
|
|
7
|
+
*/
|
|
8
|
+
export declare class HttpClient {
|
|
9
|
+
protected static log: import("@decaf-ts/logging").Logger;
|
|
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
|
+
}
|