-
-
Notifications
You must be signed in to change notification settings - Fork 72
/
Copy pathpipfile.html
200 lines (173 loc) · 5.19 KB
/
pipfile.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Pipfile.lock Dependency Parser</title>
<style>
* {
box-sizing: border-box;
}
body {
font-family: Helvetica, Arial, sans-serif;
line-height: 1.6;
max-width: 800px;
margin: 0 auto;
padding: 20px;
color: #333;
}
h1 {
margin-top: 0;
}
textarea {
width: 100%;
height: 300px;
padding: 10px;
margin-bottom: 15px;
border: 1px solid #ccc;
border-radius: 4px;
font-size: 16px;
font-family: monospace;
}
button {
background-color: #4CAF50;
color: white;
border: none;
padding: 10px 15px;
cursor: pointer;
border-radius: 4px;
font-size: 16px;
}
button:hover {
background-color: #45a049;
}
pre {
background-color: #f5f5f5;
padding: 15px;
border-radius: 4px;
overflow-x: auto;
white-space: pre-wrap;
margin-top: 20px;
}
.error {
color: #d9534f;
margin-top: 10px;
}
.controls {
display: flex;
gap: 10px;
margin-bottom: 15px;
}
</style>
</head>
<body>
<h1>Pipfile.lock Dependency Parser</h1>
<p>Paste your Pipfile.lock content below and click "Parse" to extract dependencies with their versions.</p>
<textarea id="input" placeholder="Paste Pipfile.lock content here..."></textarea>
<div class="controls">
<button id="parseBtn">Parse Dependencies</button>
<button id="copyPipfileBtn">Copy Pipfile Format</button>
<button id="copyReqsBtn">Copy Requirements.txt</button>
<button id="clearBtn">Clear All</button>
</div>
<div id="error" class="error"></div>
<h2>Pipfile Format:</h2>
<pre id="output"></pre>
<h2>Requirements.txt Format:</h2>
<pre id="reqsOutput"></pre>
<script type="module">
// Parse the Pipfile.lock content and extract dependencies
function parsePipfileLock(content) {
try {
// Parse the JSON content
const data = JSON.parse(content);
let pipfileFormat = [];
let reqsFormat = [];
// Process dependencies from "default" section
if (data.default) {
for (const [name, info] of Object.entries(data.default)) {
if (info.version) {
// Extract version without the '==' prefix
const version = info.version.replace(/^==/, '');
pipfileFormat.push(`"${name}" = "==${version}"`);
reqsFormat.push(`${name}==${version}`);
}
}
}
// Process dependencies from "develop" section if needed
if (data.develop) {
for (const [name, info] of Object.entries(data.develop)) {
if (info.version) {
const version = info.version.replace(/^==/, '');
pipfileFormat.push(`"${name}" = "==${version}"`);
reqsFormat.push(`${name}==${version}`);
}
}
}
return {
pipfileFormat: pipfileFormat.join('\n'),
reqsFormat: reqsFormat.join('\n')
};
} catch (error) {
throw new Error(`Failed to parse Pipfile.lock: ${error.message}`);
}
}
// Set up event handlers
document.getElementById('parseBtn').addEventListener('click', () => {
const input = document.getElementById('input').value.trim();
const pipfileOutputEl = document.getElementById('output');
const reqsOutputEl = document.getElementById('reqsOutput');
const errorEl = document.getElementById('error');
errorEl.textContent = '';
if (!input) {
errorEl.textContent = 'Please paste Pipfile.lock content first.';
return;
}
try {
const result = parsePipfileLock(input);
pipfileOutputEl.textContent = result.pipfileFormat;
reqsOutputEl.textContent = result.reqsFormat;
} catch (error) {
errorEl.textContent = error.message;
}
});
function copyToClipboard(text, successMessage) {
if (!text) {
document.getElementById('error').textContent = 'No content to copy.';
return;
}
navigator.clipboard.writeText(text)
.then(() => {
const errorEl = document.getElementById('error');
errorEl.textContent = successMessage || 'Output copied to clipboard!';
errorEl.style.color = '#4CAF50';
setTimeout(() => {
errorEl.textContent = '';
errorEl.style.color = '#d9534f';
}, 2000);
})
.catch(err => {
document.getElementById('error').textContent = 'Failed to copy: ' + err;
});
}
document.getElementById('copyPipfileBtn').addEventListener('click', () => {
const output = document.getElementById('output').textContent;
copyToClipboard(output, 'Pipfile format copied to clipboard!');
});
document.getElementById('copyReqsBtn').addEventListener('click', () => {
const output = document.getElementById('reqsOutput').textContent;
copyToClipboard(output, 'Requirements.txt format copied to clipboard!');
});
document.getElementById('clearBtn').addEventListener('click', () => {
document.getElementById('input').value = '';
document.getElementById('output').textContent = '';
document.getElementById('error').textContent = '';
});
// Initialize with example data from the textarea if present
const initialContent = document.getElementById('input').value.trim();
if (initialContent) {
document.getElementById('parseBtn').click();
}
</script>
</body>
</html>