Skip to content

Instantly share code, notes, and snippets.

@bergie
Created August 18, 2014 10:20
Show Gist options
  • Save bergie/df7d0ee046e385080f3f to your computer and use it in GitHub Desktop.
Save bergie/df7d0ee046e385080f3f to your computer and use it in GitHub Desktop.
Extract inline FBP graphs to files
fs = require 'fs'
jsdom = require 'jsdom'
writeGraph = (id, content) ->
console.log id
content = content.replace /\&gt\;/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