Reuse svg getter package template parts (#7457)

* Reuse svg getter package template parts
This commit is contained in:
Álvaro Mondéjar 2022-05-27 15:09:33 +02:00 committed by GitHub
parent 986589c34c
commit e0a4e765ad
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 3 deletions

View file

@ -106,18 +106,24 @@ const build = async () => {
}),
);
// constants used in templates to reduce package size
const constantsString = `const a='<svg role="img" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><title>',b='</title><path d="',c='"/></svg>';`;
// write our generic index.js
const rawIndexJs = util.format(
indexTemplate,
constantsString,
buildIcons.map(iconToKeyValue).join(','),
);
await writeJs(indexFile, rawIndexJs);
// write our file containing the exports of all icons in CommonJS ...
const rawIconsJs = `module.exports={${iconsBarrelJs.join('')}};`;
const rawIconsJs = `${constantsString}module.exports={${iconsBarrelJs.join(
'',
)}};`;
await writeJs(iconsJsFile, rawIconsJs);
// and ESM
const rawIconsMjs = iconsBarrelMjs.join('');
const rawIconsMjs = constantsString + iconsBarrelMjs.join('');
await writeJs(iconsMjsFile, rawIconsMjs);
// and create a type declaration file
const rawIconsDts = `import {SimpleIcon} from ".";type I = SimpleIcon;${iconsBarrelDts.join(

View file

@ -2,7 +2,7 @@
title: '%s',
slug: '%s',
get svg() {
return '<svg role="img" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><title>%s</title><path d="' + this.path + '"/></svg>';
return a + '%s' + b + this.path + c;
},
path: '%s',
source: '%s',

View file

@ -1,5 +1,7 @@
console.warn('Deprecation warning: The `simple-icons` entrypoint will be removed in the next major. Please switch to using `import * as icons from "simple-icons/icons"` if you need an object with all the icons.')
%s
var icons = {%s};
Object.defineProperty(icons, "Get", {