Skip to content

Commit

Permalink
Refactor(icons): Create shared filter function for SVG build scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
dlouhak committed Dec 4, 2023
1 parent c583303 commit e170ac5
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
3 changes: 2 additions & 1 deletion packages/icons/scripts/buildConstants.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ const fs = require('fs');
const path = require('path');
// eslint-disable-next-line import/no-extraneous-dependencies
const jsdom = require('jsdom');
const { filterSvgFiles } = require('./shared');

const svgSrcDir = path.resolve(__dirname, `../dist/svg`);
const distFile = path.resolve(__dirname, `../dist/icons.js`);

const buildContants = (srcDir, file) => {
fs.readdir(srcDir, (err, files) => {
const svgs = files.filter((el) => path.extname(el) === '.svg');
const svgs = filterSvgFiles(files);

if (svgs.length > 0) {
const icons = {};
Expand Down
4 changes: 2 additions & 2 deletions packages/icons/scripts/buildSvg.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
const fs = require('fs');
const path = require('path');
const { filterSvgFiles } = require('./shared');

const svgSrcDir = path.resolve(__dirname, `../src/svg`);
const svgDistDir = path.resolve(__dirname, `../dist/svg`);

const normalizeAndCopySvg = (srcDir, distDir) => {
fs.readdir(srcDir, (err, files) => {
if (files?.length > 0) {
const svgs = files.filter((el) => path.extname(el) === '.svg');
const svgs = filterSvgFiles(files);

if (svgs.length > 0) {
let sprite = '<svg xmlns="http://www.w3.org/2000/svg" style="display: none;">\n';
Expand Down
8 changes: 8 additions & 0 deletions packages/icons/scripts/shared.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const path = require('path');

const filterSvgFiles = (fileNames) =>
fileNames.filter((fileName) => path.extname(fileName) === '.svg' && fileName !== 'sprite.svg');

module.exports = {
filterSvgFiles,
};

0 comments on commit e170ac5

Please sign in to comment.