aeirola / react-native-svg-app-icon

Generate all app icons for you React Native apps from a single SVG file

Home Page:https://www.npmjs.com/package/react-native-svg-app-icon

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Not generating icons from day old input files

Sephaq opened this issue · comments

I have a situation where the I added 2 files (background and foreground) svgs to my icon folder, and try to run the module to generate my icons, but no files are created, and I get no useful information.

I've checked the code and this came up:

async function* genaratePng(fileInput, output) {
  if (!(await hasChanged(fileInput, output))) {
    return;
  }
  
  ...
  
  async function hasChanged(input, output) {
  let outputStat;

  try {
    outputStat = await fse.stat(output.filePath);
  } catch {
    return true;
  }

  if (input.lastModified > outputStat.mtimeMs) {
    return true;
  } else {
    return false;
  }
}

And this is leading to my input not being newer than my output, (were using the module to automatically populate the icons by build) and the base foreground file created won't change that often, leading its modifiedAt to always be older.
It would be great to add a force option so that we disregarding the comparison and force it to generate the files regardless.

A workaround right now is to execute touch <filePath> as this. will update the file modifiedAt, and make the check return true

Hmm, not sure I completely understand the situation that caused the output files to be newer than the input files. Did you change the input files without modifying them? Or did some other tool update the output files so that they got newer modified timestamps?

A --force option could be a good solution. Or a clean command. Would just want to better understand the issue we are solving.

We have 3 different environments, 1 icon for each, prod, stage, dev.
And they are on a S3 bucket, so our CI gets the icon.svg corresponding to the environment, then it runs the, yarn react-native-svg-app-icon command to create icon files and populate them.
However since the app icon we have already is newer than the svg we have on the bucket it never gets updated.
I understand there is multiple solutions for this, but i just think a --force on the check for modified date would solve some issues.

Ah, yeah. That is a really valid use case. Hadn't thought of using the tool that way. Definitely not nice for the user to have to worry about how the tool decides when the old images can be reused, but wouldn't hurt to provide manual overrides for that anyways.

One other solution would be to replace the timestamp based comparison with something hash based. But then the issue becomes where to store the source image hashes for the generated files. On iOS there would be the Contents.json file which could be extended, but for Android something custom would probably be required. On the other hand this wouldn't really fix issues where some other tool would write to the images for whatever reason.

For now a --force flag is probably a best option. I'll see if I can get something together over the weekend.

@Sephaq I created a PR adding the --force feature at #64. I'd highly appreciate if you could test it out in your workflow to make sure it solves the issues you were having.

Also added support for providing the configuration options and CLI arguments. Not sure if useful in your situation, but I think it made sense to have all options in both places when we anyways wanted the force option to be on the CLI.

Interpreting the 👍 as a confirmation that the solution works well for you. I'll merge the PR and release a new version soon.

This is now released in version 0.5.0 🚀