Created
February 7, 2017 09:02
-
-
Save allmarkedup/235d409f83493f1141f2bfd9d720fe99 to your computer and use it in GitHub Desktop.
Export JSON map of Fractal @handle references to filesystem paths
This file contains hidden or 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
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