public static void main(final String[] args) throws IOException {

        final Path coreSharedPath = getCoreSharedPath();
        final Path appPath = getAppPath(coreSharedPath);
        final Path sourceBasePath = getImagesSourceBasePath(appPath);
        final Path destBasePath = getImagesDestBasePath(appPath);

        final Map<Path, SvgFile> relPathToSvgObjMap = new HashMap<>();
        final Set<String> enumFieldNameSet = new HashSet<>();

        // First transform the raw images.
        deleteDirectory(destBasePath);
        try (final Stream<Path> stream = Files.walk(sourceBasePath)) {
            stream.forEach(sourceFile -> {
                final Path relSourcePath = sourceBasePath.relativize(sourceFile);
                try {
                    String fileName = sourceFile.getFileName().toString();
                    if (fileName.toLowerCase(Locale.ROOT).endsWith(".svg")) {

                        final Path output = destBasePath.resolve(relSourcePath);
                        Files.createDirectories(output.getParent());

                        String xml = Files.readString(sourceFile, StandardCharsets.UTF_8);
                        for (final Entry<String, String> entry : COLOUR_MAPPINGS.entrySet()) {
                            final String hex = entry.getKey();
                            final String cssColourVariable = entry.getValue();
                            xml = xml.replaceAll(
                                    "(?i)" + Pattern.quote(hex),
                                    cssColourVariable);
                        }
                        // Remove the XML declaration
                        xml = XML_DECLARATION_PATTERN.matcher(xml).replaceAll("");
                        xml = XML_INDENT_PATTERN.matcher(xml).replaceAll("><");
                        xml = EXCESS_WHITESPACE_PATTERN.matcher(xml).replaceAll(" ");
                        // TODO: 06/07/2023 Would be nice to clean all the inkscape clutter from the svg
                        //  but the regex needs more work
//                        xml = INKSCAPE_CLEAN_PATTERN.matcher(xml).replaceAll("");

                        final String enumFieldName = pathToEnumFieldName(relSourcePath);
                        final String className = "svg-image__"
                                + enumFieldName.toLowerCase().replace('_', '-');
                        final boolean isNewName = enumFieldNameSet.add(enumFieldName);
                        if (!isNewName) {
                            System.err.println("Enum field name clash: " + enumFieldName);
                        }

                        final SvgFile svgFile = new SvgFile(
                                relSourcePath,
                                enumFieldName,
                                className,
                                xml);

                        if (Files.exists(output)) {
                            System.err.println("File exists: " + output);
                        } else {
//                            System.out.println(relSourcePath + " => " + output);
                            Files.writeString(output, xml);
                            relPathToSvgObjMap.put(relSourcePath, svgFile);
                        }
                    } else if (fileName.toLowerCase(Locale.ROOT).endsWith(".png")) {
                        final Path output = destBasePath.resolve(relSourcePath);
                        Files.createDirectories(output.getParent());

                        if (Files.exists(output)) {
                            System.err.println("File exists: " + output);
                        } else {
                            Files.copy(sourceFile, output);
                        }
                    }
                } catch (final IOException e) {
                    throw new UncheckedIOException(e);
                }
            });

        } catch (final IOException e) {
            throw new UncheckedIOException(e);
        }

        // Now build the enum that contains all the XML content for using SVS inline in HTML
        final StringBuilder sb = new StringBuilder()
                .append(ENUM_HEADER);

        relPathToSvgObjMap.entrySet()
                .stream()
                .sorted(Comparator.comparing(entry -> entry.getValue().enumFieldName))
                .forEach(entry -> {
                    final SvgFile svgFile = entry.getValue();
                    sb.append("    ");
                    sb.append(svgFile.enumFieldName);
                    sb.append("(\"");
                    sb.append(svgFile.relPath.toString());
                    sb.append("\", \"");
                    sb.append(svgFile.className);
                    sb.append("\", \"\" +\n");

                    final String[] parts = svgFile.xml.split("\n");
                    for (String part : parts) {
                        if (part.length() == 0) {
                            sb.append("            \"\\n\" +\n");
                        } else {
                            while (part.length() > 0) {
                                int size = Math.min(80, part.length());
                                String line = part.substring(0, size);
                                part = part.substring(size);
                                line = line.replaceAll("\"", "\\\\\"");
                                line = line.replaceAll("\t", " ");
                                sb.append("            \"");
                                sb.append(line);
                                if (part.length() > 0) {
                                    sb.append("\" +\n");
                                }
                            }
                            sb.append("\\n\" +\n");
                        }
                    }
                    sb.append("            \"\"),\n\n");
                });

        sb.replace(sb.length() - 3, sb.length() - 1, ";\n");
        sb.append("    public static final String BASE_CLASS_NAME = \"");
        sb.append(BASE_CLASS_NAME);
        sb.append("\";");
        sb.append(ENUM_FOOTER);

        final Path outPath = coreSharedPath.resolve(ENUM_REL_FILE_PATH);
        try (final OutputStream outputStream = Files.newOutputStream(outPath)) {
            outputStream.write(sb.toString().getBytes(StandardCharsets.UTF_8));
            System.out.println("Written enum file " + outPath.toAbsolutePath());
        } catch (final IOException e) {
            throw new UncheckedIOException(e);
        }

        System.out.println("\nLight mode css variable definitions:");
        COLOUR_MAPPINGS.entrySet()
                .stream()
                .sorted(Entry.comparingByValue())
                .forEach(entry -> {
                    final String hex = entry.getKey();
                    final String variable = entry.getValue()
                            .replace("var(", "")
                            .replace(")", "");
                    if (!variable.equals("currentColor")) {
                        System.out.println("    "
                                           + variable
                                           + ": "
                                           + hex
                                           + ";");
                    }
                });

        SvgImageTools.generateUniqueColoursContactSheet();
        SvgImageTools.generateThemedIconsContactSheet();
    }
@return The CSS class name for the icon.
stroom-core-shared/src/test/java/stroom/svg/shared/GenerateSvgImages.java