Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Env / config package #1136

Draft
wants to merge 30 commits into
base: main
Choose a base branch
from
Draft
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
a9f9cdb
init env pkg
goastler Apr 4, 2024
09636fe
basic loadConfig fns
goastler Apr 4, 2024
966b616
logging and loading from default env/config.ts paths
goastler Apr 4, 2024
19c39c9
adjusted default path handling
goastler Apr 4, 2024
3160a9a
parse config using schema
goastler Apr 4, 2024
32e2588
load from env using dotenv
goastler Apr 4, 2024
a6b5880
load config from js
goastler Apr 4, 2024
ef82125
js should export fn to build config
goastler Apr 4, 2024
9a9f706
make a test config
goastler Apr 4, 2024
6b14672
specifying config.ts converts to config.js
goastler Apr 4, 2024
faded39
check for config file existence
goastler Apr 4, 2024
acfb34d
missing dep
goastler Apr 4, 2024
4b637fc
Merge branch 'main' into env
goastler Apr 4, 2024
c304d1f
fix deps
goastler Apr 4, 2024
58ff03e
move config type to own file
goastler Apr 4, 2024
a14821d
compile ts
goastler Apr 4, 2024
06d8cb1
fix generic typing
goastler Apr 4, 2024
b378beb
JSON stringify env variables when loading from config
goastler Apr 4, 2024
b9731ab
make a config schema
goastler Apr 4, 2024
e11ca36
example of loading config
goastler Apr 4, 2024
707f0a6
example config
goastler Apr 4, 2024
3ded955
fix tests
goastler Apr 4, 2024
274aa1e
load config using json
goastler Apr 4, 2024
616ead6
json config
goastler Apr 4, 2024
da6a4af
json config tests
goastler Apr 4, 2024
98b0015
rename example env
goastler Apr 4, 2024
52e3300
move config pkg to configure
goastler Apr 4, 2024
1b8cff3
disable ts/js/json type configs
goastler Apr 4, 2024
048973f
lint
goastler Apr 4, 2024
ac2a117
lint
goastler Apr 5, 2024
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
Prev Previous commit
Next Next commit
basic loadConfig fns
  • Loading branch information
goastler committed Apr 4, 2024
commit 09636fe7e385fd12d5a6c7aa1f9ea07a76957292
31 changes: 31 additions & 0 deletions packages/config/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* The arguments for loading environment variables.
* @param populateProcessEnv - Whether to populate `process.env` with the loaded environment variables. Defaults to `false`.
* @param src - The path to the source file containing the environment variables. If unspecified, falls back to `config.ts` then `.env`.
*/
export type Args = {
populateProcessEnv?: boolean,
src?: string,
}

const loadConfigEnv = (args?: Args) => {
args = args ?? {};
}

const loadConfigTs = (args?: Args) => {
args = args ?? {};

}

/**
* Loads the config from env or a config file.
* @param args - The arguments for loading environment variables.
*/
export function loadConfig(args?: Args) {
args = args ?? {};
if (args.src?.endsWith('.ts')) {
return loadConfigTs(args);
} else {
return loadConfigEnv(args);
}
}