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

References are not generating for assets with same file name. #36

Open
vcrash opened this issue Nov 10, 2021 · 10 comments
Open

References are not generating for assets with same file name. #36

vcrash opened this issue Nov 10, 2021 · 10 comments

Comments

@vcrash
Copy link

vcrash commented Nov 10, 2021

When assets with same file name are containing in different subdirectories reference will be generated only for a single asset.

groups:
  - paths:
      - assets
      - assets/subdir
    class_name: Images
    types: [ .png, .jpg, .jpeg, .webp, .webm, .bmp ]

Expecting references are generated for each asset with specified paths.

@BirjuVachhani
Copy link
Owner

Can you share file structure here?

@vcrash
Copy link
Author

vcrash commented Nov 15, 2021

For example:
assets/logo.png
assets/profile/logo.png

@BirjuVachhani
Copy link
Owner

I see. Please share exact configuration file as well.

@vcrash
Copy link
Author

vcrash commented Nov 18, 2021


# Generated by Spider

# Generates unit tests to verify that the assets exists in assets directory
generate_tests: true

# Use this to remove vcs noise created by the `generated` comments in dart code
no_comments: true

# Exports all the generated file as the one library
export: true

# This allows you to import all the generated references with 1 single import!
use_part_of: true

# Location where all the generated references will be stored
package: resources

groups:
  - paths:
      - assets
      - assets/profile
    class_name: Images
    types: [ .png, .jpg, .jpeg, .webp, .webm, .bmp ]
#  - path: assets/vectors
#    class_name: Svgs
#    package: res
#    types: [ .svg ]

@BirjuVachhani
Copy link
Owner

Because both of the files fall under the same group and we are using file names as dart reference names, it is most likely that it is being overridden because of the same name. While we can add some suffix (like img1 and img2) to the reference name, it is not ideal to do that. It also makes it hard for the user to identify which is which.

You can do 2 things here:

  1. Create a separate group for sub dir.
groups:
  - path: assets
    class_name: Assets
  - path: assets/profile
    class_name: ProfileAssets
  1. Rename file so it is no longer the same.

Let me know if this is helpful. Thanks.

@vcrash
Copy link
Author

vcrash commented Nov 21, 2021

Using separate class names is not always convenient because we need to remember (or check) which class contains which reference. Renaming is an option but probably names conflict should be marked more clear so user always notice it.
May be more preferable option would be adding prefix to the reference name. Better if it would resolve automatically depending on subpath, like logo, profileLogo, etc. And if we still have names conflicts then user should be aware of this too.

@BirjuVachhani
Copy link
Owner

Hmm....this could be tricky though for OS where file system is case sensitive which allows you to store 2 different files with same name and deferred case (e.g. Linux).

I agree to let the user know about this conflict. Perhaps we could add a warning/error in the console output to let the user know why it did not generate certain file reference or why it failed.

I liked the prefix idea. I'll think on it and try to create a prototype. Thanks for this insights. ☺️

@vcrash
Copy link
Author

vcrash commented Nov 23, 2021

Thanks. Perhaps it is better to generate some error marks directly in output files so we can not build a project normally without fixing conflicts. Otherwise console output can be ignored and we get runtime issue.

@BirjuVachhani
Copy link
Owner

@vcrash That would require to add error in the codegen. Interesting! This conflicts with how this package's internals work so it would require special provisions perhaps. Let me give this some thought.

@vcrash
Copy link
Author

vcrash commented Dec 7, 2021

@BirjuVachhani May be we could generate references with type of Error instead of String in a case of name conflict? It would cause an error during types resolving analysis except somebody is using asset path as a dynamic type var. Looks a little bit tricky but may do the job. Just for thoughts.

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

No branches or pull requests

2 participants