Skip to content

Commit

Permalink
adding icons.js file
Browse files Browse the repository at this point in the history
  • Loading branch information
DhairyaMajmudar committed Jul 3, 2024
1 parent dd9fb27 commit 61e5633
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 0 deletions.
29 changes: 29 additions & 0 deletions icons.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
const {readFileSync, writeFileSync} = require('fs');
const {sync: glob} = require('glob');
const {Logger, LogLevel, colorEmojiConfig} = require('plop-logger');

Logger.config = colorEmojiConfig;
const logger = Logger.getLogger('icons');
logger.level = LogLevel.All;

let svgFiles = `src/icons/*.svg`;
logger.info('SVG aggregation of', svgFiles);

const data = glob(svgFiles)
.map(file => {
const parts = file.split('/');
const id = parts[parts.length - 1].split('.')[0];
logger.debug('handle', id);
return readFileSync(file, 'utf8')
.replace(`<svg xmlns="http://www.w3.org/2000/svg"`, `\t<symbol id="${id}"`)
.replace(`</svg>`, `\t</symbol>`);
}
);

const svg = `<svg xmlns="http://www.w3.org/2000/svg" width="0" height="0" class="visually-hidden">
${data.join('\n')}
</svg>`;

const file = 'static/icons.svg';
logger.info('Generate', file);
writeFileSync(file, svg, {flag: 'w'});
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"scripts": {
"watch:style": "node-sass src/styles/theme.scss -o static --watch",
"start": "run-p watch:*",
"build:icons": "node icons.js",
"build:style": "node-sass src/styles/theme.scss -o static; postcss static/theme.css --replace",
"build": "run-p build:*"
},
Expand Down
28 changes: 28 additions & 0 deletions static/icons.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 61e5633

Please sign in to comment.