# @reapit/cli

> A cli tool for reapit cloud

Latest version **2.1.6** (published 2023-03-08) · 0 weekly downloads

## Install

```sh
npm install @reapit/cli
pnpm add @reapit/cli
yarn add @reapit/cli
bun add @reapit/cli
```

Provides the command `reapit`.

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.1.6 |
| Published | 2023-03-08 |
| First published | 2022-01-05 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 23 |
| Unpacked size | 1.1 MB |
| Known vulnerabilities | 0 (+35 in 3 direct dependencies) |
| Install scripts | no |
| Maintainers | wmcvayreapit, dawsonscott |

## Links

- npm: https://www.npmjs.com/package/@reapit/cli
- Repository: https://github.com/reapit/foundations/packages/cli
- npm.io page: https://npm.io/package/@reapit/cli

## Dependencies (23)

- [ora](https://npm.io/package/ora.md) ^5.4.1
- [open](https://npm.io/package/open.md) ^8.4.2
- [axios](https://npm.io/package/axios.md) ^0.27.2
- [chalk](https://npm.io/package/chalk.md) ^4.1.2
- [figlet](https://npm.io/package/figlet.md) ^1.5.2
- [semver](https://npm.io/package/semver.md) ^7.3.8
- [adm-zip](https://npm.io/package/adm-zip.md) ^0.5.10
- [shleemy](https://npm.io/package/shleemy.md) ^1.2.2
- [inquirer](https://npm.io/package/inquirer.md) ^8.2.5
- [tsyringe](https://npm.io/package/tsyringe.md) ^4.7.0
- [pusher-js](https://npm.io/package/pusher-js.md) ^7.6.0
- [ansi-regex](https://npm.io/package/ansi-regex.md) ^6.0.1
- [jwt-decode](https://npm.io/package/jwt-decode.md) ^3.1.2
- [simple-git](https://npm.io/package/simple-git.md) ^3.16.1
- [cli-spinners](https://npm.io/package/cli-spinners.md) ^2.7.0
- [process.argv](https://npm.io/package/process.argv.md) ^0.6.1
- [latest-semver](https://npm.io/package/latest-semver.md) ^3.0.0
- [find-free-port](https://npm.io/package/find-free-port.md) ^2.0.0
- [create-react-app](https://npm.io/package/create-react-app.md) ^5.0.1
- [isomorphic-fetch](https://npm.io/package/isomorphic-fetch.md) ^3.0.0
- [reflect-metadata](https://npm.io/package/reflect-metadata.md) ^0.1.13
- [@reapit/connect-session](https://npm.io/package/@reapit/connect-session.md) ^4.0.2
- [nestjs-typeorm-paginate](https://npm.io/package/nestjs-typeorm-paginate.md) ^2.6.3

## Recent versions

- 2.1.6 (latest) — 2023-03-08
- 2.1.5 — 2023-03-08
- 2.1.4 — 2023-03-06
- 2.1.3 — 2022-11-04
- 2.1.2 — 2022-06-21
- 2.1.1 — 2022-06-17
- 2.1.0 — 2022-06-17
- 2.0.0 — 2022-06-07
- 1.0.2 — 2022-05-10
- 1.0.0 — 2022-05-05
- 0.3.5 — 2022-02-28
- 0.3.4 — 2022-01-26
- 0.3.3 — 2022-01-26
- 0.3.2 — 2022-01-26
- 0.3.0 — 2022-01-11
- … 6 more at https://npm.io/package/@reapit/cli/versions

## README

# Reapit-cli
Command line interface tool for reapit 

![Deployment gif](https://raw.githubusercontent.com/reapit/foundations/master/packages/cli/reapit-deploy.gif)

## Available commands

Use `reapit --help` to see all commands in the terminal.
Or use `reapit config --help` to describe an individual command.

Command | description
--- | ---
`reapit config` | Starts a prompt to add the cli's config requirements (api-key)
`reapit pipeline create` | Starts the process of creating a new pipeline
`reapit pipeline edit` | Used to edit a given pipeline
`reapit pipeline delete` | Deletes a given pipeline
`reapit pipeline link` | Links repo with existing pipeline (downloads pipeline config to cwd)
`reapit pipeline list` | List all pipelines for developer account
`reapit release repo` | Starts a deployment using the github repo
`reapit release zip` | Starts a deployment using a locally built directory as source
`reapit release list` | List all pipeline releases/deployments
`reapit release version` | Deploys a specific previously deployed version (rollback)
`reapit pipeline params` | List all environment param keys configured for pipeline
`reapit pipeline param-configure` | Create or update a new or existing environment parameter

> The above is subject to updates

## Install

Installing requires the below steps

- [Obtain npm token](#obtaining-npm-token)
- [Create `.npmrc` file](#create-the-npmrc-file)
- [Installing the cli](#installing-the-cli)
- [Adding your api-key](#adding-your-api-key)


### Obtaining NPM Token

Ask the reapit developers for an NPM token

### Create the `.npmrc` file

In your computer's root, create the file `.npmrc`, here is a method using bash

```bash
touch ~/.npmrc
```
Without a global `.npmrc` file with your provided token, you will not be able to download the cli

Below is the following that needs to be added to the `.npmrc` file. Make sure to replace `NPM_TOKEN` with your npm token.

```
//registry.npmjs.org/:_authToken=NPM_TOKEN
```

### Installing the cli

Simply run the below command to install the reapit cli globally on your machine.

```bash
$ npm i -g @reapit/cli
```

### Adding your api key

In order to run commands you'll need to obtain an api-key in order to make authenticated requests.

Get your api-key from the [reapit developers]()

To add your api-key to the cli, simply run the below command. This will start a prompt for your config shown below.

```bash
$ reapit config
```

![Config Snapshot](https://raw.githubusercontent.com/reapit/foundations/master/packages/cli/snapshots/config.png)

## Terminology

Below is a table of terminologies used in the cli with some descriptions

Term | Description
--- | ---
Pipeline | A configuration for a deployment process
Pipeline Runner, Deployment | A running/individual deployment of a pipeline
Release | almost synonymous with deployment, can be used to describe a method of triggering a deployment
Rollback | The ability to make a previously deployed version live

## Deployment

> First make sure you've created a pipeline by either the UI or the cli using `reapit pipeline create`.

Start the deployment by running the following command

This will start a manual deployment by uploading a zip of your locally built application.

```bash
$ reapit pipeline deploy-zip
```

answer the following questions and the deployment will start.

![Deploy zip Snapsot](https://raw.githubusercontent.com/reapit/foundations/master/packages/cli/snapshots/deploy-zip.png)

## Deployment via github actions

First install the cli as a dev dependant

```bash
$ yarn add --dev @reapit/cli
```

Once you've done that, add the following to the file `.github/workflows/deply.yml`

This will run a deployment every time you make a push to master

```yml
name: Deploy with Reapit cli

on:
  push:
    branches:
      - master

env:
  NPM_TOKEN: ${{secrets.NPM_TOKEN}}
  REAPIT_API_KEY: ${{secrets.REAPIT_API_KEY}}
  PIPELINE_ID: ${{secrets.PIPELINE_ID}}

  CI: true

jobs:
  deploy-with-reapit-cli:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v2
        with:
          fetch-depth: 0

      - name: Set Node
        uses: actions/setup-node@v1
        with:
          node-version: '14.x'

      - name: Install
        run: yarn
        env:
          NPM_TOKEN: ${{secrets.NPM_TOKEN}}

      - name: Build
        run: |
          yarn build

      - name: Deploy
        run: |
          echo $PIPELINE_ID &&
          yarn reapit pipeline deploy-zip $PIPELINE_ID -y
        env:
          PIPELINE_ID: ${{secrets.PIPELINE_ID}}
      - name: Commit & Push changes
        uses: actions-js/push@master
        with:
          github_token: ${{ secrets.GITHUB_TOKEN }}
          branch: 'master'

```

> Note: you'll notice there is a commit & push action here. This is important to keep the version up to date with deployments. Otherwise deployments will fail after the first successful one.

# Development

This section is for the development of the reapit cli

## Creating commands

Commands are written in an OOP method and are bootstraped with the `AbstractCommand` class which provides some helpful functions for creating commands

```ts
@Command({
  name: "example", // reapit example
  description: "An example command on how to build a reapit cli command", // for the help option
})
export class ExampleCommand extends AbstractCommand {
  run(
    @Param({
      name: 'param', // name for help
      default: 'default value',
    })
    param: string,
  ) {
    console.log(param) // inputted arg or 'default value'
  }
}
```

> All commands must use the `Command` decorator so that the command can be found to be ran

### Add new command

When adding a command to the cli, it will need to be added to the runnable commands array in the bootstrap func which lives in the `index.ts` file

```ts
boot(new IntroCommand(), [new ConfigCommand(), new DeploymentCommand(), /* add new command here*/])
```

### Parent commands

Parent commands are grouped commands for running as sub commands. Below is an example of a sub command

```bash
$ reapit pipeline create
```

where `pipeline` is the command group and `create` is the sub command.

Parent commands will extends the `ParentCommand` class

```ts
@Command({
  name: 'pipeline',
  description: 'For managing deployments',
})
export class PipelineCommand extends ParentCommand {
  commands = [new PipelineCreate(), new PipelineList(), new PipelineRun()]
}
```

### Params and Options

In the run function, `Param` and `Option` decorators can be used to description incomming arguments and options.

#### Param

```ts
@Command({
  name: 'example',
})
class ExampleCommand extends AbstractCommand {
async run(
    @Param({
      name: 'param', // name for help
      default: 'default value',
    })
    param: string,
  ) {
    console.log(param) // inputted arg or 'default value'
  }
}
```

Params in the run function should be ordered in the same order as expected input args. Example `reapit example first second third`

```ts
@Command({
  name: 'example',
})
class ExampleCommand extends AbstractCommand {
async run(
    @Param({
      name: 'uno',
    })
    uno: string,
    @Param({
      name: 'due',
    })
    due: string,
    @Param({
      name: 'tre',
    })
    tre: string,
  ) {
    console.log('order', uno, due, tre) // order first second third
  }
}
```

#### Options

Options are similar to params but used as booleans. Example `reapit example this-is-the-id -f` and `reapit example --fetch this-is-the-id` will result in the `fetch` parameter being true. If these options are not supplied, `fetch` is false.

```ts
@Command({
  name: 'example',
})
class ExampleCommand extends AbstractCommand {
async run(
    @Param({
      name: 'id',
    })
    id: string,
    @Option({
      name: 'fetch',
      shortName: 'f',
    })
    fetch: boolean,
  ) {
    console.log('fetch?', fetch) // fetch? true
  }
}
```

---
_Source: https://npm.io/package/@reapit/cli · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
