properties-comparator 1.0.4 → 1.0.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/.github/workflows/sonarcloud.yml +75 -0
- package/DOCUMENTATION.md +202 -69
- package/PUBLISH.MD +3 -1
- package/README.md +80 -9
- package/TEST.md +48 -1
- package/babel.config.js +3 -0
- package/cli.js +61 -0
- package/index.js +323 -32
- package/jest.config.js +9 -22
- package/package.json +20 -7
- package/sonar-project.properties +19 -0
- package/src/compareUtility.js +540 -0
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# This workflow uses actions that are not certified by GitHub.
|
|
2
|
+
# They are provided by a third-party and are governed by
|
|
3
|
+
# separate terms of service, privacy policy, and support
|
|
4
|
+
# documentation.
|
|
5
|
+
|
|
6
|
+
# This workflow helps you trigger a SonarCloud analysis of your code and populates
|
|
7
|
+
# GitHub Code Scanning alerts with the vulnerabilities found.
|
|
8
|
+
# Free for open source project.
|
|
9
|
+
|
|
10
|
+
# 1. Login to SonarCloud.io using your GitHub account
|
|
11
|
+
|
|
12
|
+
# 2. Import your project on SonarCloud
|
|
13
|
+
# * Add your GitHub organization first, then add your repository as a new project.
|
|
14
|
+
# * Please note that many languages are eligible for automatic analysis,
|
|
15
|
+
# which means that the analysis will start automatically without the need to set up GitHub Actions.
|
|
16
|
+
# * This behavior can be changed in Administration > Analysis Method.
|
|
17
|
+
#
|
|
18
|
+
# 3. Follow the SonarCloud in-product tutorial
|
|
19
|
+
# * a. Copy/paste the Project Key and the Organization Key into the args parameter below
|
|
20
|
+
# (You'll find this information in SonarCloud. Click on "Information" at the bottom left)
|
|
21
|
+
#
|
|
22
|
+
# * b. Generate a new token and add it to your Github repository's secrets using the name SONAR_TOKEN
|
|
23
|
+
# (On SonarCloud, click on your avatar on top-right > My account > Security
|
|
24
|
+
# or go directly to https://sonarcloud.io/account/security/)
|
|
25
|
+
|
|
26
|
+
# Feel free to take a look at our documentation (https://docs.sonarcloud.io/getting-started/github/)
|
|
27
|
+
# or reach out to our community forum if you need some help (https://community.sonarsource.com/c/help/sc/9)
|
|
28
|
+
|
|
29
|
+
name: SonarCloud analysis
|
|
30
|
+
|
|
31
|
+
on:
|
|
32
|
+
push:
|
|
33
|
+
branches: ["main"]
|
|
34
|
+
pull_request:
|
|
35
|
+
branches: ["main"]
|
|
36
|
+
workflow_dispatch:
|
|
37
|
+
|
|
38
|
+
permissions:
|
|
39
|
+
pull-requests: read # allows SonarCloud to decorate PRs with analysis results
|
|
40
|
+
|
|
41
|
+
jobs:
|
|
42
|
+
Analysis:
|
|
43
|
+
runs-on: ubuntu-latest
|
|
44
|
+
|
|
45
|
+
steps:
|
|
46
|
+
- name: Checkout repository
|
|
47
|
+
uses: actions/checkout@v4
|
|
48
|
+
with:
|
|
49
|
+
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
|
|
50
|
+
|
|
51
|
+
- name: Setup Node.js
|
|
52
|
+
uses: actions/setup-node@v4
|
|
53
|
+
with:
|
|
54
|
+
node-version: "20"
|
|
55
|
+
|
|
56
|
+
- name: Install dependencies
|
|
57
|
+
run: npm install
|
|
58
|
+
|
|
59
|
+
- name: Run tests with coverage
|
|
60
|
+
run: npm test -- --coverage
|
|
61
|
+
|
|
62
|
+
- name: Analyze with SonarCloud
|
|
63
|
+
uses: SonarSource/sonarcloud-github-action@4006f663ecaf1f8093e8e4abb9227f6041f52216
|
|
64
|
+
env:
|
|
65
|
+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
|
|
66
|
+
with:
|
|
67
|
+
args: -Dsonar.projectKey=zackria_properties-comparator
|
|
68
|
+
-Dsonar.organization=zackria
|
|
69
|
+
-Dsonar.sources=index.js,cli.js,src
|
|
70
|
+
-Dsonar.tests=test
|
|
71
|
+
-Dsonar.test.inclusions=test/**/*.test.js
|
|
72
|
+
-Dsonar.exclusions=node_modules/**,coverage/**,index.js
|
|
73
|
+
-Dsonar.cpd.exclusions=index.js
|
|
74
|
+
-Dsonar.javascript.lcov.reportPaths=coverage/lcov.info
|
|
75
|
+
projectBaseDir: .
|
package/DOCUMENTATION.md
CHANGED
|
@@ -2,13 +2,18 @@
|
|
|
2
2
|
|
|
3
3
|
## Overview
|
|
4
4
|
|
|
5
|
-
This utility parses and compares **.properties** and **.yml or .yaml (YAML)** files. It reads each file as key-value pairs, compares the values for each key across multiple files, and
|
|
5
|
+
This utility parses and compares **.properties** and **.yml or .yaml (YAML)** files. It reads each file as key-value pairs, compares the values for each key across multiple files, and produces detailed comparison reports.
|
|
6
6
|
|
|
7
7
|
### Features:
|
|
8
8
|
- Parse **.properties** files into key-value objects.
|
|
9
9
|
- Parse **.yml or .yaml** (YAML) files into flattened key-value objects (supports nested keys).
|
|
10
10
|
- Compare key values across multiple files (both **.properties** and **.yml or .yaml**).
|
|
11
|
-
-
|
|
11
|
+
- Generate reports in multiple formats:
|
|
12
|
+
- Console output with color-coded highlighting
|
|
13
|
+
- HTML reports with CSS styling
|
|
14
|
+
- Markdown reports
|
|
15
|
+
- Save reports to files or display in console
|
|
16
|
+
- Flexible command-line interface with options
|
|
12
17
|
|
|
13
18
|
---
|
|
14
19
|
|
|
@@ -26,7 +31,26 @@ This utility parses and compares **.properties** and **.yml or .yaml (YAML)** fi
|
|
|
26
31
|
Run the script using Node.js with file paths provided as command-line arguments:
|
|
27
32
|
|
|
28
33
|
```bash
|
|
29
|
-
node
|
|
34
|
+
node compareUtility.js [options] <filePath1> <filePath2> [<filePath3> ...]
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### Command-Line Options
|
|
38
|
+
```
|
|
39
|
+
Options:
|
|
40
|
+
--format, -f <format> Output format: console, html, or markdown
|
|
41
|
+
--output, -o <file> Output file for html or markdown reports
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### Examples
|
|
45
|
+
```bash
|
|
46
|
+
# Basic comparison with console output
|
|
47
|
+
node compareUtility.js file1.properties file2.yaml
|
|
48
|
+
|
|
49
|
+
# Generate HTML report and save to output.html
|
|
50
|
+
node compareUtility.js --format html --output output.html file1.properties file2.yaml
|
|
51
|
+
|
|
52
|
+
# Short form options
|
|
53
|
+
node compareUtility.js -f markdown -o report.md file1.properties file2.properties file3.yml
|
|
30
54
|
```
|
|
31
55
|
|
|
32
56
|
### Input Format
|
|
@@ -37,6 +61,13 @@ key2=value2
|
|
|
37
61
|
# Comments are ignored
|
|
38
62
|
```
|
|
39
63
|
|
|
64
|
+
YAML files should follow standard YAML format. Nested structures will be flattened with dot notation:
|
|
65
|
+
```yaml
|
|
66
|
+
key1: value1
|
|
67
|
+
key2:
|
|
68
|
+
nestedKey: nestedValue # Will be accessible as "key2.nestedKey"
|
|
69
|
+
```
|
|
70
|
+
|
|
40
71
|
---
|
|
41
72
|
|
|
42
73
|
## Functions
|
|
@@ -60,113 +91,213 @@ console.log(properties);
|
|
|
60
91
|
|
|
61
92
|
---
|
|
62
93
|
|
|
63
|
-
### `
|
|
94
|
+
### `parseYamlFile(filePath)`
|
|
64
95
|
|
|
65
|
-
|
|
96
|
+
Parses a .yml or .yaml file into a flat key-value map using dot notation for nested keys.
|
|
66
97
|
|
|
67
98
|
#### Parameters:
|
|
68
|
-
- `
|
|
99
|
+
- `filePath` (string): Path to the YAML file.
|
|
69
100
|
|
|
70
101
|
#### Returns:
|
|
71
|
-
-
|
|
102
|
+
- (Object): A flattened object containing key-value pairs from the YAML file.
|
|
72
103
|
|
|
73
104
|
#### Example:
|
|
74
|
-
```
|
|
75
|
-
|
|
105
|
+
```javascript
|
|
106
|
+
const data = parseYamlFile('/path/to/yaml/file');
|
|
107
|
+
console.log(data);
|
|
108
|
+
// Output: { 'key1': 'value1', 'key2.nestedKey': 'nestedValue' }
|
|
76
109
|
```
|
|
77
110
|
|
|
78
|
-
|
|
79
|
-
```text
|
|
80
|
-
Comparing properties across files:
|
|
111
|
+
---
|
|
81
112
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
113
|
+
### `parseFile(filePath)`
|
|
114
|
+
|
|
115
|
+
Detects file extension and parses the file content into an object.
|
|
116
|
+
|
|
117
|
+
#### Parameters:
|
|
118
|
+
- `filePath` (string): Path to the file (.properties, .yml, or .yaml).
|
|
119
|
+
|
|
120
|
+
#### Returns:
|
|
121
|
+
- (Object): Parsed content as a key-value map, or {} if unsupported.
|
|
88
122
|
|
|
89
123
|
---
|
|
90
124
|
|
|
91
|
-
###
|
|
125
|
+
### `compareFileData(filePaths)`
|
|
92
126
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
127
|
+
Internal helper that compares key-value data from multiple files and returns structured results.
|
|
128
|
+
|
|
129
|
+
#### Parameters:
|
|
130
|
+
- `filePaths` (string[]): Array of file paths.
|
|
131
|
+
|
|
132
|
+
#### Returns:
|
|
133
|
+
- (Object): An object containing mismatch count and detailed comparison information.
|
|
134
|
+
|
|
135
|
+
---
|
|
136
|
+
|
|
137
|
+
### `checkIfAllValuesMatch(filePaths)`
|
|
138
|
+
|
|
139
|
+
Checks if all values match across the provided files.
|
|
140
|
+
|
|
141
|
+
#### Parameters:
|
|
142
|
+
- `filePaths` (string[]): Array of file paths.
|
|
143
|
+
|
|
144
|
+
#### Returns:
|
|
145
|
+
- (boolean): True if all properties match across all files, false otherwise.
|
|
103
146
|
|
|
104
147
|
---
|
|
105
148
|
|
|
106
|
-
###
|
|
149
|
+
### `getMismatchFields(filePaths)`
|
|
107
150
|
|
|
108
|
-
|
|
109
|
-
Detects file extension and parses `.properties`, `.yaml`, or `.yml` files. Returns an object with flattened key-value pairs or `{}` if unsupported.
|
|
151
|
+
Returns a list of fields (keys) that do not match across the provided files.
|
|
110
152
|
|
|
111
|
-
####
|
|
112
|
-
|
|
153
|
+
#### Parameters:
|
|
154
|
+
- `filePaths` (string[]): Array of file paths.
|
|
113
155
|
|
|
114
|
-
####
|
|
115
|
-
|
|
156
|
+
#### Returns:
|
|
157
|
+
- (string[]): List of mismatched keys.
|
|
116
158
|
|
|
117
|
-
|
|
118
|
-
Checks if all keys match across all provided files. Returns a boolean.
|
|
159
|
+
---
|
|
119
160
|
|
|
120
|
-
|
|
121
|
-
Returns an array of keys whose values differ across files.
|
|
161
|
+
### `generateHtmlReport(filePaths, comparisonData)`
|
|
122
162
|
|
|
123
|
-
|
|
124
|
-
|
|
163
|
+
Generates an HTML report for the comparison results.
|
|
164
|
+
|
|
165
|
+
#### Parameters:
|
|
166
|
+
- `filePaths` (string[]): Array of file paths that were compared.
|
|
167
|
+
- `comparisonData` (Object): The output from compareFileData function.
|
|
125
168
|
|
|
126
|
-
####
|
|
127
|
-
|
|
169
|
+
#### Returns:
|
|
170
|
+
- (string): HTML document as string.
|
|
171
|
+
|
|
172
|
+
---
|
|
173
|
+
|
|
174
|
+
### `generateMarkdownReport(filePaths, comparisonData)`
|
|
175
|
+
|
|
176
|
+
Generates a Markdown report for the comparison results.
|
|
177
|
+
|
|
178
|
+
#### Parameters:
|
|
179
|
+
- `filePaths` (string[]): Array of file paths that were compared.
|
|
180
|
+
- `comparisonData` (Object): The output from compareFileData function.
|
|
181
|
+
|
|
182
|
+
#### Returns:
|
|
183
|
+
- (string): Markdown document as string.
|
|
184
|
+
|
|
185
|
+
---
|
|
186
|
+
|
|
187
|
+
### `compareFiles(filePaths, options)`
|
|
188
|
+
|
|
189
|
+
Compares properties/keys across multiple files and generates a report based on options.
|
|
190
|
+
|
|
191
|
+
#### Parameters:
|
|
192
|
+
- `filePaths` (string[]): Array of file paths.
|
|
193
|
+
- `options` (Object): Options for comparison output.
|
|
194
|
+
- `format` (string): Output format ('console', 'html', or 'markdown').
|
|
195
|
+
- `outputFile` (string): Path to save the report (for html and markdown).
|
|
196
|
+
|
|
197
|
+
#### Example:
|
|
198
|
+
```javascript
|
|
199
|
+
// Compare with console output
|
|
200
|
+
compareFiles(['file1.properties', 'file2.yaml']);
|
|
201
|
+
|
|
202
|
+
// Generate HTML report
|
|
203
|
+
compareFiles(['file1.properties', 'file2.yaml'], {
|
|
204
|
+
format: 'html',
|
|
205
|
+
outputFile: 'report.html'
|
|
206
|
+
});
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
---
|
|
210
|
+
|
|
211
|
+
### `run()`
|
|
212
|
+
|
|
213
|
+
CLI entry point. Parses command-line arguments and runs the comparison.
|
|
214
|
+
|
|
215
|
+
---
|
|
216
|
+
|
|
217
|
+
## Output Formats
|
|
218
|
+
|
|
219
|
+
### Console Output
|
|
220
|
+
The default output format provides:
|
|
221
|
+
- A table showing all keys and their values across files
|
|
222
|
+
- Highlighted mismatched rows for easy identification
|
|
223
|
+
- A summary of mismatched keys
|
|
224
|
+
|
|
225
|
+
### HTML Report
|
|
226
|
+
Generates a visually appealing HTML report with:
|
|
227
|
+
- CSS styling
|
|
228
|
+
- Color-coded cells for matches and mismatches
|
|
229
|
+
- Summary section with quick statistics
|
|
230
|
+
- Responsive design
|
|
231
|
+
|
|
232
|
+
### Markdown Report
|
|
233
|
+
Creates a Markdown document with:
|
|
234
|
+
- File list with paths
|
|
235
|
+
- Comparison table
|
|
236
|
+
- Summary section with mismatched keys highlighted
|
|
128
237
|
|
|
129
238
|
---
|
|
130
239
|
|
|
131
240
|
## Error Handling
|
|
132
241
|
|
|
133
242
|
- **No File Paths Provided**: Logs an error and exits.
|
|
243
|
+
- **Only One File Provided**: Logs an error about needing at least two files and exits.
|
|
134
244
|
- **Missing Files**: Logs missing files and exits.
|
|
135
|
-
- **
|
|
245
|
+
- **Unsupported File Extensions**: Logs a warning and treats as empty file.
|
|
246
|
+
- **Invalid YAML**: Logs error details and treats as empty file.
|
|
247
|
+
- **Invalid Format Option**: Falls back to console output with warning.
|
|
136
248
|
|
|
137
249
|
---
|
|
138
250
|
|
|
139
|
-
## Example
|
|
251
|
+
## Example Scenarios
|
|
252
|
+
|
|
253
|
+
### Basic Comparison
|
|
140
254
|
|
|
141
|
-
|
|
255
|
+
#### Command:
|
|
256
|
+
```bash
|
|
257
|
+
node compareUtility.js file1.properties file2.properties
|
|
142
258
|
```
|
|
143
|
-
|
|
144
|
-
|
|
259
|
+
|
|
260
|
+
#### Output:
|
|
145
261
|
```
|
|
262
|
+
Comparing properties/keys across files:
|
|
263
|
+
|
|
264
|
+
┌─────────┬─────┬────────────┬────────────┐
|
|
265
|
+
│ (index) │ Key │ Matched │ ... │
|
|
266
|
+
├─────────┼─────┼────────────┼────────────┤
|
|
267
|
+
│ 0 │ ... │ 'Yes' │ ... │
|
|
268
|
+
│ 1 │ ... │ 'No' │ ... │
|
|
269
|
+
└─────────┴─────┴────────────┴────────────┘
|
|
146
270
|
|
|
147
|
-
|
|
271
|
+
=== Highlighted Mismatched Rows ===
|
|
272
|
+
Key: key2 | File 1: value2 | File 2: value3
|
|
273
|
+
|
|
274
|
+
=== Summary ===
|
|
275
|
+
1 key(s) have mismatched values.
|
|
276
|
+
Mismatched keys: key2
|
|
148
277
|
```
|
|
149
|
-
|
|
150
|
-
|
|
278
|
+
|
|
279
|
+
### HTML Report Generation
|
|
280
|
+
|
|
281
|
+
#### Command:
|
|
282
|
+
```bash
|
|
283
|
+
node compareUtility.js -f html -o report.html file1.properties file2.yaml
|
|
151
284
|
```
|
|
152
285
|
|
|
153
|
-
|
|
286
|
+
#### Output:
|
|
287
|
+
```
|
|
288
|
+
HTML report saved to: report.html
|
|
289
|
+
```
|
|
154
290
|
|
|
155
|
-
|
|
291
|
+
### Markdown Report Generation
|
|
156
292
|
|
|
157
|
-
|
|
293
|
+
#### Command:
|
|
158
294
|
```bash
|
|
159
|
-
node
|
|
295
|
+
node compareUtility.js -f markdown -o report.md file1.properties file2.properties
|
|
160
296
|
```
|
|
161
297
|
|
|
162
|
-
|
|
163
|
-
```
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
Key: key1 - Values match across all files.
|
|
167
|
-
Key: key2 - Mismatched values:
|
|
168
|
-
File 1: value2
|
|
169
|
-
File 2: value3
|
|
298
|
+
#### Output:
|
|
299
|
+
```
|
|
300
|
+
Markdown report saved to: report.md
|
|
170
301
|
```
|
|
171
302
|
|
|
172
303
|
---
|
|
@@ -174,21 +305,23 @@ Key: key2 - Mismatched values:
|
|
|
174
305
|
## Dependencies
|
|
175
306
|
|
|
176
307
|
- `fs` module (Node.js File System)
|
|
177
|
-
- `
|
|
308
|
+
- `path` module (Node.js Path)
|
|
309
|
+
- `js-yaml` module (YAML parsing)
|
|
310
|
+
- `chalk` module (Terminal styling)
|
|
178
311
|
|
|
179
312
|
---
|
|
180
313
|
|
|
181
314
|
## Limitations
|
|
182
315
|
|
|
183
|
-
- Assumes properties are simple key-value pairs separated by
|
|
184
|
-
-
|
|
185
|
-
-
|
|
316
|
+
- Assumes properties are simple key-value pairs separated by `=`
|
|
317
|
+
- Does not support multi-line properties in .properties files
|
|
318
|
+
- Flattens all nested YAML structures to dot notation
|
|
186
319
|
|
|
187
320
|
---
|
|
188
321
|
|
|
189
322
|
## License
|
|
190
323
|
|
|
191
|
-
This
|
|
324
|
+
This utility is licensed under the MIT License.
|
|
192
325
|
|
|
193
326
|
---
|
|
194
327
|
|
package/PUBLISH.MD
CHANGED
|
@@ -4,13 +4,15 @@
|
|
|
4
4
|
### Test Locally
|
|
5
5
|
`npm link`
|
|
6
6
|
|
|
7
|
+
`npm unlink -g`
|
|
8
|
+
|
|
9
|
+
`npm link properties-comparator`
|
|
7
10
|
|
|
8
11
|
## Now you can run the script globally using:
|
|
9
12
|
|
|
10
13
|
```properties-comparator <filePath1> <filePath2>```
|
|
11
14
|
|
|
12
15
|
|
|
13
|
-
|
|
14
16
|
## Publish the Package
|
|
15
17
|
### Login to npm (if you haven't already):
|
|
16
18
|
`npm login`
|
package/README.md
CHANGED
|
@@ -1,20 +1,91 @@
|
|
|
1
1
|
# properties-comparator
|
|
2
|
-
This utility provides functionality to parse and compare **.properties** and **.yml or .yaml(YAML)** files in the format of key-value pairs. It reads these files, compares the values for each key across multiple files, and logs the results.
|
|
3
2
|
|
|
3
|
+
A powerful utility for parsing and comparing **.properties** and **.yml/.yaml** files. This tool reads files as key-value pairs, compares values across multiple files, and generates detailed comparison reports in various formats.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
[](https://www.npmjs.com/package/properties-comparator) [](https://sonarcloud.io/summary/new_code?id=zackria_properties-comparator)
|
|
6
6
|
|
|
7
|
+
## Features
|
|
7
8
|
|
|
8
|
-
|
|
9
|
-
|
|
9
|
+
- **Multi-format Support**: Parse both **.properties** files and **.yml/.yaml** (YAML) files
|
|
10
|
+
- **Nested Structure Handling**: Flatten nested YAML structures into key-value pairs
|
|
11
|
+
- **Comprehensive Comparison**: Compare values across multiple files simultaneously
|
|
12
|
+
- **Multiple Report Formats**:
|
|
13
|
+
- Console output with color-coded highlighting
|
|
14
|
+
- HTML reports with CSS styling
|
|
15
|
+
- Markdown reports
|
|
16
|
+
- **Flexible Output Options**: Save reports to files or display in console
|
|
17
|
+
- **User-friendly CLI**: Simple command-line interface with intuitive options
|
|
10
18
|
|
|
19
|
+
## Installation
|
|
11
20
|
|
|
12
|
-
|
|
21
|
+
```bash
|
|
22
|
+
# Install globally
|
|
23
|
+
npm install -g properties-comparator
|
|
13
24
|
|
|
14
|
-
|
|
25
|
+
# To uninstall
|
|
26
|
+
npm uninstall -g properties-comparator
|
|
27
|
+
```
|
|
15
28
|
|
|
16
|
-
##
|
|
17
|
-
`npm install -g npm@11.1.0`
|
|
29
|
+
## Usage
|
|
18
30
|
|
|
31
|
+
### Basic Usage
|
|
19
32
|
|
|
20
|
-
|
|
33
|
+
Compare two or more files:
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
properties-comparator <filePath1> <filePath2> [<filePath3> ...]
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
### Examples
|
|
40
|
+
|
|
41
|
+
Compare multiple files:
|
|
42
|
+
```bash
|
|
43
|
+
properties-comparator ./config1.properties ./config2.yml ./config3.properties
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Generate HTML report:
|
|
47
|
+
```bash
|
|
48
|
+
properties-comparator -f html -o report.html ./config1.properties ./config2.yml
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Generate Markdown report:
|
|
52
|
+
```bash
|
|
53
|
+
properties-comparator -f markdown -o report.md ./config1.properties ./config2.yml
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
### Command Options
|
|
57
|
+
|
|
58
|
+
- `-f, --format <type>` - Report format (console, html, markdown)
|
|
59
|
+
- `-o, --output <file>` - Output file for the report
|
|
60
|
+
- `-h, --help` - Display help information
|
|
61
|
+
|
|
62
|
+
## Report Examples
|
|
63
|
+
|
|
64
|
+
### Terminal View
|
|
65
|
+

|
|
66
|
+
|
|
67
|
+
### HTML View
|
|
68
|
+

|
|
69
|
+
|
|
70
|
+
### Markdown View
|
|
71
|
+

|
|
72
|
+
|
|
73
|
+
## Quality Assurance
|
|
74
|
+
|
|
75
|
+
This package is thoroughly tested with over 90% code coverage to ensure reliability.
|
|
76
|
+
|
|
77
|
+

|
|
78
|
+
|
|
79
|
+
## Compatibility
|
|
80
|
+
|
|
81
|
+
Developed and tested with:
|
|
82
|
+
- npm v11.7.0
|
|
83
|
+
- Node.js v25.2.1
|
|
84
|
+
|
|
85
|
+
## Documentation
|
|
86
|
+
|
|
87
|
+
For more detailed information, please check the [Documentation](DOCUMENTATION.md).
|
|
88
|
+
|
|
89
|
+
## License
|
|
90
|
+
|
|
91
|
+
[MIT](LICENSE)
|
package/TEST.md
CHANGED
|
@@ -12,4 +12,51 @@ or
|
|
|
12
12
|
|
|
13
13
|
### Check jest.config.js for testing configuration
|
|
14
14
|
|
|
15
|
-
`npm test -- --coverage`
|
|
15
|
+
`npm test -- --coverage`
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
### Test Comparisons
|
|
19
|
+
|
|
20
|
+
`node index.js ./test/config1.properties ./test/config1.yaml`
|
|
21
|
+
|
|
22
|
+
`node index.js ./test/config1.properties ./test/config2.yml`
|
|
23
|
+
|
|
24
|
+
`node index.js ./test/config1.properties ./test/config2.properties`
|
|
25
|
+
|
|
26
|
+
`node index.js ./test/config2.properties ./test/config2.yml`
|
|
27
|
+
|
|
28
|
+
`node index.js ./test/config3.txt ./test/config3.yml2`
|
|
29
|
+
|
|
30
|
+
`node index.js --format html --output report.html ./test/config1.properties ./test/config2.yml`
|
|
31
|
+
|
|
32
|
+
`node index.js -f markdown -o report.md ./test/config1.properties ./test/config2.yml`
|
|
33
|
+
|
|
34
|
+
### NPM LINK Test
|
|
35
|
+
|
|
36
|
+
`properties-comparator ./test/config1.properties ./test/config1.yaml`
|
|
37
|
+
|
|
38
|
+
`properties-comparator ./test/config1.properties ./test/config2.yml`
|
|
39
|
+
|
|
40
|
+
`properties-comparator ./test/config1.properties ./test/config2.properties`
|
|
41
|
+
|
|
42
|
+
`properties-comparator ./test/config2.properties ./test/config2.yml`
|
|
43
|
+
|
|
44
|
+
`properties-comparator ./test/config3.txt ./test/config3.yml2`
|
|
45
|
+
|
|
46
|
+
`properties-comparator --format html --output report.html ./test/config1.properties ./test/config2.yml`
|
|
47
|
+
|
|
48
|
+
`properties-comparator -f markdown -o report.md ./test/config1.properties ./test/config2.yml`
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
`properties-comparator ./test/config1.properties ./test/config2.yml ./test/config3.properties`
|
|
52
|
+
|
|
53
|
+
`properties-comparator -v ./test/config1.properties ./test/config2.yml ./test/config3.properties`
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
`properties-comparator -f html -o report.html ./test/config1.properties ./test/config1.yaml`
|
|
57
|
+
|
|
58
|
+
`properties-comparator -f html -o report.html ./test/config1.properties ./test/config2.yml`
|
|
59
|
+
|
|
60
|
+
`properties-comparator -f html -o report.html ./test/config1.properties ./test/config2.yml ./test/config3.properties`
|
|
61
|
+
|
|
62
|
+
`properties-comparator -f markdown -o report.md ./test/config1.properties ./test/config2.yml ./test/config3.properties`
|
package/babel.config.js
ADDED
package/cli.js
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { program } from 'commander';
|
|
4
|
+
import { compareFiles } from './index.js';
|
|
5
|
+
import { readFileSync } from 'node:fs';
|
|
6
|
+
import path from 'node:path';
|
|
7
|
+
|
|
8
|
+
// Get version from package.json
|
|
9
|
+
let version = '1.0.0';
|
|
10
|
+
|
|
11
|
+
try {
|
|
12
|
+
const packageJson = JSON.parse(readFileSync('./package.json', 'utf8'));
|
|
13
|
+
version = packageJson.version;
|
|
14
|
+
} catch (err) {
|
|
15
|
+
// Use default version if package.json can't be read
|
|
16
|
+
console.warn(`Warning: Could not read version from package.json (${err.message}). Using default 1.0.0`);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// Check if no arguments were provided
|
|
20
|
+
if (process.argv.length <= 2) {
|
|
21
|
+
console.log(`properties-comparator v${version}`);
|
|
22
|
+
console.log('Usage: properties-comparator [options] <file1> <file2> [file3...]');
|
|
23
|
+
process.exit(0);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
program
|
|
27
|
+
.version(version)
|
|
28
|
+
.description('Compare properties between multiple files')
|
|
29
|
+
.option('-f, --format <format>', 'Output format: console, html, or markdown (default: console)')
|
|
30
|
+
.option('-o, --output <path>', 'Output file path for results')
|
|
31
|
+
.option('-v, --verbose', 'Show verbose output')
|
|
32
|
+
.arguments('<files...>')
|
|
33
|
+
.usage('[options] <file1> <file2> [file3...]')
|
|
34
|
+
.action((files, options) => {
|
|
35
|
+
if (files.length < 2) {
|
|
36
|
+
console.error('Error: At least two files are required for comparison');
|
|
37
|
+
program.help();
|
|
38
|
+
process.exit(1);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
try {
|
|
42
|
+
// Resolve all file paths
|
|
43
|
+
const resolvedPaths = files.map(file => path.resolve(file));
|
|
44
|
+
|
|
45
|
+
// Prepare options for compareFiles
|
|
46
|
+
const comparisonOptions = {
|
|
47
|
+
format: options.format || 'console',
|
|
48
|
+
outputFile: options.output,
|
|
49
|
+
verbose: options.verbose // Pass verbose option to compareFiles
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
// Run the comparison
|
|
53
|
+
compareFiles(resolvedPaths, comparisonOptions);
|
|
54
|
+
|
|
55
|
+
} catch (error) {
|
|
56
|
+
console.error('Error:', error.message);
|
|
57
|
+
process.exit(1);
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
program.parse(process.argv);
|