npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

runtime-env

v1.3.0

Published

A Cli to generate runtime-env for frontend apps

Downloads

320

Readme

Runtime-env

Runtime-env is cli written in go to parse environment variables & generate a javascript file which adds these to the browsers window object.

Release Software License Build status

Powered By: GoReleaser

Install

Script install

curl -sfL https://shkreios.github.io/runtime-env/install.sh | sh

NPM install

NPM

npm install --dev-save runtime-env

YARN

yarn add -D runtime-env

Usage

NAME:
   runtime-env - runtime envs for SPAs

USAGE:
   runtime-env [global options]

VERSION:
   v1.3.0

AUTHOR:
   Simon Hessel <[email protected]>

GLOBAL OPTIONS:
   --env-file value, -f value                   The .env file to be parsed
   --schema-file value, --schema value          A .env file which contains a list of envs to be parsed
   --prefix value, -p value                     The env prefix to matched
   --output value, -o value                     Output file path (default: "./env.js")
   --type-declarations-file value, --dts value  Output file path for the typescript declaration file
   --global-key value, --key value              Customize the key on which the envs will be set on window object (default: "__RUNTIME_CONFIG__")
   --remove-prefix                              Remove the prefix from the env (default: false)
   --no-envs                                    Only read envs from file not from environment variables (default: false)
   --disable-logs, --no-logs                    Disable logging output (default: false)
   --watch, -w                                  Watch .env file (default: false)
   --help, -h                                   show help (default: false)
   --version, -v                                print the version (default: false)

COPYRIGHT:
   Copyright © 2022 Simon Hessel

Input

# .env input file
TEST=Test

Command

$ runtime-env -f .env --no-envs

Output

window.__RUNTIME_CONFIG__ = { TEST: "Test" };

Code

console.log(window.__RUNTIME_CONFIG__.TEST);

Docker

#!/bin/sh

...

# any other entrypoint operations here
....
runtime-env # your runtime-env flags here

# any other entrypoint operations here
...

# call CMD
exec $@
...

# install runtime-env via install.sh script
RUN wget -O - https://shkreios.github.io/runtime-env/install.sh | sh

# important to be set after install.sh as otherwise binary will placed under /app/bin/runtime-env
WORKDIR /app/

# Copy your entrypoint script
COPY entrypoint.sh entrypoint.sh

...

#
ENTRYPOINT ["./entrypoint.sh"]

# optionaly set command
# CMD ["nginx"]

...

In CI/CD


# use either wget, curl or whatevery you ci env supports

curl -sfL https://shkreios.github.io/runtime-env/install.sh | sh

# wget -O - https://shkreios.github.io/runtime-env/install.sh | sh

runtime-env # your runtime-env flags here

Github Action

Read from secrets

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@master
      - uses: shkreios/runtime-env-action@v1
        with:
          version: v1.1.0
          prefix: RUN_ENV_
          output: ./public/env.js
          removePrefix: "true"
        env:
          RUN_ENV_EXAMPLE: ${{ secrets.EXAMPLE }}
// resulting env.js in public folder
window.__RUNTIME_CONFIG__ = { EXAMPLE: "SECRET_VALUE" };

Why go / Why should i use this package?

There many solutions similar to this package react-env, runtime-env-cra or sh scripts to name a few. They all fall in one of 2 categories:

  1. they are either dependent on a runtime/interpreter to be preinstalled like nodejs or python or
  2. they are not platform-agnostic

Go supports building binaries for multiple platforms and arches, and the binary itself includes everything to be executed. Therefore, no matter if development with npm or in docker CI/CD you can expect it to be easily installed and as light as it can be.

Why have a npm wrapper/placeholder script?

As this tool will mostly be used in npm codebases where you expect everything, including a tool that generates runtime-envs, to be installed via npm/yarn it's the best option.