parsers icon indicating copy to clipboard operation
parsers copied to clipboard

Opinionated file name casing in svg-to-jsx parser

Open abdavid opened this issue 2 years ago • 1 comments

https://github.com/Specifyapp/parsers/blob/4de22b38f655270467f8ec9ee018341c27e10f00/parsers/svg-to-jsx/svg-to-jsx.parser.ts#L161

Hi, It would be nice if it would be possible to configure what type of casing that should be used (seen in context with the newly added isTsx option).

An alternative workaround is ofcourse using the name-assets-files-by-pattern parser to enforce casing on the filename, but that would also make the isTsx option dedundant.

Here is my asset configuration for reference and if you have any optimizations or suggestions.

{
            name: "Assets",
            path: "packages/core/assets/icons",
            filter: {
                types: ["vector"]
            },
            parsers: [
                {
                    name: "replace-string",
                    options: {
                        keys: ["name"],
                        regex: {
                            pattern: "\\d+",
                        },
                        trim: true
                    }
                },
                {
                    name: "svgo",
                    options: {
                        svgo: {
                            plugins: [
                                {
                                    removeDimensions: true
                                },
                                {
                                    removeAttrs: {
                                        attrs: "*:(fill|stroke)"
                                    }
                                }
                            ]
                        }
                    }
                },
                {
                    name: "pascalcasify",
                    options: {
                        keys: ["name"]
                    }
                },
                { // this part here I would like to omit, but currently need to enforce casing
                    name: "name-assets-files-by-pattern",
                    options: {
                        pattern: "{{name}}.tsx"
                    }
                },
                {
                    name: "svg-to-jsx",
                    options: {
                        prepend: "import React from 'react';",
                        variableFormat: "pascalCase",
                        //filenameFormat: "pascalCase" <-- my initial suggestion
                        wrapper: {
                            "tag": "div",
                            "className": "rds-icon"
                        },
                        formatConfig: {
                            isTsx: true,
                        }
                    }
                }
            ],
        }

-- David

abdavid avatar Mar 07 '22 12:03 abdavid

Hi @abdavid,

Thanks for your suggestion. It's a good idea, we will add this update to our roadmap.

If it's really important for you, feel free to open a PR. I will be happy to review it 🙂

AMoreaux avatar Mar 07 '22 18:03 AMoreaux