Open vcrash opened 3 years ago
Can you share file structure here?
For example: assets/logo.png assets/profile/logo.png
I see. Please share exact configuration file as well.
# 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 ]
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:
Create a separate group for sub dir.
groups:
- path: assets
class_name: Assets
- path: assets/profile
class_name: ProfileAssets
Rename file so it is no longer the same.
Let me know if this is helpful. Thanks.
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.
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. ☺️
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.
@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.
@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.
When assets with same file name are containing in different subdirectories reference will be generated only for a single asset.
Expecting references are generated for each asset with specified paths.