forked from mui/material-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
1 parent
8c5d095
commit 4d213bf
Showing
3 changed files
with
868 additions
and
0 deletions.
There are no files selected for viewing
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
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
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('')); |
Oops, something went wrong.