Skip to content

Commit

Permalink
prepare for version 0.3.1
Browse files Browse the repository at this point in the history
Signed-off-by: birjuvachhani <[email protected]>
  • Loading branch information
BirjuVachhani committed Feb 15, 2020
1 parent 1805949 commit 8ecc3cf
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 67 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 0.3.1

- Fix version command.
- Formatted outputs and added more verbose logs.
- Added config validation before processing assets.

## 0.3.0

- Add support for categorization by file types.
Expand Down
145 changes: 80 additions & 65 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
# Spider

A small dart library to generate Assets dart code from assets folder.
It generates dart class with static const variables in it which can be used to reference
the assets safely anywhere in the flutter app.
It generates dart class with static const variables in it which can
be used to reference the assets safely anywhere in the flutter app.

### Example

Expand All @@ -30,12 +30,15 @@ class Assets {
}
```

This method allows no error scope for string typos. Also, it provides auto-complete
in the IDE which comes very handy when you have large amount of assets.
This method allows no error scope for string typos. Also, it provides
auto-complete in the IDE which comes very handy when you have
large amount of assets.

## Installation

This is package is an independent library that is not linked to your project. So there's no need to add it to your flutter project as it works as a global command line tool for all of your projects.
This is package is an independent library that is not linked to your
project. So there's no need to add it to your flutter project as it
works as a global command line tool for all of your projects.

```shell
pub global activate spider
Expand All @@ -49,76 +52,39 @@ spider --help

## Usage

### Using default configuration
By default, Spider will look for assets in 'assets' folder and will generate Dart
class with name `Assets` in 'lib/res/assets.dart' file.

#### Default Configs
```yaml
path: assets
class_name: Assets
package: res
```
### Categorizing by File Extension
By default, Spider allows any file to be referenced in the dart code. but you can change that
behavior. You can specify which files you want to be referenced.
```yaml
path: assets
class_name: Assets
package: res
types: [ jpg, png, jpeg, webp, bmp, gif ]
```
### Use Prefix
You can use prefixes for names of the generated dart references. Prefixes will be
attached to the formatted reference names.
```yaml
path: assets
class_name: Assets
package: res
prefix: ic
```
##### Output
```dart
class Assets {
static const String icCamera = 'assets/camera.png';
static const String icLocation = 'assets/location.png';
}
```

### Customize Configuration
To use custom configurations, Spider searches for a yaml file named 'spider.yaml' or 'spider.yml' in the
root directory of the flutter project. see default configs block for information on available configurations.

#### Create Configuration File
Spider provides a very easy and straight forward way to create a configuration file.
Execute following command and it will create a configuration file with default configurations in it.
Spider provides a very easy and straight forward way to create
a configuration file.
Execute following command and it will create a configuration file
with default configurations in it.

```shell
spider create
```

Now you can modify available configurations and Spider will use those configs when generating dart code.
Now you can modify available configurations and Spider will use
those configs when generating dart code.

#### Use JSON config file

Though above command creates `YAML` format for config file, spider also supports `JSON` format for config file. Use this command to create `JSON` config file instead of `YAML`.
Though above command creates `YAML` format for config file, spider
also supports `JSON` format for config file. Use this command to
create `JSON` config file instead of `YAML`.

```shell
spider create --json
```

No matter which config format you use, `JSON` or `YAML`, spider automatically detects it and uses it for code generation.
No matter which config format you use, `JSON` or `YAML`, spider
automatically detects it and uses it for code generation.

see help for more information:
```shell
spider create --help
Here's the default configuration that will be in the config file:

```yaml
groups:
- path: assets/images
class_name: Images
package: res
```
### Generate Code
Expand All @@ -130,7 +96,8 @@ spider build
```

### Watch Directory
Spider can also watch given directory for changes in files and rebuild dart code automatically. Use following command to watch for changes:
Spider can also watch given directory for changes in files and rebuild
dart code automatically. Use following command to watch for changes:

```shell
spider build --watch
Expand All @@ -141,11 +108,54 @@ see help for more information:
spider build --help
```

### Categorizing by File Extension

By default, Spider allows any file to be referenced in the dart code.
but you can change that behavior. You can specify which files you want to be referenced.

```yaml
path: assets
class_name: Assets
package: res
types: [ jpg, png, jpeg, webp, bmp, gif ]
```
### Use Prefix
You can use prefixes for names of the generated dart references.
Prefixes will be attached to the formatted reference names.
```yaml
path: assets
class_name: Assets
package: res
prefix: ic
```
##### Output
```dart
class Assets {
static const String icCamera = 'assets/camera.png';
static const String icLocation = 'assets/location.png';
}
```

### Customize Configuration
To use custom configurations, Spider searches for a yaml file named
'spider.yaml' or 'spider.yml' in the
root directory of the flutter project. see default configs block for
information on available configurations.

## Advanced Configuration
Spider provides supports for multiple configurations and classifications. If you wanna group your assets by module, type or anything, you can do that using `groups` in spider.
Spider provides supports for multiple configurations and classifications.
If you wanna group your assets by module, type or anything, you can do
that using `groups` in spider.

### Example
Suppose you have both vector(SVGs) and raster images in your project and you want to me classified separately so that you can use them with separate classes. You can use groups here. Keep your vector and raster images in separate folder and specify them in the config file.
Suppose you have both vector(SVGs) and raster images in your project
and you want to me classified separately so that you can use them with
separate classes. You can use groups here. Keep your vector and raster
images in separate folder and specify them in the config file.

`spider.yaml`
```yaml
Expand All @@ -158,9 +168,14 @@ groups:
package: res
```
Here, first item in the list indicates to group assets of `assets/images` folder under class named `Images` and the second one indicates to group assets of `assets/vectors` directory under class named `Svgs`.
Here, first item in the list indicates to group assets of
`assets/images` folder under class named `Images` and the second
one indicates to group assets of `assets/vectors` directory under
class named `Svgs`.

So when you refer to `Images` class, auto-complete suggests raster images only and you know that you can use them with `AssetImage` and other one with vector rendering library.
So when you refer to `Images` class, auto-complete suggests raster
images only and you know that you can use them with `AssetImage` and
other one with vector rendering library.

## License
```
Expand Down
2 changes: 1 addition & 1 deletion lib/src/version.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: spider
description: A small dart command-line tool for generating dart references of assets from the assets folder.
version: 0.3.0
version: 0.3.1
homepage: https://github.com/BirjuVachhani/spider

environment:
Expand Down

0 comments on commit 8ecc3cf

Please sign in to comment.