From fdc707bf81fd7240481c39050b1ef9b0063e27ec Mon Sep 17 00:00:00 2001 From: LitoMore Date: Sat, 24 Sep 2022 02:44:28 +0800 Subject: [PATCH] Build icons in order (#7852) --- scripts/build/package.js | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/scripts/build/package.js b/scripts/build/package.js index 0088eac93..bfd4ece37 100644 --- a/scripts/build/package.js +++ b/scripts/build/package.js @@ -81,31 +81,29 @@ const build = async () => { }; // 'main' - const iconsBarrelMjs = []; - const iconsBarrelJs = []; - const iconsBarrelDts = []; - const buildIcons = []; - - await Promise.all( + const buildIcons = await Promise.all( icons.map(async (icon) => { const filename = getIconSlug(icon); const svgFilepath = path.resolve(iconsDir, `${filename}.svg`); icon.svg = (await fs.readFile(svgFilepath, UTF8)).replace(/\r?\n/, ''); icon.path = svgToPath(icon.svg); icon.slug = filename; - buildIcons.push(icon); - const iconObject = iconToObject(icon); - const iconExportName = slugToVariableName(icon.slug); - - // add object to the barrel file - iconsBarrelJs.push(`${iconExportName}:${iconObject},`); - iconsBarrelMjs.push(`export const ${iconExportName}=${iconObject}`); - iconsBarrelDts.push(`export const ${iconExportName}:I;`); + return { icon, iconObject, iconExportName }; }), ); + const iconsBarrelDts = []; + const iconsBarrelJs = []; + const iconsBarrelMjs = []; + + buildIcons.forEach(({ icon, iconObject, iconExportName }) => { + iconsBarrelDts.push(`export const ${iconExportName}:I;`); + iconsBarrelJs.push(`${iconExportName}:${iconObject},`); + iconsBarrelMjs.push(`export const ${iconExportName}=${iconObject}`); + }); + // constants used in templates to reduce package size const constantsString = `const a='',b='';`; @@ -113,7 +111,7 @@ const build = async () => { const rawIndexJs = util.format( indexTemplate, constantsString, - buildIcons.map(iconToKeyValue).join(','), + buildIcons.map(({ icon }) => iconToKeyValue(icon)).join(','), ); await writeJs(indexFile, rawIndexJs);