Skip to content

Commit

Permalink
Added index generator for SVG icons
Browse files Browse the repository at this point in the history
src/svg-icons/index-generator.js is a naive implementation to generate an index.js file for SVG icons that uses synchronous calls to fs (nodejs API).

index-generator.js can be run with node using "node index-generator.js" to generate the index.js file (good idea to delete old index.js first).
  • Loading branch information
shaurya947 committed Oct 21, 2015
1 parent 8c5d095 commit 4d213bf
Show file tree
Hide file tree
Showing 3 changed files with 868 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
"react-hot-loader": "^1.2.8",
"react-router": "^1.0.0-rc1",
"react-tap-event-plugin": "^0.2.0",
"recursive-readdir-sync": "^1.0.6",
"rimraf": "^2.4.3",
"sinon": "^1.15.4",
"sinon-chai": "^2.8.0",
Expand Down
40 changes: 40 additions & 0 deletions src/svg-icons/index-generator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
const fs = require('fs');
const rrs = require('recursive-readdir-sync');

var outArray = [];
outArray.push('module.exports = {\n');

rrs('./').forEach(function(file) {
if(file !== 'index-generator.js' && file !== 'index.js')
{
var fileLines = fs.readFileSync(file, 'utf8').split('\n');
var index = 0, found = false;

while(found === false && index < fileLines.length)
{
if(fileLines[index].indexOf('module.exports') > -1)
{
var moduleName = fileLines[index].split('=')[1].replace(';','').trim();

outArray.push('\t');
outArray.push(moduleName);
outArray.push(': require(\'./');
outArray.push(file.substring(0, file.length - 4));
outArray.push('\'),\n');

found = true;
}

else
{
index++;
}
}
}
});

outArray.push('\n};')

// console.log(outArray.join(''));

fs.writeFileSync('index.js', outArray.join(''));
Loading

0 comments on commit 4d213bf

Please sign in to comment.