Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(36): added svg to icon library + added function to create icons … #37

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 31 additions & 3 deletions build/generate_js.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable max-len */
/* eslint-disable no-await-in-loop */
/* eslint-disable no-restricted-globals */
/* eslint-disable no-console */
Expand All @@ -9,8 +8,10 @@ const path = require('path');

const svgSourceFolder = './svg/';
const jsTargetFolder = './generated_js/';
const fontTargetFolder = './generated_fonts/';

if (!fsr.existsSync(jsTargetFolder)) fsr.mkdirSync(jsTargetFolder, { recursive: true });
if (!fsr.existsSync(fontTargetFolder)) fsr.mkdirSync(fontTargetFolder, { recursive: true });

// #######################################
console.info(`removing files from target directory ${jsTargetFolder}`);
Expand All @@ -23,7 +24,7 @@ fs.readdir(jsTargetFolder, (err, files) => {
});
});
});
console.info('deletion successfull\n');
console.info('deletion successful\n');

// #######################################
console.info('start reading svg files and creating js files');
Expand Down Expand Up @@ -70,4 +71,31 @@ fs.readdir(svgSourceFolder).then(async (files) => {
console.error(err3);
}
});
});

// Dynamically import SVGIcons2SVGFontStream
const { SVGIcons2SVGFontStream } = await import('svgicons2svgfont');

// Create the icon font
const fontStream = new SVGIcons2SVGFontStream({
fontName: 'iconfont',
});

fontStream.pipe(fsr.createWriteStream(path.join(fontTargetFolder, 'iconfont.svg')))
.on('finish', () => {
console.log('Font successfully created!');
})
.on('error', (err) => {
console.error(err);
});

files.forEach((file) => {
const glyph = fsr.createReadStream(path.join(svgSourceFolder, file));
glyph.metadata = {
unicode: [String.fromCharCode(0xe000 + addedIcons.indexOf(file.replace('.svg', '')))],
name: file.replace('.svg', ''),
};
fontStream.write(glyph);
});

fontStream.end();
});
Loading
Loading