forked from MapComplete/MapComplete
		
	Refactoring: remove last of old SVG-bundling
This commit is contained in:
		
							parent
							
								
									195e9b140f
								
							
						
					
					
						commit
						3bb73425e3
					
				
					 8 changed files with 38 additions and 153 deletions
				
			
		|  | @ -1,118 +1,9 @@ | |||
| import * as fs from "fs" | ||||
| import Script from "./Script" | ||||
| 
 | ||||
| function genImages(dryrun = false) { | ||||
|     console.log("Generating images") | ||||
|     // These images are not referenced via 'Svg.ts' anymore and can be ignored
 | ||||
|     const blacklist: string[] = [ | ||||
|         "add", | ||||
|         "addSmall", | ||||
|         "back", | ||||
|         "circle", | ||||
|         "blocked", | ||||
|         "brick_wall", | ||||
|         "brick_wall_raw", | ||||
|         "brick_wall_round", | ||||
|         "brick_wall_square", | ||||
|         "bug", | ||||
|         "center", | ||||
|         "checkmark", | ||||
|         "clock", | ||||
|         "close", | ||||
|         "community", | ||||
|         "compass", | ||||
|         "compass_arrow", | ||||
|         "confirm", | ||||
|         "copyright", | ||||
|         "cross", | ||||
|         "cross_bottom_right", | ||||
|         "crosshair", | ||||
|         "crosshair_locked", | ||||
|         "crosshair-locked", | ||||
|         "delete_not_allowed", | ||||
|         "direction_gradient", | ||||
|         "direction_stroke", | ||||
|         "duplicate", | ||||
|         "elevator", | ||||
|         "elevator_wheelchair", | ||||
|         "envelope", | ||||
|         "eye", | ||||
|         "filter", | ||||
|         "filter_disable", | ||||
|         "floppy", | ||||
|         "gear", | ||||
|         "gender_bi", | ||||
|         "gender_inter", | ||||
|         "gender_female", | ||||
|         "gender_male", | ||||
|         "gender_trans", | ||||
|         "gender_queer", | ||||
|         "generic_map", | ||||
|         "gps_arrow", | ||||
|         "hand", | ||||
|         "help", | ||||
|         "home", | ||||
|         "length_crosshair", | ||||
|         "length-crosshair", | ||||
|         "liberapay", | ||||
|         "location", | ||||
|         "location_empty", | ||||
|         "location_locked", | ||||
|         "location_refused", | ||||
|         "location-refused", | ||||
|         "location_unlocked", | ||||
|         "logo", | ||||
|         "logout", | ||||
|         "mapcomplete_logo", | ||||
|         "mapillary", | ||||
|         "mapillary_black", | ||||
|         "mastodon", | ||||
|         "min", | ||||
|         "move", | ||||
|         "move-arrows", | ||||
|         "move_confirm", | ||||
|         "move_not_allowed", | ||||
|         "not_found", | ||||
|         "osm_logo_us", | ||||
|         "osm-logo-us", | ||||
|         "party", | ||||
|         "pencil", | ||||
|         "person", | ||||
|         "pin", | ||||
|         "plantnet_logo", | ||||
|         "plus", | ||||
|         "reload", | ||||
|         "resolved", | ||||
|         "ring", | ||||
|         "robot", | ||||
|         "scissors", | ||||
|         "search", | ||||
|         "search_disable", | ||||
|         "share", | ||||
|         "SocialImageForeground", | ||||
|         "speech_bubble", | ||||
|         "speech_bubble_black_outline", | ||||
|         "square", | ||||
|         "square_rounded", | ||||
|         "star", | ||||
|         "star_half", | ||||
|         "star_outline", | ||||
|         "teardrop", | ||||
|         "teardrop_with_hole_green", | ||||
|         "statistics", | ||||
|         "translate", | ||||
|         "triangle", | ||||
|         "up", | ||||
|         "Upload", | ||||
|         "wikidata", | ||||
|         "wikimedia-commons-white", | ||||
|         "wikimedia_commons_white", | ||||
|         "wikipedia", | ||||
|         "github", | ||||
|     ].map((s) => s.toLowerCase()) | ||||
|     const dir = fs.readdirSync("./assets/svg") | ||||
| 
 | ||||
|     let module = | ||||
|         'import Img from "./UI/Base/Img";\n\n/* @deprecated */\nexport default class Svg {\n\n\n' | ||||
|     for (const path of dir) { | ||||
|         if (path.endsWith("license_info.json")) { | ||||
|             continue | ||||
|  | @ -133,7 +24,7 @@ function genImages(dryrun = false) { | |||
|             .replace(/\n/g, " ") | ||||
|             .replace(/\r/g, "") | ||||
|             .replace(/\\/g, "\\") | ||||
|             .replace(/"/g, '\\"') | ||||
|             .replace(/"/g, "\\\"") | ||||
|             .replaceAll(" ", " ") | ||||
| 
 | ||||
|         let hasNonAsciiChars = Array.from(svg) | ||||
|  | @ -147,35 +38,29 @@ function genImages(dryrun = false) { | |||
| 
 | ||||
|         const nameUC = name.toUpperCase().at(0) + name.substring(1) | ||||
|         const svelteCode = | ||||
|             '<script>\nexport let color = "#000000"\n</script>\n' + | ||||
|             "<script>\nexport let color = \"#000000\"\n</script>\n" + | ||||
|             svg | ||||
|                 .replace( | ||||
|                     "<svg ", | ||||
|                     "<svg {...$$$$restProps} on:click on:mouseover on:mouseenter on:mouseleave on:keydown " | ||||
|                     "<svg {...$$$$restProps} on:click on:mouseover on:mouseenter on:mouseleave on:keydown ", | ||||
|                 ) | ||||
|                 .replace(/\\"/g, '"') | ||||
|                 .replace(/\\"/g, "\"") | ||||
|                 .replace(/(rgb\(0%,0%,0%\)|#000000|#000)/g, "{color}") | ||||
|         fs.writeFileSync("./src/assets/svg/" + nameUC + ".svelte", svelteCode, "utf8") | ||||
| 
 | ||||
|         if (blacklist.some((item) => path.toLowerCase().endsWith(item + ".svg"))) { | ||||
|             continue | ||||
|         } | ||||
|         if (dryrun) { | ||||
|             svg = "<omitting svg - dryrun>" | ||||
|         } | ||||
| 
 | ||||
|         let rawName = name | ||||
| 
 | ||||
|         module += `    public static ${name} = "${svg}"\n` | ||||
|         if (!dryrun) { | ||||
|             module += `    public static ${name}_svg() { return new Img(Svg.${rawName}, true);}\n` | ||||
|         } else { | ||||
|             module += `    public static ${name}_svg() { return new Img("", true);}\n` | ||||
|         } | ||||
|     } | ||||
|     module += "}\n" | ||||
|     fs.writeFileSync("src/Svg.ts", module) | ||||
|     console.log("Done") | ||||
| } | ||||
| 
 | ||||
| genImages() | ||||
| 
 | ||||
| class GenerateIncludedImages extends Script { | ||||
|     constructor() { | ||||
|         super("Converts all images from assets/svg into svelte-classes.") | ||||
|     } | ||||
| 
 | ||||
|     async main(args: string[]): Promise<void> { | ||||
|         genImages() | ||||
| 
 | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| new GenerateIncludedImages().run() | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue