Skip to content

Commit

Permalink
Changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Vorlias committed Jun 17, 2022
1 parent 0bb3ec8 commit 94017c2
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 33 deletions.
7 changes: 4 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
out
node_modules
include
out
node_modules
include
**/*.ts-output
30 changes: 25 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,29 @@ Transformer for Roblox TypeScript compiler that allows getting values of process
}
```

For example, you have a `.env` file in your project directory as following:
# Usage
## `$NODE_ENV`
This will change to whatever the value of `NODE_ENV` is in your environment. If no value is set, this is defined in the configuration options above under `defaultEnvironment`, or `"production"` if no such value is present.

```env
HELLO=Hello, World!
NUMBER=20
```
## `$env`
This contains three functions of which can be used to obtain environment variables

#### `$env.string( variable [, defaultValue] )`
This will attempt to grab the given `variable` from the environment, otherwise will provide the default value. (`undefined` if no default value is given)

#### `$env.boolean( variable )`
This can be used to get a boolean environment variable, or check if an environment variable exists.
If the value is not (case-insensitive) `false`, but is set it will be considered `true`. This can be used to also check if environment variables exist.

#### `$env.number( variable [, defaultValue] )`
This will attempt to grab the given `variable` from the environment and parse it as a number, otherwise will provide the default value. (`undefined` if no default value is given)

# Behaviours
If there is an if statement, an attempt will be made to short-circuit the if statement. e.g.

```ts
if ($NODE_ENV === "production") {
// Code here
}
```
Any code in this if statement will not render (unless an else is specified) if the environment is not production.
9 changes: 5 additions & 4 deletions example/src/shared/module.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { $env, $NODE_ENV } from "../../..";

$env("NODE_ENV");
const test = $env.string("USERPROFILE");

const test = $env.string("POOP");
$env.string("test", "withDefault");

function testing() {
if ($env.boolean("USERPROFILE")) {
Expand All @@ -17,7 +17,8 @@ $NODE_ENV;
if ($NODE_ENV === "production") {}
if ("public-test" === $NODE_ENV) {}

if ($env.string("NODE_ENV") === "right") {}
if ($env.string("NODE_ENV2")) {}
if ($env.boolean("USERPROFILE")) {
const seqAddr = $env.string("USERPROFILE");
}

const something = $NODE_ENV === "production" ? "yes":"no";
16 changes: 0 additions & 16 deletions example/src/shared/module.ts-output

This file was deleted.

5 changes: 0 additions & 5 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@
export const $env: $env;

export interface $env {
/** @deprecated Use `$env.string`, `$env.number` or `$env.boolean` */
(variable: string): string | undefined;
/** @deprecated Use `$env.string`, `$env.number` or `$env.boolean` */
(variable: string, defaultValue: string): string;

/**
* Attempts to fetch the given environment variable - if not set, it will be `undefined` or the default value if given.
* @param name The name of the variable
Expand Down

0 comments on commit 94017c2

Please sign in to comment.