Skip to content

Switch xml2json to xml2js in tooling #1381

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

Merged
merged 3 commits into from
May 16, 2018
Merged
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
111 changes: 30 additions & 81 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@
"webpack": "^3.4.1",
"webpack-dev-middleware": "^1.12.0",
"webpack-hot-middleware": "^2.18.2",
"xml2json": "^0.11.0"
"xml2js": "^0.4.19"
},
"components": [
{
Expand Down
68 changes: 41 additions & 27 deletions scripts/inline-icons.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import async from 'async';
import fs from 'fs-extra';
import path from 'path';
import parser from 'xml2json';
import xml2js from 'xml2js';
import omit from 'lodash.omit';

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

const parseXml = (string, done) => {
xml2js.parseString(
string,
{
emptyTag: {},
explicitArray: false,
mergeAttrs: true,
},
done
);
};

const inlineIcons = (spriteType, done) => {
const inputPath = path.join(
__dirname,
Expand All @@ -35,32 +47,34 @@ const inlineIcons = (spriteType, done) => {
"let icons = {}; if ('__EXCLUDE_SLDS_ICONS__' === '__INCLUDE_SLDS_ICONS__') { icons = {",
];

const sprite = JSON.parse(parser.toJson(text));

let viewBox;
async.each(
sprite.svg.symbol,
(symbol, iconDone) => {
let data = omit(symbol, ['id']);
const iconName = symbol.id.toLowerCase();

const icon = [license, `export default ${JSON.stringify(data)};`, ''];

outputFile(`${spriteType}/${iconName}`, icon, iconDone);

if (!viewBox) viewBox = data.viewBox;
data = omit(data, ['viewBox']);
index.push(`${iconName}:${JSON.stringify(data)},`);
},
(err) => {
if (err) console.error(err);
}
);

index.push(`viewBox:'${viewBox}'`);
index.push('}; } export default icons;');
index.push('');
outputFile(`${spriteType}/index`, index, done);
parseXml(text, (error, sprite) => {
if (error) throw error;

let viewBox;
async.each(
sprite.svg.symbol,
(symbol, iconDone) => {
let data = omit(symbol, ['id']);
const iconName = symbol.id.toLowerCase();

const icon = [license, `export default ${JSON.stringify(data)};`, ''];

outputFile(`${spriteType}/${iconName}`, icon, iconDone);

if (!viewBox) viewBox = data.viewBox;
data = omit(data, ['viewBox']);
index.push(`${iconName}:${JSON.stringify(data)},`);
},
(err) => {
if (err) console.error(err);
}
);

index.push(`viewBox:'${viewBox}'`);
index.push('}; } export default icons;');
index.push('');
outputFile(`${spriteType}/index`, index, done);
});
};

async.each(
Expand Down