Skip to content
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

Add ability to download resulting config #383

Open
wants to merge 27 commits into
base: main
Choose a base branch
from

Conversation

epodivilov
Copy link

@epodivilov epodivilov commented Apr 18, 2022

Hi.

I and others (according to requests #11, #50 and #184), miss the possibility to apply SVGO configuration to multiple files. As I understood it, batch processing support is not expected, that's why I suggest an intermediate solution - a possibility to download the resulting config and then apply it using the cli interface of SVGO.

Unfortunately, the latest versions of SVGO don't support sending the config as text, that's why you'll have to create the config file as JS.

# Example of usage
npx svgo --config="./path/to/svgo.config.js" -f ./input -o ./output

Fixes #11

@netlify
Copy link

netlify bot commented Apr 18, 2022

Deploy Preview for svgomg ready!

Name Link
🔨 Latest commit d11c8c2
🔍 Latest deploy log https://app.netlify.com/sites/svgomg/deploys/664b10d155d4410008168f19
😎 Deploy Preview https://deploy-preview-383--svgomg.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@epodivilov epodivilov force-pushed the settings branch 2 times, most recently from c128425 to 441e414 Compare April 21, 2022 11:24
const floatPrecision = Number(settings.floatPrecision);
const plugins = [];

for (const [name, active] of Object.entries(settings.plugins)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most of this block seems to be duplicated in svgo-worker. Doesn't seem good from a maintenance perspective.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I decided to copy the code first. I can rework it a bit and take out the repeating code.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that would help, yeah. Because this kind of duplication can be bad in the future.

Maybe we should just have a function to return the config with plugins somewhere in a common place.

@jakearchibald any suggestions?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved the code for getting plugins into a separate utility

@@ -0,0 +1,15 @@
export function downloadSvgoConfig(filename, text) {
const element = document.createElement('a');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering, isn't there a cleaner way without adding the extra a tag?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rewrote the code so that the link to the configuration was always on the page and was updated when the configuration was changed

@XhmikosR
Copy link
Collaborator

XhmikosR commented Nov 3, 2022

hey, there. Thanks for continuing your work on this.

Can you please make sure there are no lint issues and the the export actually works?

src/js/utils/download.js Outdated Show resolved Hide resolved
@XhmikosR
Copy link
Collaborator

XhmikosR commented Nov 3, 2022

This doesn't seem to work, no lint errors, no console errors but the config is not downloaded, at lean of Firefox that I tried.

@epodivilov
Copy link
Author

This doesn't seem to work, no lint errors, no console errors but the config is not downloaded, at lean of Firefox that I tried.

What version of Firefox do you have?

I have tested with the following versions on my system (MacOS Ventura)

  • Chrome 107.0.5304.87
  • Firefox 106.0.4
  • Safari 16.1

I tested the export button on localhost and on the netlify build

@XhmikosR
Copy link
Collaborator

XhmikosR commented Nov 4, 2022

Something weird is happening... If I load the page and don't make any change, clicking on the export button does not trigger the download. If I change a setting, then it works.

@XhmikosR
Copy link
Collaborator

XhmikosR commented Nov 4, 2022

Maybe you are missing a click event?

@epodivilov
Copy link
Author

epodivilov commented Nov 4, 2022

Maybe you are missing a click event?

But it's a link, it doesn't need click event handler.
Maybe you have an old variant with button cached?

UPDATE: I think I've found a case where the problem might arise

@XhmikosR
Copy link
Collaborator

XhmikosR commented Nov 4, 2022

Yup, that was it.

Now, the only issue I see is ripple not firing when clicking the button.

src/js/utils/settings.js Outdated Show resolved Hide resolved
@XhmikosR
Copy link
Collaborator

XhmikosR commented Nov 5, 2022

This looks pretty good now! Waiting for @jakearchibald to review too.

@KnifeFed
Copy link

No progress on the review? I guess https://deploy-preview-383--svgomg.netlify.app works for now though 🙂

@AdrianoCahete
Copy link

JFYI: Using the preview build, I was able to export and use the config, but the property cleanupIDs returns an error:

Error: Unknown builtin plugin "cleanupIDs" specified.
    at resolvePluginConfig (...)

Mostly because cleanupIDs was renamed to cleanupIds in v3, as referenced in changelog.

Manually renaming on config file works.

@epodivilov epodivilov force-pushed the settings branch 2 times, most recently from 0b9e437 to be87fcf Compare May 20, 2024 08:43
@epodivilov
Copy link
Author

cleanupIds

Thanks for the feedback. Checked, there is indeed a problem. It is true that for SVGOMG to support the new plugin name you need to update the svgo package.

I updated my PR and added the necessary edits

@epodivilov epodivilov requested a review from XhmikosR May 20, 2024 09:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Show cmd line equivalent
4 participants