Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/actions/go-setup/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ runs:
shell: bash
run: |
go install github.com/magefile/mage
go install github.com/hexira/go-ignore-cov@latest
mage -v bootstrap
4 changes: 3 additions & 1 deletion .github/actions/test/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ runs:
steps:
- name: Run Tests
shell: bash
run: mage -v test
run: |
mage -v test
go-ignore-cov --file cover.out
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:
jobs:
test:
runs-on: ubuntu-latest
name: Run Tests
name: Tests

steps:
- uses: actions/checkout@v6
Expand All @@ -21,7 +21,7 @@ jobs:
release:
needs: test
runs-on: ubuntu-latest
name: Build release binaries
name: Build and Release

steps:
- uses: actions/checkout@v6
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ on:
jobs:
test:
runs-on: ubuntu-latest
name: Run Tests
name: Tests

steps:
- uses: actions/checkout@v6
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ on:
jobs:
test:
runs-on: ubuntu-latest
name: Run Tests
name: Tests

steps:
- uses: actions/checkout@v6
Expand Down
40 changes: 22 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# reactENV

[![](https://img.shields.io/npm/v/%40reactenv%2Fcli)](https://www.npmjs.com/package/@reactenv/cli)
[![](https://img.shields.io/npm/v/%40reactenv%2Fcli)](https://www.npmjs.com/package/@reactenv/cli) [![Coverage Status](https://coveralls.io/repos/github/hmerritt/reactenv/badge.svg?branch=master)](https://coveralls.io/github/hmerritt/reactenv?branch=master)

Inject environment variables into a **bundled** react app (after `build`).

Expand All @@ -10,23 +10,23 @@ Useful for creating generic Docker images. Build your app once and add build fil

### Features ⚡

- No runtime overhead
- No app code changes required
- Injection is strict by default, and will error if any values are missing
- Blazing fast environment variable injection (~1ms for a basic react app)
- (Optional) Bundler plugins to automate processing `process.env` values during build
- [Webpack plugin `@reactenv/webpack`](https://github.com/hmerritt/reactenv/tree/master/npm/plugin-webpack)
- No runtime overhead
- No app code changes required
- Injection is strict by default, and will error if any values are missing
- Blazing fast environment variable injection (~1ms for a basic react app)
- (Optional) Bundler plugins to automate processing `process.env` values during build
- [Webpack plugin `@reactenv/webpack`](https://github.com/hmerritt/reactenv/tree/master/npm/plugin-webpack)

https://github.com/user-attachments/assets/c51465c9-d828-45e5-b469-a95e743d7d02

### Jump to:

- [Install](#install)
- [Usage](#usage)
- [Example](#example)
- [Reasoning](#reasoning)
- [Aims](#aims)
- [Licence](#licence)
- [Install](#install)
- [Usage](#usage)
- [Example](#example)
- [Reasoning](#reasoning)
- [Aims](#aims)
- [Licence](#licence)

## Install

Expand Down Expand Up @@ -69,8 +69,12 @@ It uses the current host enviroment variables and will replace all matches in th
All you need to do is run `reactenv run <path-to-js-files>` and it will do it's thing:

```sh
# Inject environment variables into all `.js` files in `dist` directory
# Inject environment variables into all `.js` files in `dist` directory (recursively)
$ reactenv run dist

# Override the file matcher (regex or glob, matching relative paths)
$ reactenv run --match "glob:**/*.mjs" dist
$ reactenv run --match "regex:^assets/.*\\.js$" dist
```

After running `reactenv`, your app is ready to be deployed and served!
Expand Down Expand Up @@ -177,10 +181,10 @@ I'm aware that this solution has it's drawbacks and I don't recommend it for eve

Since this is being ran **after** a build, this program needs to be 100% reliable. If somthing does go wrong, it catches and reports it so a failed build does not end up in production.

- Fast
- Reliable
- Easy to **debug**
- Simple to use
- Fast
- Reliable
- Easy to **debug**
- Simple to use

## Developing

Expand Down
116 changes: 0 additions & 116 deletions command/base.go

This file was deleted.

53 changes: 0 additions & 53 deletions command/base_helpers.go

This file was deleted.

52 changes: 29 additions & 23 deletions command/command.go
Original file line number Diff line number Diff line change
@@ -1,38 +1,44 @@
package command

import (
"fmt"
"os"

"github.com/hmerritt/reactenv/ui"
"github.com/hmerritt/reactenv/version"

"github.com/mitchellh/cli"
"github.com/spf13/cobra"
)

var Ui = ui.GetUi()

func Run() {
// Initiate new CLI app
app := cli.NewCLI("reactenv", version.GetVersion().VersionNumber())
app.Args = os.Args[1:]

// Feed active commands to CLI app
app.Commands = map[string]cli.CommandFactory{
"run": func() (cli.Command, error) {
return &RunCommand{
BaseCommand: GetBaseCommand(),
}, nil
},
rootCmd := NewRootCommand()
if err := rootCmd.Execute(); err != nil {
os.Exit(1)
}
}

// Run app
exitStatus, err := app.Run()
if err != nil {
os.Stderr.WriteString(fmt.Sprint(err))
func NewRootCommand() *cobra.Command {
showVersion := false

// Setup root CLI
rootCmd := &cobra.Command{
Use: "reactenv",
Short: "Inject environment variables into a built react app",
Run: func(cmd *cobra.Command, args []string) {
if showVersion {
Ui.Output(version.GetVersion().VersionNumber())
return
}
_ = cmd.Help()
},
SilenceUsage: true,
}

// Exit without an error if no arguments were passed
if len(app.Args) == 0 {
os.Exit(0)
}
// Flags
rootCmd.Flags().BoolVar(&showVersion, "version", false, "Show version")

// Commands
rootCmd.AddCommand(NewCommandRun())

os.Exit(exitStatus)
return rootCmd
}
Loading