# pd (Product Development and Deployment)

<div align="center">
    <img src="images/logo128.png" alt="pd logo" width="128" height="128">
</div>

`pd` is a command-line tool that helps you with various development and deployment tasks.

|   | Feature                                     | Description                                                              |
|---|---------------------------------------------|--------------------------------------------------------------------------|
| 1 | Project initialization (`init`)             | Quickly initialize new development projects (e.g. FastAPI, Electron etc) |
| 2 | Content downloading (`down`)                | Download content from the internet (YouTube).                            |
| 3 | File conversion (`conv`)                    | Convert files into other formats (Image, Audio, Video).                  |
| 4 | EC2 instance management (`ec2`)             | Manage EC2 instances (launch, terminate).                                |
| 5 | Image editing (`edit`)                      | Edit images (round, favicon, logos etc).                                 |
| 6 | Environment setup and configuration (`env`) | Setup and configure development environment (zsh, vim, git, etc).        |
| 7 | Nginx configuration management (`nginx`)    | Manage Nginx configuration files (proxy, static resources).              |

See [COMMANDS](./COMMANDS.md) for more details.

# Installation

```bash
pip install zf-pd
```

This installs a `pd` command in your system (even though the package name is `zf-pd`).

Like other shell tools, pd stores its config in `~/.pdconfig.json`.

See [CONFIG](./CONFIG.md) for more details.

# Usage

## Initializing a new Project

```bash
$ pd init fastapi --name /path/to/fastapi-test
```

This will create a new FastAPI project called `fastapi-test` inside `/path/to` directory.

## Downloading a YouTube video

```bash
pd down youtube -l https://www.youtube.com/watch?v=... -f mp4 # or mp3, text etc
```

This will output a file called `{TITLE}.txt` at the current directory.

## Generating logo varations

```bash
$ pd edit logos -p /path/to/logo.png -t iOS - "20%"

# Outputs
# /path/to/logo40.png
# /path/to/logo60.png
# ...
```

This will generate all required iOS logos with `20%` border radius at `/path/to` directory.

## Converting MP4 to MP3

```bash
$ pd conv video -p /path/to/file.mp4 -f mp3
```

This will output a file called `file.mp3` at `/path/to` directory.

## Launching an EC2 instance

You can launch an EC2 instance using a launch template as below:

```bash
$ pd ec2 launch -n ec2-test -c 1
````

This will launch 1 EC2 instance called `ec2-test` using the launch template specified in `~/.
pdconfig.json`.

Check out the [CONFIG.md](./CONFIG.MD) for more details.

## Generating an Nginx Config

You can generate a Nginx configuration file using the `generate` command.

```bash
$ pd nginx generate -h localhost -p 80 -d example.com -s /path/to/static
server {
    server_name example.com;

    root /path/to/static;
    client_max_body_size 50M;

    location / {
        proxy_pass http://localhost:80;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }

    location /path/to/static {
        alias /path/to/static;

        # Add CORS 'Access-Control-Allow-Origin' header for fonts
        location ~* \.(ico|png|css|ttf)$ {
            add_header Access-Control-Allow-Origin *;
        }
    }
}
```

## License

MIT License

