Skip to content

Instantly share code, notes, and snippets.

@allmarkedup
Created February 7, 2017 09:02
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save allmarkedup/235d409f83493f1141f2bfd9d720fe99 to your computer and use it in GitHub Desktop.
Save allmarkedup/235d409f83493f1141f2bfd9d720fe99 to your computer and use it in GitHub Desktop.
Export JSON map of Fractal @handle references to filesystem paths
const path = require('path');
const fs = require('fs');
const fractal = module.exports = require('@frctl/fractal').create();
function exportPaths() {
const map = {};
for (let item of fractal.components.flatten()) {
map[`@${item.handle}`] = path.relative(process.cwd(), item.viewPath);
}
fs.writeFileSync('components-map.json', JSON.stringify(map, null, 2), 'utf8');
}
fractal.components.on('updated', function(){
exportPaths();
});
fractal.cli.command('pathmap', function(opts, done){
exportPaths();
done();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment