Skip to content

Commit d39103f

Browse files
committed
Add final HTML file
1 parent 67b378f commit d39103f

File tree

2 files changed

+118
-1
lines changed

2 files changed

+118
-1
lines changed

lib/cocoapods-dependency/command/dependency.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
require 'cocoapods-dependency/analyze'
22
require 'pp'
33
require 'cocoapods-dependency/visual_out'
4+
require 'tmpdir'
45

56
module Pod
67
class Command
@@ -32,7 +33,13 @@ def run
3233
analyze_result = CocoapodsDependency::Analyzer.analyze_with_podfile(nil, config.podfile)
3334
if @using_visual_output
3435
helper = CocoapodsDependency::VisualOutHelper.new(analyze_result)
35-
helper.write_json_to_file('/tmp/index.json')
36+
final_path = Dir.tmpdir
37+
helper.write_json_to_file("#{final_path}/index.json")
38+
html_path = File.expand_path("../resources/index.html", __dir__)
39+
system "cp #{html_path} #{final_path}"
40+
final_html_path = "#{final_path}/index.html"
41+
puts "[CocoapodsDependency] ✅ html file generated at path #{final_html_path}"
42+
system "open #{final_html_path}"
3643
else
3744
pp result
3845
end
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
<!DOCTYPE html>
2+
<html>
3+
4+
<head>
5+
<meta charset="UTF-8">
6+
<title>Dependency Checker for CocoaPods Projects</title>
7+
<style type="text/css">
8+
#nav a {
9+
display: block;
10+
}
11+
12+
html,
13+
body {
14+
height: 100%;
15+
}
16+
17+
#nav {
18+
padding: 10px 30px;
19+
float: left;
20+
width: 30%;
21+
height: 100%;
22+
overflow: scroll;
23+
}
24+
25+
#content {
26+
padding: 10px 30px;
27+
float: left;
28+
width: 60%;
29+
height: 100%;
30+
overflow: scroll;
31+
}
32+
</style>
33+
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/css/bootstrap.min.css" integrity="sha384-/Y6pD6FV/Vv2HJnA6t+vslU6fwYXjCFtcEpHbNJ0lyAFsXTsjBbfaDjzALeQsN6M" crossorigin="anonymous">
34+
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/js/bootstrap.min.js" integrity="sha384-h0AbiXch4ZDo7tp9hKZ4TsHbi047NrKGLO3SEJAg45jXxnGIfYzk4Si90RDIqNm1" crossorigin="anonymous"></script>
35+
36+
<body onload="pageDidLoad()">
37+
<script>
38+
39+
function loadJSON(fileName, callback) {
40+
var xobj = new XMLHttpRequest();
41+
xobj.overrideMimeType("application/json");
42+
xobj.open('GET', fileName, true);
43+
xobj.onreadystatechange = function () {
44+
if (xobj.readyState == 4 && xobj.status == "200") {
45+
callback(xobj.responseText);
46+
}
47+
};
48+
xobj.send(null);
49+
}
50+
51+
function pageDidLoad() {
52+
loadJSON('index.json', response => {
53+
var actual_JSON = JSON.parse(response);
54+
55+
let podNames = actual_JSON.links.map(s => s.source);
56+
57+
renderNavs(podNames)
58+
renderPods(actual_JSON.links)
59+
});
60+
}
61+
62+
function renderNavs(podNames) {
63+
let fLeft = document.getElementById('nav')
64+
podNames.forEach(e => {
65+
let nav = document.createElement('a')
66+
nav.href = '#' + e
67+
nav.innerText = e
68+
fLeft.appendChild(nav)
69+
})
70+
}
71+
72+
function renderPods(pods) {
73+
let d = document.getElementById('pods')
74+
pods.forEach(element => {
75+
let div = document.createElement('div')
76+
let header = document.createElement('h3')
77+
header.innerHTML = element.source
78+
header.id = element.source
79+
80+
div.appendChild(header)
81+
82+
let ul = document.createElement('ul')
83+
let dependencies = element.dependencies.sort()
84+
dependencies.forEach(dependency => {
85+
let li = document.createElement('li')
86+
let a = document.createElement('a')
87+
a.innerHTML = dependency
88+
a.href = '#' + dependency
89+
ul.appendChild(li)
90+
li.appendChild(a)
91+
})
92+
93+
div.appendChild(ul)
94+
d.appendChild(div)
95+
})
96+
}
97+
98+
</script>
99+
</head>
100+
101+
<body>
102+
<div id="nav">
103+
104+
</div>
105+
<div id="content">
106+
<div id="pods"></div>
107+
</div>
108+
</body>
109+
110+
</html>

0 commit comments

Comments
 (0)