# PecoCLI

A command line app that is primarily used to setup a Node.js project with [PecoTS](https://www.pecots.co.uk) (backend) and Angular (frontend) as the main frameworks.
[PecoTS](https://www.pecots.co.uk) is a closed source framework, and this tool has very little use outside of working with the framework.

## Create A New App

Use this command to quickly prepare an application directory with a backend, frontend, or both basic applications.
The process will ask for various details depending on the options selected.

```
peco-cli create-app
```

## Generate DOTENV

Generate a .env file for your PecoTS application using the `generate-env` command. The file will be created in the current directory.

```
peco-cli generate-env
```

## Check Update

Checks if an update to the CLI package is available.

```
peco-cli check-update
```

## Version

Outputs the current package version to the console.

```
peco-cli version
```

## Executing your CLI

You may execute your CLI application built in PecoTS by calling this utility from the root folder of your application followed by the commands you have created or those provided by the framework.

```
peco-cli my-app-command.a-function-to-execute
peco-cli migration.make users
peco-cli rbac.make
peco-cli migration.up
peco-cli migration.down
```

## Monorepo Configuration

For monorepo structures where your backend project is not located in the standard `./backend` directory, you can configure the backend path using the `PECOTS_BACKEND_PATH` environment variable.

### Environment Variable

Set the `PECOTS_BACKEND_PATH` environment variable to specify the path to your backend project:

```bash
# For relative paths (resolved from current working directory)
export PECOTS_BACKEND_PATH=packages/api/backend

# For absolute paths
export PECOTS_BACKEND_PATH=/full/path/to/backend
```

### Using .env Files

Alternatively, create a `.env` file in your project root:

```env
# .env file in project root
PECOTS_BACKEND_PATH=packages/api/backend
```

### Common Monorepo Examples

**Lerna/Nx Style:**

```env
PECOTS_BACKEND_PATH=packages/api
```

**Apps/Packages Structure:**

```env
PECOTS_BACKEND_PATH=apps/server
```

**Nested Backend:**

```env
PECOTS_BACKEND_PATH=services/backend/api
```

**Workspace Structure:**

```env
PECOTS_BACKEND_PATH=workspaces/backend
```

### Discovery Order

The CLI searches for your backend project in the following order:

1. **Environment Variable Path** - If `PECOTS_BACKEND_PATH` is set (from environment or .env file)
2. **Current Directory** - Looks for `index.ts` or `index.js` in the current directory
3. **Backend Subdirectory** - Looks for `index.ts` or `index.js` in `./backend/`

The CLI will automatically change to the backend directory during execution and return to the original directory when complete.

## Copyright

Copyright [Pecometer Software Limited](https://www.pecometer.co.uk)
