# serverless-post-deployment-builder

> A Serverless Framework plugin to immediately build after serverless deployment

Latest version **1.0.1** (published 2020-10-25) · MIT license · 0 weekly downloads

## Install

```sh
npm install serverless-post-deployment-builder
pnpm add serverless-post-deployment-builder
yarn add serverless-post-deployment-builder
bun add serverless-post-deployment-builder
```

## 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 | 1.0.1 |
| Published | 2020-10-25 |
| First published | 2020-10-24 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 9.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Mahasooq AT |
| Maintainers | mahasooq |
| Keywords | serverless, framework, plugin, deploy, build, frontend, client, cloudformation, stack, output, cognito, environment, variable |

## Links

- npm: https://www.npmjs.com/package/serverless-post-deployment-builder
- Repository: https://github.com/mahasooq/serverless-post-deployment-builder
- Homepage: https://github.com/mahasooq/serverless-post-deployment-builder#readme
- Issues: https://github.com/mahasooq/serverless-post-deployment-builder/issues
- npm.io page: https://npm.io/package/serverless-post-deployment-builder

## Dependencies (1)

- [cross-spawn](https://npm.io/package/cross-spawn.md) ^7.0.3

## Alternatives

- [replicas-cli](https://npm.io/package/replicas-cli.md) — 3.0K weekly downloads
- [env-contract](https://npm.io/package/env-contract.md) — 133 weekly downloads
- [@openveo/api](https://npm.io/package/@openveo/api.md) — 61 weekly downloads
- [@ryniaubenpm2/cumque-error-reiciendis](https://npm.io/package/@ryniaubenpm2/cumque-error-reiciendis.md) — 54 weekly downloads
- [ts-global-type-extra](https://npm.io/package/ts-global-type-extra.md) — 11 weekly downloads

## Recent versions

- 1.0.1 (latest) — 2020-10-25
- 1.0.0 — 2020-10-24

## README

# Serverless Post Deployment Builder
[![npm](https://img.shields.io/npm/v/serverless-post-deployment-builder.svg)](https://www.npmjs.com/package/serverless-post-deployment-builder)
[![license](https://img.shields.io/github/license/mahasooq/serverless-post-deployment-builder.svg)](https://github.com/mahasooq/serverless-post-deployment-builder/blob/master/LICENSE.md)

A [Serverless Framework](https://serverless.com) plugin to immediately build your frontend applicatoin after serverless deployment. It can fetch the cloudformation stack output and set in enviroment variables before building. 

## Installation

```sh
$ npm install --save-dev serverless-post-deployment-builder
```

## Configuration


```yaml
...

plugins:
  - serverless-post-deployment-builder

postDeployBuilder:
    cwd: app
    packager: npm
    command: run build
    environment:
      REACT_APP_VERSION: 2
    stackenvironment:
      REACT_APP_USER_POOL_ID: UserPoolId # In the format ENV_NAME: STACK_OUTPUT_NAME
      REACT_APP_USER_POOL_CLIENT_ID: UserPoolClientId
...
``` 

## Options 

**--noRun**

_optional_

`--noRun` cli option can be passed with `serverless deploy` to disable this plugin

### Configuration Options

**cwd**

_required_

The working directory where you need to run the build command

---

**packager**

_optional_, default: `npm`

Either `npm` or `yarn`

---

**command**

_optional_, default: `run build`

---

**environment**

_optional_

The values defined will be set as environemnt variable before building. It will override any environment variable in provider. 

---

**stackenvironment**

_optional_

You can spefify cloudformation stack outputs which you need to set in environemnt variables using this option. It's a key value in the format `ENV_NAME: STACK_OUTPUT_NAME`. It will fetch the output value with key `STACK_OUTPUT_NAME` and set to an environemtn variable named `ENV_NAME`

---

## Example
In this example, the plugin is setting two cloudformation outputs for AWS Cognito in the enviroment and build frontend application at `app` directory using `npm`

### serverless.yml

```yaml
service: post-deploy-builder-example

frameworkVersion: '2'

plugins:
  - serverless-post-deployment-builder


custom:  
  postDeployBuilder:
    cwd: app
    packager: npm
    command: run build
    environment:
      REACT_APP_STAGE: ${opt:stage}
    stackenvironment:
      REACT_APP_USER_POOL_ID: UserPoolId
      REACT_APP_USER_POOL_CLIENT_ID: UserPoolClientId

provider:
  name: aws
  runtime: nodejs12.x

functions:
  example:
    handler: lambda/example.handler
    events:
      - http:
          path: example
          method: get
          cors: true

resources:
  Resources:    
    CognitoUserPool:
      Type: AWS::Cognito::UserPool
      Properties:
          UserPoolName: ${self:service}-${opt:stage}-user-pool

    CognitoUserPoolClient:
      Type: AWS::Cognito::UserPoolClient
      Properties:
          ClientName: ${self:service}-${opt:stage}-user-pool-client
          UserPoolId:
            Ref: CognitoUserPool

  Outputs:
    UserPoolId:
      Value:
        Ref: CognitoUserPool
      Export:
        Name: ${self:service}-${opt:stage}-user-poolId

    UserPoolClientId:
      Value:
        Ref: CognitoUserPoolClient
      Export:
        Name: ${self:service}-${opt:stage}-user-pool-clientId
```

The plugin will be invoked when you deploy the applicaiton with
```sh
$ serverless deploy --stage=dev
```
This will build the frontend using `npm run build` with the environment variables
```env
REACT_APP_STAGE=dev
REACT_APP_USER_POOL_ID=ap-southeast-1_XXXXXXU
REACT_APP_USER_POOL_CLIENT_ID=6oeieXXXXXXXXXXXXXXXXb3
```

---
_Source: https://npm.io/package/serverless-post-deployment-builder · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
