https://github.com/coursedesign/conev-source-jsonfile
conev-source-jsonfile is an implementation of conev's source to get configuration from json file.
https://github.com/coursedesign/conev-source-jsonfile
conev configuration environment npm npm-package
Last synced: 10 months ago
JSON representation
conev-source-jsonfile is an implementation of conev's source to get configuration from json file.
- Host: GitHub
- URL: https://github.com/coursedesign/conev-source-jsonfile
- Owner: CourseDesign
- Created: 2020-03-19T07:12:00.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2023-01-16T07:04:50.000Z (about 3 years ago)
- Last Synced: 2024-05-28T20:49:04.323Z (over 1 year ago)
- Topics: conev, configuration, environment, npm, npm-package
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/conev-source-jsonfile
- Size: 18.6 KB
- Stars: 0
- Watchers: 1
- Forks: 1
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# conev-source-jsonfile
conev-source-jsonfile is an implementation of conev's source to get configuration from json file.

## Install
```shell
# with npm
npm install conev-source-jsonfile
# or with Yarn
yarn add conev-source-jsonfile
```
## Usage
Get ConfigBuilder from conev and Sources to use.
```typescript
import { ConfigBuilder } from 'conev';
import ProcessEnvSource from 'conev-source-jsonfile';
```
And create Source and set up.
```typescript
const jsonFileSource = new ProcessEnvSource();
jsonFileSource
.setConfig('basic', './basic.json') // basic is JSON
.setConfig('dev', './dev.json') // dev is JSON
.setConfig('prd', './prd.json'); // prd is JSON
```
Create ConfigBuilder and set Environment, add source. (highest priority is added first).
```typescript
const builder = new ConfigBuilder();
builder
.setEnv('dev', 'basic')
.addSource(jsonFileSource);
```
Build configuration
```typescript
const config = await builder.build(); // This is the result of combining dev and basic.
```
Use configuration
```typescript
config.get() // The whole configuration created comes out
config.get('a.b.c'); // Is same as config.get().a.b.c
```
## Json File Source
```typescript
class JsonFileSource {
constructor(fileMap?: Map);
setConfig(env: string, ...filenames: string[]): JsonFileSource;
addConfig(env: string, ...filename: string[]): JsonFileSource;
removeConfig(env: string): JsonFileSource;
export(): Promise>;
}
```
`ProcessEnvSource` defines the source from JSON file. Use `setConfig` to add a configuration for a new environment or ` removeConfig` to delete a configuration. Map is returned as the result value of `export`. The key of this map is environment and the value is the configuration when environment.