BirjuVachhani / spider

A small dart library to generate Assets dart code from assets folder.
https://spider.birju.dev/
Apache License 2.0
190 stars 20 forks source link

In multi-resolution scenes, the path generated by the image is wrong #12

Closed madroidmaq closed 4 years ago

madroidmaq commented 4 years ago

I am coming again :)

In multi-resolution scenes, Like below:

assets
├── background.jpg    //1.0x
├── 2.0x
│   └── background.jpg  //2.0x
└── 3.0x
    └── background.jpg  //3.0x

Only a 1.0x path should be generated, like

static const String background = 'assets/background.png';

but I have something wrong. Here is some of our environmental information:

spider.ymal

groups:
  - path: assets/images
    class_name: Images
    package: res
  - path: assets/images/2.0x
    class_name: Images
    package: res
  - path: assets/images/3.0x
    class_name: Images
    package: res

auto gen code

class Images {
  static const String dsStore = 'assets/images/3.0x/.DS_Store';
  static const String deviceWatch = 'assets/images/3.0x/device_watch.webp';
  static const String deviceBindError =
      'assets/images/3.0x/device_bind_error.webp';
  static const String deviceBindSuccess =
      'assets/images/3.0x/device_bind_success.webp';
  static const String deviceBindKnock =
      'assets/images/3.0x/device_bind_knock.webp';
}

terminal log

❯ spider build
[INFO] Processing path: assets/images
[File: 'assets/images/.DS_Store', Directory: 'assets/images/2.0x', File: 'assets/images/norex_logo_positiv.svg', Directory: 'assets/images/3.0x', File: 'assets/images/pair_device.svg']
Valid: File: 'assets/images/.DS_Store'
Valid: Directory: 'assets/images/2.0x'
Valid: File: 'assets/images/norex_logo_positiv.svg'
Valid: Directory: 'assets/images/3.0x'
Valid: File: 'assets/images/pair_device.svg'
[SUCCESS] Processed items for class Images: 3
[INFO] Processing path: assets/images/2.0x
[File: 'assets/images/2.0x/.DS_Store', File: 'assets/images/2.0x/device_watch.webp', File: 'assets/images/2.0x/device_bind_error.webp', File: 'assets/images/2.0x/device_bind_success.webp', File: 'assets/images/2.0x/device_bind_knock.webp']
Valid: File: 'assets/images/2.0x/.DS_Store'
Valid: File: 'assets/images/2.0x/device_watch.webp'
Valid: File: 'assets/images/2.0x/device_bind_error.webp'
Valid: File: 'assets/images/2.0x/device_bind_success.webp'
Valid: File: 'assets/images/2.0x/device_bind_knock.webp'
[SUCCESS] Processed items for class Images: 5
[INFO] Processing path: assets/images/3.0x
[File: 'assets/images/3.0x/.DS_Store', File: 'assets/images/3.0x/device_watch.webp', File: 'assets/images/3.0x/device_bind_error.webp', File: 'assets/images/3.0x/device_bind_success.webp', File: 'assets/images/3.0x/device_bind_knock.webp']
Valid: File: 'assets/images/3.0x/.DS_Store'
Valid: File: 'assets/images/3.0x/device_watch.webp'
Valid: File: 'assets/images/3.0x/device_bind_error.webp'
Valid: File: 'assets/images/3.0x/device_bind_success.webp'
Valid: File: 'assets/images/3.0x/device_bind_knock.webp'
[SUCCESS] Processed items for class Images: 5

Is the configuration information in our file wrong, or am I missing something?

by the way, I think .DS_Store files should not be generated.

BirjuVachhani commented 4 years ago

Hey @madroidmaq

I think your configuration is wrong! The assets inside directories 2.0x and 3.0x is used by Flutter internally. It has nothing to do with assets path and developers don't need to reference them anywhere in their dart code. So you can omit those directories from your configuration file. You just have to mention the root directory of those assets directories like this:

groups:
  - path: assets/images
    class_name: Images
    package: res

This will work perfectly in your case.

BirjuVachhani commented 4 years ago

@madroidmaq However, we can show some kind of warning or error when the user tries to use those directories in the configuration file. I have created one issue with an enhancement label that describes this in detail. Follow this #13

BirjuVachhani commented 4 years ago

@madroidmaq The default implementation says spider to generate a reference for any file in the directory unless you provide allowed types in the configuration file.

However, it is not aware of OS files like this .DS_STORE file on mac systems. But it should. I have created a new issue addressing this. #14

BirjuVachhani commented 4 years ago

@madroidmaq Until it is fixed, what you can do is that

  1. You can delete .ds_store file.
  2. You can specify the allowed types in the configuration.

Example

groups:
  - path: assets/images
    class_name: Images
    package: res
    types: [ .png, .jpg, .jpeg, .webp, .png, .gif ]
BirjuVachhani commented 4 years ago

I am closing this issue and you can follow these issues addressing main issues that you've reported and enhancements. #13 #14

madroidmaq commented 4 years ago

Hey @madroidmaq

I think your configuration is wrong! The assets inside directories 2.0x and 3.0x is used by Flutter internally. It has nothing to do with assets path and developers don't need to reference them anywhere in their dart code. So you can omit those directories from your configuration file. You just have to mention the root directory of those assets directories like this:

groups:
  - path: assets/images
    class_name: Images
    package: res

This will work perfectly in your case.

@BirjuVachhani I mention the root directory of those assets directories as you say. But it will not generate image resources in the 2.0x and 3.0x directory。

image

What should I do to generate resources under the 2.0x and 3.0x directory?Looking forward to your reply.