Skip to content

Commit 8c85f69

Browse files
Merge pull request #1381 from dougwilson/dougwilson-patch-1
Switch xml2json to xml2js in tooling
2 parents 4cf2751 + 1bfbfa4 commit 8c85f69

File tree

3 files changed

+72
-109
lines changed

3 files changed

+72
-109
lines changed

package-lock.json

Lines changed: 30 additions & 81 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@
204204
"webpack": "^3.4.1",
205205
"webpack-dev-middleware": "^1.12.0",
206206
"webpack-hot-middleware": "^2.18.2",
207-
"xml2json": "^0.11.0"
207+
"xml2js": "^0.4.19"
208208
},
209209
"components": [
210210
{

scripts/inline-icons.js

Lines changed: 41 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import async from 'async';
44
import fs from 'fs-extra';
55
import path from 'path';
6-
import parser from 'xml2json';
6+
import xml2js from 'xml2js';
77
import omit from 'lodash.omit';
88

99
console.log('# Building the inline SVG icons');
@@ -14,6 +14,18 @@ const outputFile = (filename, data, done) => {
1414
fs.outputFile(outputPath, data.join('\n'), done);
1515
};
1616

17+
const parseXml = (string, done) => {
18+
xml2js.parseString(
19+
string,
20+
{
21+
emptyTag: {},
22+
explicitArray: false,
23+
mergeAttrs: true,
24+
},
25+
done
26+
);
27+
};
28+
1729
const inlineIcons = (spriteType, done) => {
1830
const inputPath = path.join(
1931
__dirname,
@@ -35,32 +47,34 @@ const inlineIcons = (spriteType, done) => {
3547
"let icons = {}; if ('__EXCLUDE_SLDS_ICONS__' === '__INCLUDE_SLDS_ICONS__') { icons = {",
3648
];
3749

38-
const sprite = JSON.parse(parser.toJson(text));
39-
40-
let viewBox;
41-
async.each(
42-
sprite.svg.symbol,
43-
(symbol, iconDone) => {
44-
let data = omit(symbol, ['id']);
45-
const iconName = symbol.id.toLowerCase();
46-
47-
const icon = [license, `export default ${JSON.stringify(data)};`, ''];
48-
49-
outputFile(`${spriteType}/${iconName}`, icon, iconDone);
50-
51-
if (!viewBox) viewBox = data.viewBox;
52-
data = omit(data, ['viewBox']);
53-
index.push(`${iconName}:${JSON.stringify(data)},`);
54-
},
55-
(err) => {
56-
if (err) console.error(err);
57-
}
58-
);
59-
60-
index.push(`viewBox:'${viewBox}'`);
61-
index.push('}; } export default icons;');
62-
index.push('');
63-
outputFile(`${spriteType}/index`, index, done);
50+
parseXml(text, (error, sprite) => {
51+
if (error) throw error;
52+
53+
let viewBox;
54+
async.each(
55+
sprite.svg.symbol,
56+
(symbol, iconDone) => {
57+
let data = omit(symbol, ['id']);
58+
const iconName = symbol.id.toLowerCase();
59+
60+
const icon = [license, `export default ${JSON.stringify(data)};`, ''];
61+
62+
outputFile(`${spriteType}/${iconName}`, icon, iconDone);
63+
64+
if (!viewBox) viewBox = data.viewBox;
65+
data = omit(data, ['viewBox']);
66+
index.push(`${iconName}:${JSON.stringify(data)},`);
67+
},
68+
(err) => {
69+
if (err) console.error(err);
70+
}
71+
);
72+
73+
index.push(`viewBox:'${viewBox}'`);
74+
index.push('}; } export default icons;');
75+
index.push('');
76+
outputFile(`${spriteType}/index`, index, done);
77+
});
6478
};
6579

6680
async.each(

0 commit comments

Comments
 (0)