I created a npm package that fetches the dependencies of any github repository
Rocktim Saikia
Posted on November 4, 2019
Few days i ago i was working on a very minimal nextjs based portfolio boilerplate that fetches all your repositories from your github account and displays them as your personal projects .I was quite happy with the over-all design of the site but then i had a fun little idea that it would be really cool if i could show all the tools and libraries that are being used on each github repository and display those tools and libraries as extra tags on each project card of my portfolio page.
So i started digging through the whole github api documents but cound not find anything relating to that issue.The only thing the api returns relating to what my need was the language
property which only returns the programming language that most of the codes are written in; After getting nothing from the documentations i started tweaking the actual api and found something very interesting.The information about the dependencies actually are available in the api but was nested deeply and the most interesting thing is that it was not in plain object; it was in encoded as base 64 strings so it was quite a headache.
Since i didn't get any direct help from the github documents i thought of making a module that exactly does this job which is decoding the base 64
strings from all the nested objects and representing the actual data in a easy to integrate and friendly manner.So i went on ahead and created the module which gets my job done .Since i thought anyone might needs this same feature in their node based web applications this might be good idea to make it into a actual npm package. So i ended up creating dependency-fetcher .This tiny 1.9kB
tool extracts all the libraries/tools along with their respective versions
that are being used in a node based github repository and returns them in simple object.So you don't have to worry about all ugly things behind the scenes.
This is how it works in real world app.It takes two arguments , your github username
and the repository name
you want extract from.
example :
const getDependencies = require("dependency-fetcher");
//add user_name and repo_ name
getDependencies("RocktimSaikia", "git-job").then(res => {
console.log(res);
});
/* returns :
{
dependencies: [
{ package: 'axios', version: '0.18.1' },
{ package: 'chalk', version: '2.4.2' },
{ package: 'meow', version: '5.0.0' },
{ package: 'striptags', version: '3.1.1' }
],
devDependencies: [
{ package: 'eslint', version: '5.16.0' },
{ package: 'eslint-config-airbnb-base', version: '13.2.0' },
{ package: 'eslint-plugin-import', version: '2.18.2' }
]
}
*/
I also used this module on my tiny portfolio too .
Source Repo : https://github.com/RocktimSaikia/dependency-fetcher;
npm package : https://npm.im/dependency-fetcher
And that's about it π
If you liked the idea behind this tiny module.Then please give it a starπ in the project repo π
Thanks for reading π
This is my first tech article ever of my life. I am doing software development for almost 2 years now but never got into writing. This is really special to me to publish my first article as i was thinking about doing it for a long time but never did it. Hopefully will make more useful stuff and try to document them too π
Posted on November 4, 2019
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.
Related
May 23, 2022
November 4, 2019