Created
August 18, 2014 10:20
-
-
Save bergie/df7d0ee046e385080f3f to your computer and use it in GitHub Desktop.
Extract inline FBP graphs to files
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
fs = require 'fs' | |
jsdom = require 'jsdom' | |
writeGraph = (id, content) -> | |
console.log id | |
content = content.replace /\>\;/g, '>' | |
content = content.replace /\n[\s]*/g, '\n' | |
content = content.replace /local\//g, 'ui/' | |
fs.writeFileSync "graphs/#{id}.fbp", content | |
jsdom.env fs.readFileSync('index.dist.html', 'utf-8'), | |
ProcessExternalResources: false | |
, (err, win) -> | |
return console.error 'ERR', err if err | |
graphs = win.document.querySelectorAll 'script[type="application/fbp"]' | |
for graph in graphs | |
writeGraph graph.getAttribute('id'), graph.textContent |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment