Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

import from glitch #1

Merged
merged 1 commit into from Jul 10, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions .config/configstore/update-notifier-micro.json
@@ -0,0 +1,4 @@
{
"optOut": false,
"lastUpdateCheck": 1499643043124
}
4 changes: 4 additions & 0 deletions .config/configstore/update-notifier-micro.json.2064645767
@@ -0,0 +1,4 @@
{
"optOut": false,
"lastUpdateCheck": 1499643041153
}
4 changes: 4 additions & 0 deletions .config/configstore/update-notifier-npm.json
@@ -0,0 +1,4 @@
{
"optOut": false,
"lastUpdateCheck": 1499635379712
}
3 changes: 3 additions & 0 deletions .glitch-assets
@@ -0,0 +1,3 @@
{"name":"drag-in-files.svg","date":"2016-10-22T16:17:49.954Z","url":"https://cdn.hyperdev.com/drag-in-files.svg","type":"image/svg","size":7646,"imageWidth":276,"imageHeight":276,"thumbnail":"https://cdn.hyperdev.com/drag-in-files.svg","thumbnailWidth":276,"thumbnailHeight":276,"dominantColor":"rgb(102, 153, 205)","uuid":"adSBq97hhhpFNUna"}
{"name":"click-me.svg","date":"2016-10-23T16:17:49.954Z","url":"https://cdn.hyperdev.com/click-me.svg","type":"image/svg","size":7116,"imageWidth":276,"imageHeight":276,"thumbnail":"https://cdn.hyperdev.com/click-me.svg","thumbnailWidth":276,"thumbnailHeight":276,"dominantColor":"rgb(243, 185, 186)","uuid":"adSBq97hhhpFNUnb"}
{"name":"paste-me.svg","date":"2016-10-24T16:17:49.954Z","url":"https://cdn.hyperdev.com/paste-me.svg","type":"image/svg","size":7242,"imageWidth":276,"imageHeight":276,"thumbnail":"https://cdn.hyperdev.com/paste-me.svg","thumbnailWidth":276,"thumbnailHeight":276,"dominantColor":"rgb(42, 179, 185)","uuid":"adSBq97hhhpFNUnc"}
3 changes: 0 additions & 3 deletions README.md

This file was deleted.

65 changes: 65 additions & 0 deletions graph.js
@@ -0,0 +1,65 @@
const fs = require('fs')
const Viz = require('viz.js')
const download = require('co-download')
const decompress = require('decompress')
const mkdirp = require('mkdirp')
const dep = require('dependency-tree')
const relative = require('relative')

var cache = {}
var inc = 0
var base

module.exports = function (user, repo, file = 'index.js') {
let folder = '/tmp/' + user + '/' + repo
base = folder + '/' + repo + '-master'
mkdirp.sync(folder)

return download('https://github.com/' + user + '/' + repo + '/archive/master.zip', '/tmp/master.zip')
.then(filepath => decompress(filepath, folder))
.then(() => {
let res = dep({
filename: base + '/' + file,
directory: base
})
var dot = {dot: 'digraph main {\n'}
recurse(dot, res)
dot.dot += '}'
return Viz(dot.dot)
})
.catch(console.log)
}

function nodecache (dot, path) {
let p = './' + relative(base, path)
var id
if (p in cache) {
id = cache[p]
} else {
id = inc++
cache[p] = id
dot.dot += ' f' + id + '[label="' + p + '"]\n'
}
return [id, p]
}

function relcache (dot, from, to) {
let def = 'f' + from + '->f' + to
if (!(def in cache)) {
dot.dot += ' ' + def + '\n'
}
}

function recurse (dot, paths) {
for (let path in paths) {
let [id, p] = nodecache(dot, path)

if (typeof paths[path] === 'object') {
Object.keys(paths[path]).forEach(dep => {
let [did] = nodecache(dot, dep)
relcache(dot, id, did)
})
recurse(dot, paths[path])
}
}
}
16 changes: 16 additions & 0 deletions package.json
@@ -0,0 +1,16 @@
{
"name": "node-dependencies-view",
"description": "nada",
"dependencies": {
"viz.js": "^1.8.0",
"co-download": "^0.2.0",
"decompress": "^4.2.0",
"mkdirp": "^0.5.1",
"dependency-tree": "^5.9.1",
"relative": "^3.0.2",
"express": "^4.15.3"
},
"scripts": {
"start": "node server.js"
}
}
15 changes: 15 additions & 0 deletions server.js
@@ -0,0 +1,15 @@
const express = require('express')

const graph = require('./graph')

const app = express()

app.get('/:user/:repo/**', (r, w) => {
console.log(r.params)
graph(r.params.user, r.params.repo, r.params[0])
.then(svg => w.send(svg))
.catch(console.log)
})

let port = process.env.PORT || 3000
app.listen(port, () => console.log('listening at :' + port))