Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/hugojosefson/load-config-files

Loads config files.
https://github.com/hugojosefson/load-config-files

common config deno file javascript json toml typescript yaml yml

Last synced: 5 days ago
JSON representation

Loads config files.

Awesome Lists containing this project

README

        

# load_config_files

Loads config files.

Supports joining with common config files, also further up in the directory
structure.

Filetypes supported:

- .toml
- .json
- .yml
- .yaml
- .js
- .mjs
- .ts

## Usage

Set up a directory for example like
[example-config](https://deno.land/x/load_config_files/example-config), in your
current working directory:

```
example-config/
├── dev/
│   ├── common.js
│   ├── myapp1.toml
│   └── myapp2.toml
└── prod/
├── common.json
├── myapp1.json
└── myapp2.json
```

```typescript
// example.ts

import {
Config,
CONFIG_FORMATTERS,
ConfigFormatter,
loadConfig,
LoadConfigOptions,
} from "https://deno.land/x/load_config_files/mod.ts";

const options: LoadConfigOptions = { verbose: false };

const [formatterId, configRootPath, ...segments] = Deno.args;
const configRootUrl = new URL(configRootPath, "file:" + Deno.cwd());
const config: Config = await loadConfig(configRootUrl, segments, options);

const formatter: ConfigFormatter = CONFIG_FORMATTERS[formatterId];
const output: string = await formatter(config);

console.log(output);
```

Running the above program:

```sh
deno run \
--allow-read \
--allow-net=deno.land \
https://deno.land/x/load_config_files/example.ts \
shell example-config dev myapp2
```

...would output:

```sh
COLOR='purple'
CUSTOMER_URLS='{"CustomerA":"https://dev.example.com/customers/CustomerA.json","CustomerB":"https://dev.example.com/customers/CustomerB.json","CustomerC":"https://dev.example.com/customers/CustomerC.json","CustomerD":"https://dev.example.com/customers/CustomerD.json","CustomerE":"https://dev.example.com/customers/CustomerE.json"}'
APP_ID='myapp2'
```

### More examples

For all possible combinations, including different output formats, see
[example-config/EXAMPLE_ALL_COMBINATIONS.md](https://deno.land/x/load_config_files/example-config/EXAMPLE_ALL_COMBINATIONS.md).