# Metro CLI tool

<div id="introduction"></div>
## Introduction

Metro is a CLI tool that works under the hood of the Nylo framework. 
It provides a lot of helpful tools to speed up development.

<div id="install"></div>
## Install

Mac guide

**Run the below command from the terminal**

``` bash
echo "alias metro='dart run nylo_framework:main'" >>~/.bash_profile && source ~/.bash_profile
```

If you open a project that uses Nylo, try to run the following in the terminal.

``` bash
metro
```

You should see an output similar to the below.

``` bash
Usage: 
    command [options] [arguments]

Options
    -h

All commands:

 make
  make:controller
  make:model
  make:page
  make:stateless_widget
  make:stateful_widget
  make:theme
  make:event
  make:provider
  make:api_service
  make:theme
  make:route_guard
```

<div id="make-controller"></div>

## Make controller

You can make a new controller by running the below in the terminal.

``` bash
dart run nylo_framework:main make:controller profile_controller
```

Or with the alias metro

``` bash
metro make:controller profile_controller
```

This will create a new controller if it doesn't exist within the `lib/app/controllers/` directory.

<div id="make-model"></div>

## Make model

You can make a new model by running the below in the terminal.

``` bash
dart run nylo_framework:main make:model product
```

Or with the alias metro

``` bash
metro make:model product
```

It will place the newly created model in `lib/app/models/`.

If you plan to use the same model to represent objects from your API's, add it to your `lib/config/decoders.dart` modelDecoders map.

#### Arguments:

Using the `--force` flag will overwrite an existing class if it already exists.

``` bash
metro make:model product --force
```


<div id="make-page"></div>

## Make page

You can make a new page by running the below in the terminal.

``` bash
dart run nylo_framework:main make:page product_page
```

Or with the alias metro

``` bash
metro make:page product_page
```

This will create a new page if it doesn't exist within the `lib/resources/pages/` directory.
Nylo also supports the use of controllers. Use the below command to create a new page with a controller.

``` bash
metro make:page product_page -c
```

Create a page with a controller.

<div id="make-stateless-widget"></div>

## Make stateless widget

You can make a new stateless widget by running the below in the terminal.

``` bash
dart run nylo_framework:main make:stateless_widget product_rating_widget
```

Or with the alias metro

``` bash
metro make:stateless_widget product_rating_widget
```

The above will create a new widget if it doesn't exist within the `lib/resources/widgets/` directory.

<div id="make-stateful-widget"></div>

## Make stateful widget

You can make a new stateful widget by running the below in the terminal.

``` bash
dart run nylo_framework:main make:stateful_widget product_rating_widget
```
Or with the alias metro
``` bash
metro make:stateful_widget product_rating_widget
```

The above will create a new widget if it doesn't exist within the `lib/resources/widgets/` directory.

<div id="make-api-service"></div>

## Make API Service

You can make a new API service by running the below in the terminal.

``` bash
dart run nylo_framework:main make:api_service user
```

Or with the alias metro

``` bash
metro make:api_service user_api_service
```

You can provide the `--url="https://myapi.com"` option to create an API Service that will use the `url` as the Base URL.

``` bash
dart run nylo_framework:main make:api_service user --url="https://myapi-baseurl.com"
```

You can provide a `--model="User"` option to tell Nylo to create a new API Service with the following methods: <b>find</b>, <b>create</b>, <b>delete</b>, <b>update</b> and <b>fetchAll</b>.

``` bash
dart run nylo_framework:main make:api_service user --model="User"
```

It will place the newly created API service in `lib/app/networking/`.


<div id="make-api-service-using-postman"></div>

### Use Postman to Make API Services

You can make new API services using Postman v2.1 collection files. 

First, you must export your postman collection into a JSON file (using v2.1).

This should give you a file like `JsonPlaceHolder.postman_collection.json`.

You will need to copy this file into your Nylo project.
Copy the exported file into the `public/assets/postman` directory. 

E.g. `public/assets/postman/JsonPlaceHolder.postman_collection.json`.
After copying the file into the above directory, go to the terminal and run the following command.

``` bash
dart run nylo_framework:main make:api_service json_placeholder --postman="JsonPlaceHolder.postman_collection.json"
```

Or with the alias metro

``` bash
metro make:api_service json_placeholder --postman="JsonPlaceHolder.postman_collection.json"
```

This will create new **ApiServices** for your postman collections.

If your Postman collections include variables such as "BASE_URL" or others. You can define them in Nylo by opening the `postman.json` file which is located at the root of your Nylo project. Then, inside this file, add your variables.

E.g. 

```json
{
  "global": {
    "BASE_URL": "https://myapi.site.dev",
    "VERSION": "2.0"
  }
}
```

It will also add **Models** to your project if your Postman collections have a saved response.
You can check if your collection has saved responses by going to your Postman collection, then selecting a request. You should see a dropdown which will contain any saved responses.

If your collection doesn't contain a saved response, you will need to use Postman to make an HTTP request and then save the response.
The **name** of the saved response will be used as the name of the **Model** that Nylo will create.

<div id="make-event"></div>

## Make event

You can make a new event by running the below in the terminal.

``` bash
dart run nylo_framework:main make:event login_event
```

Or with the alias metro

``` bash
metro make:api_service login_event
```

This will create a new event in `lib/app/events`.

You will also need to add the event to your `lib/config/events.dart` map for it to be used.


<div id="make-provider"></div>

## Make provider

Create new providers in your application using the below command.

``` bash
dart run nylo_framework:main make:provider firebase_provider
```

Or with the alias metro

``` bash
metro make:provider firebase_provider
```

It will place the newly created provider in `lib/app/providers/`.

You will also need to add the provider to your `lib/config/providers.dart` map for it to be used.


<div id="make-theme"></div>

## Make theme

You can make themes by running the below in the terminal.

``` bash
dart run nylo_framework:main make:theme bright_theme
```

Or with the alias metro

``` bash
metro make:theme bright_theme
```

<div id="make-route-guard"></div>

## Make Route Guard

You can make a route guard by running the below in the terminal.

``` bash
dart run nylo_framework:main make:route_guard premium_content
```

Or with the alias metro

``` bash
metro make:route_guard premium_content
```

<div id="build-app-icons"></div>

## Build App Icons

You can generate all the app icons for IOS and Android by running the below command.

``` bash
dart run flutter_launcher_icons:main
```

This uses the <b>flutter_icons</b> configuration in your `pubspec.yaml` file.
