Skip to content

Commit

Permalink
Simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
tristen committed Jan 3, 2025
1 parent ad47546 commit b3e2a52
Showing 1 changed file with 8 additions and 13 deletions.
21 changes: 8 additions & 13 deletions scripts/utils.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
const { promises: fs } = require('fs');

const { readdir, readFile } = require('node:fs/promises');
const { readdir, readFile, writeFile, mkdir } = require('node:fs/promises');
const path = require('path');
const pify = require('pify');
const xml2js = require('xml2js');
const mkdirp = dir => fs.mkdir(dir, { recursive: true });

const builder = new xml2js.Builder({
rootName: 'svg',
Expand Down Expand Up @@ -36,15 +33,13 @@ async function gatherIcons(iconPath) {
});
}

function write(cleanedSvgs, iconPath) {
const pWrite = pify(fs.writeFile);
return pify(mkdirp)(iconPath).then(
Promise.all(
cleanedSvgs.map(svgObj => {
const svg = builder.buildObject(svgObj);
return pWrite(path.join(iconPath, `${svgObj.$.id}.svg`), svg, 'utf8');
})
)
async function write(cleanedSvgs, iconPath) {
await mkdir(iconPath, { recursive: true });
return Promise.all(
cleanedSvgs.map(svgObj => {
const svg = builder.buildObject(svgObj);
return writeFile(path.join(iconPath, `${svgObj.$.id}.svg`), svg, 'utf8');
})
);
}

Expand Down

0 comments on commit b3e2a52

Please # to comment.