Created
June 11, 2019 23:41
-
-
Save Michaela-Davis/3fff2a7ce19b8753636e7a3c763eefde to your computer and use it in GitHub Desktop.
CSV to HTML
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env node | |
const csv = require("csvtojson"); | |
const fs = require('fs'); | |
csv() | |
.fromFile(`${__dirname}/dependencies.csv`) | |
.then((json)=>{ | |
// console.log(json); | |
const html = json.map(row => { | |
let repository = row.repository; | |
if (row.repository.includes("ssh://")){ | |
repository = row.repository.replace("ssh://git@","https://www."); | |
} | |
console.log(row); | |
return ` | |
<tr> | |
<td>${row.name} v${row.version}</td> | |
<td>${row.summary}</td> | |
<td>${repository.includes("http") ? | |
`<a href="${repository}">${repository}</a>` : | |
`none` | |
}</td> | |
</tr> | |
` | |
}).join(''); | |
const htmlWrapped = ` | |
<table id="dependencies"> | |
<tbody> | |
<thead> | |
<tr> | |
<th>Name v#</th> | |
<th>License</th> | |
<th>Respository</th> | |
</tr> | |
</thead> | |
${html} | |
</tbody> | |
</table>` | |
fs.writeFileSync('./index.html', htmlWrapped); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment