-
-
Notifications
You must be signed in to change notification settings - Fork 151
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9e98ce1
commit c6b3025
Showing
1 changed file
with
56 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#!/usr/bin/env node | ||
const fs = require("fs"); | ||
const execSync = require('child_process').execSync; | ||
const dg = require("@thi.ng/dgraph"); | ||
const tx = require("@thi.ng/transducers"); | ||
|
||
const baseDir = "./packages/"; | ||
const col = "#555555"; | ||
const ecol = "#aaaaaa"; | ||
|
||
const xform = tx.comp( | ||
tx.map((f) => baseDir + f), | ||
tx.filter((f) => f.indexOf(".DS_Store") < 0 && fs.statSync(f).isDirectory), | ||
tx.map((f) => fs.readFileSync(f + "/package.json")), | ||
tx.map((p) => { | ||
p = JSON.parse(p.toString()); | ||
return { | ||
id: p.name, | ||
v: p.version, | ||
deps: p.dependencies ? Object.keys(p.dependencies) : [] | ||
}; | ||
})); | ||
|
||
const packages = tx.transduce(xform, tx.push(), fs.readdirSync(baseDir)); | ||
const formatted = tx.transduce( | ||
tx.map((m) => `"${m.id}"[color="${col}",label="${m.id}\\n${m.v}"];\n` + | ||
m.deps.map((d) => `"${m.id}" -> "${d}"[color="${ecol}"];`).join("\n")), | ||
tx.str("\n"), | ||
packages | ||
); | ||
const leaves = tx.transduce( | ||
tx.comp(tx.filter((p) => !p.deps.length), tx.map((p) => `"${p.id}";`)), | ||
tx.str(" "), | ||
packages | ||
); | ||
|
||
const dot = `digraph g { | ||
# size="16,9"; | ||
# ratio=fill; | ||
rankdir=RL; | ||
node[fontname=Inconsolata,fontsize=9,fontcolor=white,style=filled]; | ||
edge[arrowsize=0.66]; | ||
${formatted} | ||
subgraph cluster0 { color="white"; rank=same; ${leaves} } | ||
}`; | ||
fs.writeFileSync("assets/deps.dot", dot, "utf8"); | ||
execSync("dot -Tpng -o assets/deps.png assets/deps.dot"); | ||
|
||
const g = new dg.DGraph(); | ||
tx.run( | ||
tx.mapcat((p) => tx.tuples(tx.repeat(p.id), p.deps)), | ||
([p, d]) => g.addDependency(p, d), | ||
packages); | ||
|
||
console.log("topo order:", g.sort().map((x) => x.replace("@thi.ng/", "")).join(" ")); | ||
console.log("done"); |