Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/florianrappl/piral-cli-dotenv

Adds a flag to include environment variables from .env files. :rocket:
https://github.com/florianrappl/piral-cli-dotenv

cli dotenv environment-variables microfrontend piral plugin

Last synced: 10 days ago
JSON representation

Adds a flag to include environment variables from .env files. :rocket:

Awesome Lists containing this project

README

        

# piral-cli-dotenv

![Azure Build Status](https://dev.azure.com/FlorianRappl/piral-cli-plugins/_apis/build/status/FlorianRappl.piral-cli-dotenv?branchName=main) ![GitHub License](https://img.shields.io/badge/license-MIT-blue.svg)

Plugin for the `piral-cli`. Adds a flag to include environment variables from *.env* files.

Extends the Piral CLI command options to include dotenv files.

## Installation

Install the plugin either locally or globally.

We recommend the local installation:

```sh
npm i piral-cli-dotenv --save-dev
```

## Usage

### Including a .env File

Some commands of the Piral CLI will be extended with `--env` flags, e.g.,

```sh
piral debug --env
```

The list of supported / extended commands is:

- `build-piral`
- `debug-piral`
- `validate-piral`
- `build-pilet`
- `debug-pilet`
- `publish-pilet`
- `validate-pilet`

The `--env` flags behave as follows.

#### No argument

Standard dotenv resolution mechanism, e.g., takes a `.env` file if available.

Example Call:

```sh
piral build --env
```

#### File path

Uses the path to resolve and use the file as dotenv input.

Example input:

```plain
./secrets/.env
```

Example call:

```sh
piral build --env .env.prod
```

#### Name

Uses a file `{name}.env` or `.env.{name}` as input for dotenv.

Example input:

```plain
prod
```

Example call:

```sh
piral build --env prod
```

#### Variables

Uses the provided values as environment variables.

Example inputs:

```plain
FOO=BAR
FOO="BAR";BAR="FOO"
```

Example call:

```sh
piral build --env SERVICE_URL="http://example.com"
```

## FAQ

### Does it work with every bundler?

It should. It was tested with `piral-cli-webpack5` only. The `piral-cli-parcel2` bundler is presumably not working as they treat environment variables differently. Other bundlers are not tested.

### Are some environment variables overwritten?

Yes. Some variables are special (e.g., `NODE_ENV`) and will be set by the `piral-cli` anyway. This plugin focuses on non-special variables.

## License

This plugin is released using the MIT license. For more information see the [LICENSE file](LICENSE).