pomanalyzer 1.0.0 → 1.0.1
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 +69 -0
- package/DEPENDENCY.md +20 -0
- package/DOCUMENTATION.md +157 -0
- package/README.md +5 -1
- package/cli.js +7 -5
- package/package.json +16 -11
- package/sonar-project.properties +15 -0
- package/src/services/dependencyService.js +12 -16
- package/src/utils/fileUtils.js +1 -1
- package/src/utils/printHTMLTable.js +10 -10
- package/src/utils/printMarkdownTable.js +7 -7
- package/test/fileUtils.test.js +2 -2
- package/output/Maven_Dependencies_report.html +0 -84
- package/output/Maven_Dependencies_report.md +0 -24
- package/screenshots/CodeCoverage.png +0 -0
- package/screenshots/ConsoleOutput.png +0 -0
- package/screenshots/HtmlOutput.png +0 -0
- package/screenshots/MarkdownOutput.png +0 -0
|
@@ -0,0 +1,69 @@
|
|
|
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: Analyze with SonarCloud
|
|
47
|
+
|
|
48
|
+
# You can pin the exact commit or the version.
|
|
49
|
+
# uses: SonarSource/sonarcloud-github-action@v2.2.0
|
|
50
|
+
uses: SonarSource/sonarcloud-github-action@4006f663ecaf1f8093e8e4abb9227f6041f52216
|
|
51
|
+
env:
|
|
52
|
+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} # Generate a token on Sonarcloud.io, add it to the secrets of this repo with the name SONAR_TOKEN (Settings > Secrets > Actions > add new repository secret)
|
|
53
|
+
with:
|
|
54
|
+
# Additional arguments for the SonarScanner CLI
|
|
55
|
+
args:
|
|
56
|
+
# Unique keys of your project and organization. You can find them in SonarCloud > Information (bottom-left menu)
|
|
57
|
+
# mandatory
|
|
58
|
+
-Dsonar.projectKey=zackria_pomanalyzer
|
|
59
|
+
-Dsonar.organization=zackria
|
|
60
|
+
-Dsonar.cpd.exclusions=test/**/*.test.js,coverage/**
|
|
61
|
+
-Dsonar.exclusions=coverage/**
|
|
62
|
+
# Comma-separated paths to directories containing main source files.
|
|
63
|
+
#-Dsonar.sources= # optional, default is project base directory
|
|
64
|
+
# Comma-separated paths to directories containing test source files.
|
|
65
|
+
#-Dsonar.tests= # optional. For more info about Code Coverage, please refer to https://docs.sonarcloud.io/enriching/test-coverage/overview/
|
|
66
|
+
# Adds more detail to both client and server-side analysis logs, activating DEBUG mode for the scanner, and adding client-side environment variables and system properties to the server-side log of analysis report processing.
|
|
67
|
+
#-Dsonar.verbose= # optional, default is false
|
|
68
|
+
# When you need the analysis to take place in a directory other than the one from which it was launched, default is .
|
|
69
|
+
projectBaseDir: .
|
package/DEPENDENCY.md
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# Dependency Diagram
|
|
2
|
+
|
|
3
|
+
```mermaid
|
|
4
|
+
graph TD
|
|
5
|
+
A[analyzePom index.js] -->|uses| B[readPomXml dependencyService.js]
|
|
6
|
+
B -->|uses| C[readFile fileUtils.js]
|
|
7
|
+
B -->|uses| D[parseXml xmlParser.js]
|
|
8
|
+
B -->|uses| E[resolveVersion dependencyResolver.js]
|
|
9
|
+
A -->|uses| F[checkForDuplicates duplicateChecker.js]
|
|
10
|
+
A -->|uses| G[printTable outputFormatter.js]
|
|
11
|
+
A -->|uses| H[printHTMLTable printHTMLTable.js]
|
|
12
|
+
A -->|uses| I[printMarkdownTable printMarkdownTable.js]
|
|
13
|
+
H -->|uses| J[fs Node.js]
|
|
14
|
+
H -->|uses| K[path Node.js]
|
|
15
|
+
I -->|uses| J[fs Node.js]
|
|
16
|
+
I -->|uses| K[path Node.js]
|
|
17
|
+
C -->|uses| J[fs Node.js]
|
|
18
|
+
D -->|uses| L[xml2js npm]
|
|
19
|
+
|
|
20
|
+
```
|
package/DOCUMENTATION.md
CHANGED
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
# POM Analyzer Documentation
|
|
2
|
+
|
|
3
|
+
This document provides an overview of the functionality of each JavaScript file in the project.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## `/src/services/dependencyService.js`
|
|
8
|
+
|
|
9
|
+
### Description
|
|
10
|
+
This file contains functions to read and parse Maven `pom.xml` files and extract dependencies.
|
|
11
|
+
|
|
12
|
+
### Functions
|
|
13
|
+
1. **`readPomXml(filePath)`**
|
|
14
|
+
- Reads and parses a Maven `pom.xml` file.
|
|
15
|
+
- **Parameters**:
|
|
16
|
+
- `filePath` (string): Path to the `pom.xml` file.
|
|
17
|
+
- **Returns**: A promise that resolves to an array of dependencies.
|
|
18
|
+
|
|
19
|
+
2. **`extractDependencies(result)`**
|
|
20
|
+
- Extracts dependencies from the parsed XML result.
|
|
21
|
+
- **Parameters**:
|
|
22
|
+
- `result` (Object): Parsed XML result.
|
|
23
|
+
- **Returns**: An array of dependencies.
|
|
24
|
+
|
|
25
|
+
---
|
|
26
|
+
|
|
27
|
+
## `/cli.js`
|
|
28
|
+
|
|
29
|
+
### Description
|
|
30
|
+
This file serves as the command-line interface for the POM Analyzer. It uses the `commander` library to parse CLI arguments and options.
|
|
31
|
+
|
|
32
|
+
### Key Features
|
|
33
|
+
- Displays version and usage information.
|
|
34
|
+
- Accepts options for generating HTML and Markdown reports.
|
|
35
|
+
- Invokes the `analyzePom` function to analyze the provided `pom.xml` file.
|
|
36
|
+
|
|
37
|
+
---
|
|
38
|
+
|
|
39
|
+
## `/src/index.js`
|
|
40
|
+
|
|
41
|
+
### Description
|
|
42
|
+
This file contains the main logic for analyzing Maven `pom.xml` files. It integrates various services and utilities to process dependencies and generate reports.
|
|
43
|
+
|
|
44
|
+
### Functions
|
|
45
|
+
1. **`analyzePom(pomXmlPath, options)`**
|
|
46
|
+
- Analyzes the provided `pom.xml` file.
|
|
47
|
+
- **Parameters**:
|
|
48
|
+
- `pomXmlPath` (string): Path to the `pom.xml` file.
|
|
49
|
+
- `options` (Object): Options for generating reports (HTML, Markdown, etc.).
|
|
50
|
+
- **Behavior**:
|
|
51
|
+
- Reads dependencies using `readPomXml`.
|
|
52
|
+
- Checks for duplicate dependencies.
|
|
53
|
+
- Generates reports based on the provided options.
|
|
54
|
+
|
|
55
|
+
---
|
|
56
|
+
|
|
57
|
+
## `/src/utils/xmlParser.js`
|
|
58
|
+
|
|
59
|
+
### Description
|
|
60
|
+
This file provides a utility function to parse XML content into a JavaScript object using the `xml2js` library.
|
|
61
|
+
|
|
62
|
+
### Functions
|
|
63
|
+
1. **`parseXml(xmlContent)`**
|
|
64
|
+
- Parses XML content and returns a JavaScript object.
|
|
65
|
+
- **Parameters**:
|
|
66
|
+
- `xmlContent` (string): XML content to parse.
|
|
67
|
+
- **Returns**: A promise that resolves to the parsed object.
|
|
68
|
+
|
|
69
|
+
---
|
|
70
|
+
|
|
71
|
+
## `/src/utils/printMarkdownTable.js`
|
|
72
|
+
|
|
73
|
+
### Description
|
|
74
|
+
This file contains a function to generate and save a Markdown report for dependencies and duplicate dependencies.
|
|
75
|
+
|
|
76
|
+
### Functions
|
|
77
|
+
1. **`printMarkdownTable(dependencies, duplicateDependencies, title, folderPath)`**
|
|
78
|
+
- Generates and saves a Markdown table.
|
|
79
|
+
- **Parameters**:
|
|
80
|
+
- `dependencies` (Array): List of dependencies.
|
|
81
|
+
- `duplicateDependencies` (Array): List of duplicate dependencies.
|
|
82
|
+
- `title` (string): Title of the report.
|
|
83
|
+
- `folderPath` (string): Folder path to save the Markdown file.
|
|
84
|
+
|
|
85
|
+
---
|
|
86
|
+
|
|
87
|
+
## `/src/utils/printHTMLTable.js`
|
|
88
|
+
|
|
89
|
+
### Description
|
|
90
|
+
This file contains a function to generate and save an HTML report for dependencies and duplicate dependencies.
|
|
91
|
+
|
|
92
|
+
### Functions
|
|
93
|
+
1. **`printHTMLTable(dependencies, duplicateDependencies, title, folderPath)`**
|
|
94
|
+
- Generates and saves an HTML table.
|
|
95
|
+
- **Parameters**:
|
|
96
|
+
- `dependencies` (Array): List of dependencies.
|
|
97
|
+
- `duplicateDependencies` (Array): List of duplicate dependencies.
|
|
98
|
+
- `title` (string): Title of the report.
|
|
99
|
+
- `folderPath` (string): Folder path to save the HTML file.
|
|
100
|
+
|
|
101
|
+
---
|
|
102
|
+
|
|
103
|
+
## `/src/utils/outputFormatter.js`
|
|
104
|
+
|
|
105
|
+
### Description
|
|
106
|
+
This file provides a utility function to print dependencies in a tabular format to the console.
|
|
107
|
+
|
|
108
|
+
### Functions
|
|
109
|
+
1. **`printTable(dependencies, title)`**
|
|
110
|
+
- Prints a list of dependencies in a table format.
|
|
111
|
+
- **Parameters**:
|
|
112
|
+
- `dependencies` (Array): List of dependencies.
|
|
113
|
+
- `title` (string): Title of the table.
|
|
114
|
+
|
|
115
|
+
---
|
|
116
|
+
|
|
117
|
+
## `/src/utils/fileUtils.js`
|
|
118
|
+
|
|
119
|
+
### Description
|
|
120
|
+
This file contains utility functions for file operations, such as reading files.
|
|
121
|
+
|
|
122
|
+
### Functions
|
|
123
|
+
1. **`readFile(filePath)`**
|
|
124
|
+
- Reads a file and returns its content.
|
|
125
|
+
- **Parameters**:
|
|
126
|
+
- `filePath` (string): Path to the file.
|
|
127
|
+
- **Returns**: A promise that resolves to the file content.
|
|
128
|
+
|
|
129
|
+
---
|
|
130
|
+
|
|
131
|
+
## `/src/utils/dependencyResolver.js`
|
|
132
|
+
|
|
133
|
+
### Description
|
|
134
|
+
This file provides a utility function to resolve Maven-style property placeholders in version strings.
|
|
135
|
+
|
|
136
|
+
### Functions
|
|
137
|
+
1. **`resolveVersion(version, properties)`**
|
|
138
|
+
- Resolves a Maven-style property placeholder in a version string.
|
|
139
|
+
- **Parameters**:
|
|
140
|
+
- `version` (string): Version string with a placeholder.
|
|
141
|
+
- `properties` (Object): Key-value pairs of Maven properties.
|
|
142
|
+
- **Returns**: Resolved version string or "N/A" if unresolved.
|
|
143
|
+
|
|
144
|
+
---
|
|
145
|
+
|
|
146
|
+
## `/src/services/duplicateChecker.js`
|
|
147
|
+
|
|
148
|
+
### Description
|
|
149
|
+
This file contains a function to identify duplicate dependencies based on `groupId` and `artifactId`.
|
|
150
|
+
|
|
151
|
+
### Functions
|
|
152
|
+
1. **`checkForDuplicates(dependencies)`**
|
|
153
|
+
- Identifies duplicate dependencies.
|
|
154
|
+
- **Parameters**:
|
|
155
|
+
- `dependencies` (Array): List of dependencies.
|
|
156
|
+
- **Returns**: List of duplicate dependencies grouped by `groupId:artifactId`.
|
|
157
|
+
|
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
pomanalyzer is a utility to analyze Apache Maven POM XML files offline. It extracts and formats dependency information, detects duplicate dependencies, and generates reports in various formats.
|
|
4
4
|
|
|
5
|
-
[](https://www.npmjs.com/package/pomanalyzer)
|
|
5
|
+
[](https://www.npmjs.com/package/pomanalyzer) [](https://sonarcloud.io/summary/new_code?id=zackria_pomanalyzer)
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
## Features
|
|
@@ -144,6 +144,10 @@ This package is thoroughly tested with over 90% code coverage to ensure reliabil
|
|
|
144
144
|
|
|
145
145
|

|
|
146
146
|
|
|
147
|
+
## Documentation
|
|
148
|
+
|
|
149
|
+
For more detailed information, please check the [Documentation](DOCUMENTATION.md).
|
|
150
|
+
|
|
147
151
|
## Compatibility
|
|
148
152
|
|
|
149
153
|
Developed and tested with:
|
package/cli.js
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
import { program } from 'commander';
|
|
4
4
|
import { analyzePom } from './src/index.js';
|
|
5
|
-
import { readFileSync } from 'fs';
|
|
6
|
-
import path from 'path';
|
|
5
|
+
import { readFileSync } from 'node:fs';
|
|
6
|
+
import path from 'node:path';
|
|
7
7
|
|
|
8
8
|
// Get version from package.json
|
|
9
9
|
let version = '1.0.0';
|
|
@@ -12,7 +12,9 @@ try {
|
|
|
12
12
|
const packageJson = JSON.parse(readFileSync('./package.json', 'utf8'));
|
|
13
13
|
version = packageJson.version;
|
|
14
14
|
} catch (err) {
|
|
15
|
-
|
|
15
|
+
if (err.code !== 'ENOENT') {
|
|
16
|
+
console.error(`Error reading package.json: ${err.message}`);
|
|
17
|
+
}
|
|
16
18
|
}
|
|
17
19
|
|
|
18
20
|
// Check if no arguments were provided
|
|
@@ -35,7 +37,7 @@ program
|
|
|
35
37
|
try {
|
|
36
38
|
// Resolve file path
|
|
37
39
|
const resolvedPath = path.resolve(pomFile);
|
|
38
|
-
|
|
40
|
+
|
|
39
41
|
// Prepare options for analysis
|
|
40
42
|
const analysisOptions = {
|
|
41
43
|
html: options.html,
|
|
@@ -46,7 +48,7 @@ program
|
|
|
46
48
|
|
|
47
49
|
// Use the centralized analyzePom function
|
|
48
50
|
await analyzePom(resolvedPath, analysisOptions);
|
|
49
|
-
|
|
51
|
+
|
|
50
52
|
} catch (error) {
|
|
51
53
|
console.error('Error:', error.message);
|
|
52
54
|
process.exit(1);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pomanalyzer",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "pomanalyzer is a utility to analyze Apache Maven POM XML file",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"pom",
|
|
@@ -26,22 +26,27 @@
|
|
|
26
26
|
},
|
|
27
27
|
"scripts": {
|
|
28
28
|
"test": "jest",
|
|
29
|
-
"run": "node ./src/index.js"
|
|
29
|
+
"run": "node ./src/index.js",
|
|
30
|
+
"clean": "rm -rf node_modules coverage"
|
|
30
31
|
},
|
|
31
32
|
"devDependencies": {
|
|
32
|
-
"@babel/core": "^7.
|
|
33
|
-
"@babel/preset-env": "^7.
|
|
34
|
-
"babel-jest": "^
|
|
35
|
-
"jest": "^
|
|
36
|
-
"jest-environment-node": "^
|
|
33
|
+
"@babel/core": "^7.28.5",
|
|
34
|
+
"@babel/preset-env": "^7.28.5",
|
|
35
|
+
"babel-jest": "^30.2.0",
|
|
36
|
+
"jest": "^30.2.0",
|
|
37
|
+
"jest-environment-node": "^30.2.0"
|
|
37
38
|
},
|
|
38
39
|
"dependencies": {
|
|
39
|
-
"chalk": "^5.
|
|
40
|
-
"commander": "^
|
|
41
|
-
"js-yaml": "^4.1.
|
|
40
|
+
"chalk": "^5.6.2",
|
|
41
|
+
"commander": "^14.0.2",
|
|
42
|
+
"js-yaml": "^4.1.1",
|
|
42
43
|
"xml2js": "^0.6.2"
|
|
43
44
|
},
|
|
45
|
+
"overrides": {
|
|
46
|
+
"test-exclude": "^7.0.1",
|
|
47
|
+
"glob": "^10.5.0"
|
|
48
|
+
},
|
|
44
49
|
"engines": {
|
|
45
50
|
"node": ">=14.0.0"
|
|
46
51
|
}
|
|
47
|
-
}
|
|
52
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
sonar.projectKey=zackria_pomanalyzer
|
|
2
|
+
sonar.organization=zackria
|
|
3
|
+
sonar.projectName=pomanalyzer
|
|
4
|
+
sonar.projectVersion=1.0.0
|
|
5
|
+
sonar.sources=src,cli.js
|
|
6
|
+
sonar.tests=test
|
|
7
|
+
sonar.language=js
|
|
8
|
+
sonar.sourceEncoding=UTF-8
|
|
9
|
+
sonar.javascript.lcov.reportPaths=coverage/lcov.info
|
|
10
|
+
|
|
11
|
+
# Exclude coverage and specific test files from all analysis
|
|
12
|
+
sonar.exclusions=coverage/**
|
|
13
|
+
|
|
14
|
+
# Exclude test files from duplication check (CPD)
|
|
15
|
+
sonar.cpd.exclusions=test/**/*.test.js,coverage/**
|
|
@@ -26,33 +26,29 @@ export async function readPomXml(filePath) {
|
|
|
26
26
|
*/
|
|
27
27
|
function extractDependencies(result) {
|
|
28
28
|
const dependencies = [];
|
|
29
|
-
|
|
30
|
-
if (!result
|
|
29
|
+
|
|
30
|
+
if (!result?.project) {
|
|
31
31
|
return dependencies;
|
|
32
32
|
}
|
|
33
|
-
|
|
34
|
-
const properties = result.project.properties ? result.project.properties[0] : {};
|
|
35
33
|
|
|
36
|
-
|
|
34
|
+
const properties = result.project.properties?.[0] ?? {};
|
|
35
|
+
|
|
36
|
+
if (result.project.dependencies?.[0]?.dependency) {
|
|
37
37
|
dependencies.push(
|
|
38
38
|
...result.project.dependencies[0].dependency.map((dep) => ({
|
|
39
|
-
groupId: dep.groupId
|
|
40
|
-
artifactId: dep.artifactId
|
|
41
|
-
version: resolveVersion(dep.version
|
|
39
|
+
groupId: dep.groupId?.[0] ?? 'unknown',
|
|
40
|
+
artifactId: dep.artifactId?.[0] ?? 'unknown',
|
|
41
|
+
version: resolveVersion(dep.version?.[0] ?? 'N/A', properties),
|
|
42
42
|
}))
|
|
43
43
|
);
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
-
if (result.project.dependencyManagement
|
|
47
|
-
result.project.dependencyManagement[0] &&
|
|
48
|
-
result.project.dependencyManagement[0].dependencies &&
|
|
49
|
-
result.project.dependencyManagement[0].dependencies[0] &&
|
|
50
|
-
result.project.dependencyManagement[0].dependencies[0].dependency) {
|
|
46
|
+
if (result.project.dependencyManagement?.[0]?.dependencies?.[0]?.dependency) {
|
|
51
47
|
dependencies.push(
|
|
52
48
|
...result.project.dependencyManagement[0].dependencies[0].dependency.map((dep) => ({
|
|
53
|
-
groupId: dep.groupId
|
|
54
|
-
artifactId: dep.artifactId
|
|
55
|
-
version: resolveVersion(dep.version
|
|
49
|
+
groupId: dep.groupId?.[0] ?? 'unknown',
|
|
50
|
+
artifactId: dep.artifactId?.[0] ?? 'unknown',
|
|
51
|
+
version: resolveVersion(dep.version?.[0] ?? 'N/A', properties),
|
|
56
52
|
}))
|
|
57
53
|
);
|
|
58
54
|
}
|
package/src/utils/fileUtils.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import fs from 'fs';
|
|
2
|
-
import path from 'path';
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Generates and saves an HTML table for the given dependencies.
|
|
@@ -18,7 +18,7 @@ export const printHTMLTable = (dependencies, duplicateDependencies, title, folde
|
|
|
18
18
|
th { background-color: #f2f2f2; }
|
|
19
19
|
.duplicate { background-color: #ffcccc; }
|
|
20
20
|
</style>`;
|
|
21
|
-
|
|
21
|
+
|
|
22
22
|
// Maven Dependencies table.
|
|
23
23
|
const depHeaders = Object.keys(dependencies[0] || {});
|
|
24
24
|
const dependenciesTable = `
|
|
@@ -38,7 +38,7 @@ export const printHTMLTable = (dependencies, duplicateDependencies, title, folde
|
|
|
38
38
|
</tbody>
|
|
39
39
|
</table>
|
|
40
40
|
`;
|
|
41
|
-
|
|
41
|
+
|
|
42
42
|
// Duplicate Dependencies table (if any).
|
|
43
43
|
let duplicateTable = '';
|
|
44
44
|
if (duplicateDependencies && duplicateDependencies.length > 0) {
|
|
@@ -61,9 +61,9 @@ export const printHTMLTable = (dependencies, duplicateDependencies, title, folde
|
|
|
61
61
|
</table>
|
|
62
62
|
`;
|
|
63
63
|
}
|
|
64
|
-
|
|
65
|
-
const htmlContent =
|
|
66
|
-
<html>
|
|
64
|
+
|
|
65
|
+
const htmlContent = `<!DOCTYPE html>
|
|
66
|
+
<html lang="en">
|
|
67
67
|
<head>
|
|
68
68
|
<meta charset="UTF-8">
|
|
69
69
|
<title>${title} Report</title>
|
|
@@ -75,9 +75,9 @@ export const printHTMLTable = (dependencies, duplicateDependencies, title, folde
|
|
|
75
75
|
</body>
|
|
76
76
|
</html>
|
|
77
77
|
`;
|
|
78
|
-
|
|
79
|
-
const filePath = path.join(folderPath, `${title.
|
|
80
|
-
|
|
78
|
+
|
|
79
|
+
const filePath = path.join(folderPath, `${title.replaceAll(/\s+/g, '_')}_report.html`);
|
|
80
|
+
|
|
81
81
|
// Ensure the folder exists
|
|
82
82
|
if (!fs.existsSync(folderPath)) {
|
|
83
83
|
fs.mkdirSync(folderPath, { recursive: true });
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import fs from 'fs';
|
|
2
|
-
import path from 'path';
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Generates and saves a Markdown table for the given dependencies.
|
|
@@ -17,7 +17,7 @@ export const printMarkdownTable = (dependencies, duplicateDependencies, title, f
|
|
|
17
17
|
| ${depHeaders.map(() => '---').join(' | ')} |
|
|
18
18
|
${dependencies.map(dep => `| ${Object.values(dep).join(' | ')} |`).join('\n')}
|
|
19
19
|
`;
|
|
20
|
-
|
|
20
|
+
|
|
21
21
|
let duplicateTable = '';
|
|
22
22
|
if (duplicateDependencies && duplicateDependencies.length > 0) {
|
|
23
23
|
const dupHeaders = Object.keys(duplicateDependencies[0] || {});
|
|
@@ -29,7 +29,7 @@ ${dependencies.map(dep => `| ${Object.values(dep).join(' | ')} |`).join('\n')}
|
|
|
29
29
|
${duplicateDependencies.map(dep => `| ${Object.values(dep).join(' | ')} | <!-- duplicate row -->`).join('\n')}
|
|
30
30
|
`;
|
|
31
31
|
}
|
|
32
|
-
|
|
32
|
+
|
|
33
33
|
const markdownContent = `
|
|
34
34
|
# Report
|
|
35
35
|
|
|
@@ -37,9 +37,9 @@ ${dependenciesTable}
|
|
|
37
37
|
|
|
38
38
|
${duplicateTable}
|
|
39
39
|
`;
|
|
40
|
-
|
|
41
|
-
const filePath = path.join(folderPath, `${title.
|
|
42
|
-
|
|
40
|
+
|
|
41
|
+
const filePath = path.join(folderPath, `${title.replaceAll(/\s+/g, '_')}_report.md`);
|
|
42
|
+
|
|
43
43
|
// Ensure the folder exists
|
|
44
44
|
if (!fs.existsSync(folderPath)) {
|
|
45
45
|
fs.mkdirSync(folderPath, { recursive: true });
|
package/test/fileUtils.test.js
CHANGED
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
<html>
|
|
3
|
-
<head>
|
|
4
|
-
<meta charset="UTF-8">
|
|
5
|
-
<title>Maven Dependencies Report</title>
|
|
6
|
-
<style>
|
|
7
|
-
body { font-family: Arial, sans-serif; margin: 20px; }
|
|
8
|
-
h2 { color: #333; }
|
|
9
|
-
table { width: 100%; border-collapse: collapse; margin-bottom: 20px; }
|
|
10
|
-
th, td { border: 1px solid #ddd; padding: 8px; text-align: left; }
|
|
11
|
-
th { background-color: #f2f2f2; }
|
|
12
|
-
.duplicate { background-color: #ffcccc; }
|
|
13
|
-
</style>
|
|
14
|
-
</head>
|
|
15
|
-
<body>
|
|
16
|
-
|
|
17
|
-
<h2>Maven Dependencies</h2>
|
|
18
|
-
<table>
|
|
19
|
-
<thead>
|
|
20
|
-
<tr>
|
|
21
|
-
<th>groupId</th><th>artifactId</th><th>version</th>
|
|
22
|
-
</tr>
|
|
23
|
-
</thead>
|
|
24
|
-
<tbody>
|
|
25
|
-
|
|
26
|
-
<tr>
|
|
27
|
-
<td>org.springframework</td><td>spring-core</td><td>5.3.9</td>
|
|
28
|
-
</tr>
|
|
29
|
-
|
|
30
|
-
<tr>
|
|
31
|
-
<td>org.springframework</td><td>spring-core</td><td>5.3.9</td>
|
|
32
|
-
</tr>
|
|
33
|
-
|
|
34
|
-
<tr>
|
|
35
|
-
<td>org.apache.commons</td><td>commons-lang3</td><td>N/A</td>
|
|
36
|
-
</tr>
|
|
37
|
-
|
|
38
|
-
<tr>
|
|
39
|
-
<td>org.apache.commons</td><td>commons-lang3</td><td>N/A</td>
|
|
40
|
-
</tr>
|
|
41
|
-
|
|
42
|
-
<tr>
|
|
43
|
-
<td>junit</td><td>junit</td><td>4.13.2</td>
|
|
44
|
-
</tr>
|
|
45
|
-
|
|
46
|
-
<tr>
|
|
47
|
-
<td>com.google.guava</td><td>guava</td><td>N/A</td>
|
|
48
|
-
</tr>
|
|
49
|
-
|
|
50
|
-
<tr>
|
|
51
|
-
<td>com.google.guava</td><td>guava</td><td>N/A</td>
|
|
52
|
-
</tr>
|
|
53
|
-
|
|
54
|
-
</tbody>
|
|
55
|
-
</table>
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
<h2>Duplicate Dependencies</h2>
|
|
59
|
-
<table>
|
|
60
|
-
<thead>
|
|
61
|
-
<tr>
|
|
62
|
-
<th>dependency</th><th>versions</th>
|
|
63
|
-
</tr>
|
|
64
|
-
</thead>
|
|
65
|
-
<tbody>
|
|
66
|
-
|
|
67
|
-
<tr class="duplicate">
|
|
68
|
-
<td>org.springframework:spring-core</td><td>5.3.9, 5.3.9</td>
|
|
69
|
-
</tr>
|
|
70
|
-
|
|
71
|
-
<tr class="duplicate">
|
|
72
|
-
<td>org.apache.commons:commons-lang3</td><td>N/A, N/A</td>
|
|
73
|
-
</tr>
|
|
74
|
-
|
|
75
|
-
<tr class="duplicate">
|
|
76
|
-
<td>com.google.guava:guava</td><td>N/A, N/A</td>
|
|
77
|
-
</tr>
|
|
78
|
-
|
|
79
|
-
</tbody>
|
|
80
|
-
</table>
|
|
81
|
-
|
|
82
|
-
</body>
|
|
83
|
-
</html>
|
|
84
|
-
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
# Report
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
## Maven Dependencies
|
|
5
|
-
|
|
6
|
-
| groupId | artifactId | version |
|
|
7
|
-
| --- | --- | --- |
|
|
8
|
-
| org.springframework | spring-core | 5.3.9 |
|
|
9
|
-
| org.springframework | spring-core | 5.3.9 |
|
|
10
|
-
| org.apache.commons | commons-lang3 | N/A |
|
|
11
|
-
| org.apache.commons | commons-lang3 | N/A |
|
|
12
|
-
| junit | junit | 4.13.2 |
|
|
13
|
-
| com.google.guava | guava | N/A |
|
|
14
|
-
| com.google.guava | guava | N/A |
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
## Duplicate Dependencies
|
|
19
|
-
|
|
20
|
-
| dependency | versions |
|
|
21
|
-
| --- | --- |
|
|
22
|
-
| org.springframework:spring-core | 5.3.9, 5.3.9 | <!-- duplicate row -->
|
|
23
|
-
| org.apache.commons:commons-lang3 | N/A, N/A | <!-- duplicate row -->
|
|
24
|
-
| com.google.guava:guava | N/A, N/A | <!-- duplicate row -->
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|