From c04b05f587835d8c0707041e089ab8d29d92db84 Mon Sep 17 00:00:00 2001 From: WolverinDEV Date: Mon, 10 Aug 2020 14:52:50 +0200 Subject: [PATCH] Fixed bug with some special svg icons --- demo/app/test.d.ts | 5 +++-- demo/sprites/player_off.svg | 24 ++++++++++++++++++++++++ package.json | 2 +- plugin/generator.ts | 9 +++++++-- 4 files changed, 35 insertions(+), 5 deletions(-) create mode 100644 demo/sprites/player_off.svg diff --git a/demo/app/test.d.ts b/demo/app/test.d.ts index aef64d9..7540a4c 100644 --- a/demo/app/test.d.ts +++ b/demo/app/test.d.ts @@ -3,12 +3,13 @@ * * This file has been auto generated by the svg-sprite generator. * Sprite source directory: D:\git\web\webpack-svg-sprite\demo\sprites - * Sprite count: 20 + * Sprite count: 21 */ declare module "svg-sprites/test" { - export type TestIconClasses = "client-about" | "client-activate_microphone" | "client-add" | "client-add_foe" | "client-add_folder" | "client-add_friend" | "client-addon-collection" | "client-addon" | "client-apply" | "client-arrow_down" | "client-arrow_left" | "client-arrow_right" | "client-arrow_up" | "client-away" | "client-ban_client" | "client-ban_list" | "client-bookmark_add" | "client-bookmark_add_folder" | "client-bookmark_duplicate" | "client-w2g"; + export type TestIconClasses = "client-_player_commander_on" | "client-about" | "client-activate_microphone" | "client-add" | "client-add_foe" | "client-add_folder" | "client-add_friend" | "client-addon-collection" | "client-addon" | "client-apply" | "client-arrow_down" | "client-arrow_left" | "client-arrow_right" | "client-arrow_up" | "client-away" | "client-ban_client" | "client-ban_list" | "client-bookmark_add" | "client-bookmark_add_folder" | "client-bookmark_duplicate" | "client-w2g"; export enum TestIcons { + PlayerCommanderOn = "client-_player_commander_on", About = "client-about", ActivateMicrophone = "client-activate_microphone", Add = "client-add", diff --git a/demo/sprites/player_off.svg b/demo/sprites/player_off.svg new file mode 100644 index 0000000..6b02df4 --- /dev/null +++ b/demo/sprites/player_off.svg @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/package.json b/package.json index 03ebae5..261bdb0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "webpack-svg-sprite-generator", - "version": "1.0.13", + "version": "1.0.14", "description": "", "main": "plugin.js", "types": "ts/index.d.ts", diff --git a/plugin/generator.ts b/plugin/generator.ts index e6cac17..98afac2 100644 --- a/plugin/generator.ts +++ b/plugin/generator.ts @@ -21,8 +21,8 @@ function jsNode2xml(indent: string, data: XMLParser.Node) { const tagOpen = `<${data.name}${generateAttributes(data.attributes)}>`; const tagClose = ``; - let content = data.children.length ? data.children.map(e => jsNode2xml(indent + " ", e)).join("\n") : data.content; - if(content?.length !== 0) + let content = data.children.length ? data.children.map(e => jsNode2xml(indent + " ", e)).join("\n") : data.content || ""; + if(content.length !== 0) content = "\n" + content + "\n" + indent; return ( @@ -278,6 +278,11 @@ export async function generateSprite(files: string[]) : Promise svg.data = XMLParser((await fs.readFile(file)).toString()); svg.name = path.basename(file, path.extname(file)); + if(!svg.data.root) { + console.warn("Missing svg root element for %s. Skipping file.", file); + continue; + } + if(svg.data.root.name !== "svg") { console.warn("invalid svg root attribute for " + file + " (" + svg.data.root.name + ")"); continue;