easy-dep-graph 1.0.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/LICENSE +21 -0
- package/README.md +87 -0
- package/bin/index.js +118 -0
- package/package.json +62 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 danisss9
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
# Easy Dep Graph
|
|
2
|
+
|
|
3
|
+
Easily see the dependency graph of your npm project!
|
|
4
|
+
|
|
5
|
+
## Table of Contents
|
|
6
|
+
|
|
7
|
+
- [Easy Dep Graph](#easy-dep-graph)
|
|
8
|
+
- [Table of Contents](#table-of-contents)
|
|
9
|
+
- [Install](#install)
|
|
10
|
+
- [Use](#use)
|
|
11
|
+
- [Arguments](#arguments)
|
|
12
|
+
- [Packages](#packages)
|
|
13
|
+
- [Package Dependents](#package-dependents)
|
|
14
|
+
- [Port](#port)
|
|
15
|
+
- [No Open](#no-open)
|
|
16
|
+
- [Changelog](#changelog)
|
|
17
|
+
- [FAQs](#faqs)
|
|
18
|
+
|
|
19
|
+
## Install
|
|
20
|
+
|
|
21
|
+
```cmd
|
|
22
|
+
npm install -g easy-dep-graph
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Use
|
|
26
|
+
|
|
27
|
+
Run the following command on the folder where you package.json is:
|
|
28
|
+
|
|
29
|
+
```cmd
|
|
30
|
+
npx easy-dep-graph
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Arguments
|
|
34
|
+
|
|
35
|
+
### Packages
|
|
36
|
+
|
|
37
|
+
A list of packages to show on the graph separated by ','. (By default it shows all packages)
|
|
38
|
+
|
|
39
|
+
Command: `--packages <packages names>`
|
|
40
|
+
|
|
41
|
+
Example:
|
|
42
|
+
```cmd
|
|
43
|
+
npx easy-dep-graph --packages open,mustache,fastify
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### Package Dependents
|
|
47
|
+
|
|
48
|
+
This option will only show on graph the packages that depend on the submited package.
|
|
49
|
+
|
|
50
|
+
Command: `--package-dependents <package name>`
|
|
51
|
+
|
|
52
|
+
Example:
|
|
53
|
+
```cmd
|
|
54
|
+
npx easy-dep-graph --package-dependents is-docker
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### Port
|
|
58
|
+
|
|
59
|
+
The port number to be used when serving the dependency graph. (Default is 8080)
|
|
60
|
+
|
|
61
|
+
Command: `--port <port number>`
|
|
62
|
+
|
|
63
|
+
Example:
|
|
64
|
+
```cmd
|
|
65
|
+
npx easy-dep-graph --port 8000
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### No Open
|
|
69
|
+
|
|
70
|
+
Flag to not open the browser after the depedency graph is done.
|
|
71
|
+
|
|
72
|
+
Command: `--no-open`
|
|
73
|
+
|
|
74
|
+
Example:
|
|
75
|
+
```cmd
|
|
76
|
+
npx easy-dep-graph --no-open
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## Changelog
|
|
80
|
+
|
|
81
|
+
**Version 1.0:**
|
|
82
|
+
|
|
83
|
+
- published library
|
|
84
|
+
|
|
85
|
+
## FAQs
|
|
86
|
+
|
|
87
|
+
No FAQs for now. (⌐■_■)
|
package/bin/index.js
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
#! /usr/bin/env node
|
|
2
|
+
import shell from "shelljs";
|
|
3
|
+
import mustache from "mustache";
|
|
4
|
+
import fastify from "fastify";
|
|
5
|
+
import open from "open";
|
|
6
|
+
let flatDeps;
|
|
7
|
+
void (async function main() {
|
|
8
|
+
// List of packages user wants to see the dependencies
|
|
9
|
+
const packagesArgIndex = process.argv.findIndex((a) => a.toLowerCase() === "--packages");
|
|
10
|
+
const packagesFilter = packagesArgIndex !== -1 ? process.argv[packagesArgIndex + 1] : undefined;
|
|
11
|
+
// Only get the dependents of a specific package
|
|
12
|
+
const packageArgIndex = process.argv.findIndex((a) => a.toLowerCase() === "--package-dependents");
|
|
13
|
+
const packageName = packageArgIndex !== -1 ? process.argv[packageArgIndex + 1] : undefined;
|
|
14
|
+
// Get port number
|
|
15
|
+
const portArgIndex = process.argv.findIndex((a) => a.toLowerCase() === "--port");
|
|
16
|
+
const port = portArgIndex !== -1 ? +process.argv[portArgIndex + 1] : 8080;
|
|
17
|
+
// Get if should not open browser
|
|
18
|
+
const shouldOpenBrowser = process.argv.findIndex((a) => a.toLowerCase() === "--no-open") === -1;
|
|
19
|
+
// Run npm list command
|
|
20
|
+
const result = shell.exec(`npm list --json ${packageName ?? "--all"}`, {
|
|
21
|
+
windowsHide: true,
|
|
22
|
+
silent: true,
|
|
23
|
+
});
|
|
24
|
+
// Parse the result to a JSON object
|
|
25
|
+
const packageInfo = JSON.parse(result.stdout);
|
|
26
|
+
console.log(`Generating dependency graph for: "${packageInfo.name}"...`);
|
|
27
|
+
// Filter dependencies if needed
|
|
28
|
+
if (packagesFilter != null) {
|
|
29
|
+
const packagesFilterList = packagesFilter.split(",").map((d) => d.trim());
|
|
30
|
+
for (const key of Object.keys(packageInfo.dependencies)) {
|
|
31
|
+
if (!packagesFilterList.includes(key)) {
|
|
32
|
+
delete packageInfo.dependencies[key];
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
// Flat the dependencies from npm list
|
|
37
|
+
flatDeps = {};
|
|
38
|
+
flatDepsRecursive(packageInfo.dependencies);
|
|
39
|
+
// Turn deps into nodes and edges
|
|
40
|
+
const data = {
|
|
41
|
+
name: packageInfo.name,
|
|
42
|
+
nodes: JSON.stringify(Object.entries(flatDeps).map((dep) => ({
|
|
43
|
+
id: dep[0],
|
|
44
|
+
label: `${dep[0]} V${dep[1].version}`,
|
|
45
|
+
color: { border: dep[1].isRoot ? "green" : "blue" },
|
|
46
|
+
}))),
|
|
47
|
+
edges: JSON.stringify(Object.entries(flatDeps)
|
|
48
|
+
.filter((dep) => !!dep[1].dependencies.length)
|
|
49
|
+
.flatMap((dep) => dep[1].dependencies.map((d) => ({
|
|
50
|
+
from: dep[0],
|
|
51
|
+
to: d,
|
|
52
|
+
arrows: "to",
|
|
53
|
+
})))),
|
|
54
|
+
};
|
|
55
|
+
// Render the UI using mustache
|
|
56
|
+
const html = mustache.render(getTemplate(), data);
|
|
57
|
+
// Initialize server to serve graph
|
|
58
|
+
const app = fastify({
|
|
59
|
+
logger: false,
|
|
60
|
+
});
|
|
61
|
+
app.get("/", (_req, resp) => resp.type("text/html").send(html));
|
|
62
|
+
// Run the server
|
|
63
|
+
app.listen({ port }, (err, address) => {
|
|
64
|
+
if (err)
|
|
65
|
+
throw err;
|
|
66
|
+
console.log(`Done! Visit "${address}" to see dependecy graph.`);
|
|
67
|
+
if (shouldOpenBrowser)
|
|
68
|
+
open(address);
|
|
69
|
+
});
|
|
70
|
+
})();
|
|
71
|
+
function flatDepsRecursive(deps, parentDepName) {
|
|
72
|
+
if (deps == null)
|
|
73
|
+
return;
|
|
74
|
+
for (const dep of Object.entries(deps)) {
|
|
75
|
+
const depName = dep[0];
|
|
76
|
+
const depInfo = dep[1];
|
|
77
|
+
const isRoot = parentDepName == null;
|
|
78
|
+
if (!isRoot) {
|
|
79
|
+
const parentDep = flatDeps[parentDepName];
|
|
80
|
+
parentDep.dependencies.push(depName);
|
|
81
|
+
}
|
|
82
|
+
if (flatDeps[depName] == null) {
|
|
83
|
+
flatDeps[depName] = {
|
|
84
|
+
version: depInfo.version,
|
|
85
|
+
isRoot,
|
|
86
|
+
dependencies: [],
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
flatDepsRecursive(depInfo.dependencies, depName);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
function getTemplate() {
|
|
93
|
+
return `
|
|
94
|
+
<html>
|
|
95
|
+
<head>
|
|
96
|
+
<title>{{name}}'s Dependency Graph</title>
|
|
97
|
+
<script type="text/javascript" src="https://unpkg.com/vis-network/standalone/umd/vis-network.min.js"></script>
|
|
98
|
+
<script type="text/javascript">
|
|
99
|
+
function renderGraph() {
|
|
100
|
+
var nodes = new vis.DataSet({{{nodes}}});
|
|
101
|
+
var edges = new vis.DataSet({{{edges}}});
|
|
102
|
+
var container = document.getElementById("dep-graph");
|
|
103
|
+
var data = { nodes: nodes, edges: edges };
|
|
104
|
+
var options = { };
|
|
105
|
+
var network = new vis.Network(container, data, options);
|
|
106
|
+
}
|
|
107
|
+
</script>
|
|
108
|
+
<style>
|
|
109
|
+
body { margin: 0; padding: 0; }
|
|
110
|
+
#dep-graph { width: 100vw; height: 100vh; }
|
|
111
|
+
</style>
|
|
112
|
+
</head>
|
|
113
|
+
<body onload="renderGraph()">
|
|
114
|
+
<div id="dep-graph"></div>
|
|
115
|
+
</body>
|
|
116
|
+
</html>
|
|
117
|
+
`;
|
|
118
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "easy-dep-graph",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Easily see the dependency graph of your npm project",
|
|
5
|
+
"homepage": "https://github.com/danisss9/easy-dep-graph#readme",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/danisss9/easy-dep-graph.git"
|
|
9
|
+
},
|
|
10
|
+
"bugs": {
|
|
11
|
+
"url": "https://github.com/danisss9/easy-dep-graph/issues"
|
|
12
|
+
},
|
|
13
|
+
"bin": {
|
|
14
|
+
"easy-dep-graph": "bin/index.js"
|
|
15
|
+
},
|
|
16
|
+
"type": "module",
|
|
17
|
+
"license": "MIT",
|
|
18
|
+
"keywords": [
|
|
19
|
+
"node",
|
|
20
|
+
"nodejs",
|
|
21
|
+
"npm",
|
|
22
|
+
"npx",
|
|
23
|
+
"list",
|
|
24
|
+
"la",
|
|
25
|
+
"la",
|
|
26
|
+
"easy",
|
|
27
|
+
"dep",
|
|
28
|
+
"circular",
|
|
29
|
+
"dependencies",
|
|
30
|
+
"dependency",
|
|
31
|
+
"dependent",
|
|
32
|
+
"graph",
|
|
33
|
+
"visual",
|
|
34
|
+
"browser",
|
|
35
|
+
"angular",
|
|
36
|
+
"ng",
|
|
37
|
+
"react",
|
|
38
|
+
"vue",
|
|
39
|
+
"svelte",
|
|
40
|
+
"javascript",
|
|
41
|
+
"typescript",
|
|
42
|
+
"js",
|
|
43
|
+
"ts"
|
|
44
|
+
],
|
|
45
|
+
"scripts": {
|
|
46
|
+
"release": "npm run compile:lib && npm run publish:lib",
|
|
47
|
+
"compile:lib": "tsc --project ./src/tsconfig.json",
|
|
48
|
+
"publish:lib": "npm publish --access public"
|
|
49
|
+
},
|
|
50
|
+
"dependencies": {
|
|
51
|
+
"fastify": "^4.25.2",
|
|
52
|
+
"mustache": "^4.2.0",
|
|
53
|
+
"open": "^10.0.3",
|
|
54
|
+
"shelljs": "^0.8.5"
|
|
55
|
+
},
|
|
56
|
+
"devDependencies": {
|
|
57
|
+
"@types/mustache": "^4.2.5",
|
|
58
|
+
"@types/node": "^20.11.5",
|
|
59
|
+
"@types/shelljs": "^0.8.15",
|
|
60
|
+
"typescript": "^5.3.3"
|
|
61
|
+
}
|
|
62
|
+
}
|