# egg-extra-config

> Extra config plugin for egg

Latest version **0.0.1** (published 2019-02-27) · MIT license · 0 weekly downloads

## Install

```sh
npm install egg-extra-config
pnpm add egg-extra-config
yarn add egg-extra-config
bun add egg-extra-config
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.1 |
| Published | 2019-02-27 |
| First published | 2019-02-27 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 7.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | claude-ray |
| Maintainers | claude-ray |
| Keywords | eggjs, egg-config, egg-plugin, eggPlugin |

## Links

- npm: https://www.npmjs.com/package/egg-extra-config
- Repository: https://github.com/Claude-Ray/egg-extra-config
- Homepage: https://github.com/Claude-Ray/egg-extra-config#readme
- Issues: https://github.com/Claude-Ray/egg-extra-config/issues
- npm.io page: https://npm.io/package/egg-extra-config

## Dependencies (3)

- [extend2](https://npm.io/package/extend2.md) ~1.0.0
- [chokidar](https://npm.io/package/chokidar.md) ~2.0.4
- [debounce](https://npm.io/package/debounce.md) ~1.2.0

## Alternatives

- [jsforce](https://npm.io/package/jsforce.md) — 851.2K weekly downloads
- [react-native-qrcode-svg](https://npm.io/package/react-native-qrcode-svg.md) — 693.5K weekly downloads
- [@salesforce/plugin-data](https://npm.io/package/@salesforce/plugin-data.md) — 394.9K weekly downloads
- [@backstage/plugin-search-common](https://npm.io/package/@backstage/plugin-search-common.md) — 308.5K weekly downloads
- [@chain-registry/types](https://npm.io/package/@chain-registry/types.md) — 38.4K weekly downloads

## Recent versions

- 0.0.1 (latest) — 2019-02-27

## README

# egg-extra-config
[![Build Status](https://travis-ci.org/Claude-Ray/egg-extra-config.svg?branch=master)](https://travis-ci.org/Claude-Ray/egg-extra-config)
[![codecov](https://codecov.io/gh/Claude-Ray/egg-extra-config/branch/master/graph/badge.svg)](https://codecov.io/gh/Claude-Ray/egg-extra-config)

Loading config file outside eggjs project path. Watching this file's changes and auto reloading configurations of `app.config` without restarting process.

## Install
```sh
npm install egg-extra-config
```

## Usage
```js
// plugin.js
exports.extraConfig = {
  enable: true,
  package: 'egg-extra-config',
};
```

## Configuration
Configure information in ${app_root}/config/config.default.js:

### Paths
Support directory path.
> [chokidar#paths](https://github.com/paulmillr/chokidar#api)(string or array of strings). Paths to files, dirs to be watched recursively, or glob patterns.

#### Single path
```js
config.extraConfig: {
  paths: '/your/custom/config/path/config.js',
};
```

#### Multi paths
These files' config reloading has no priority.

However, the same configuration will be overrided in the order of the array only during application starting.

```js
config.extraConfig: {
  paths: [
    '/etc/path/config.js',
    '/etc/path/dir/',
    '/etc/path/this-file-might-override-the-above-files.js',
  ],
};
```

### Extensions
Used to restrict file types.

By default, configuration will be loaded by `require`, this could be dangerous because functions can be executed in a `.js` file.

If you do not want the runtime environment to be destoryed, it is highly recommended to configure `extensions` as `['.json']`.

```js
config.extraConfig: {
  paths: [
    '/etc/path1/',
    '/etc/path2/',
  ],
  extensions: [ '.json' ],
};
```

## TODO
- [ ] 按照egg的[生命周期](https://github.com/eggjs/egg/blob/master/docs/source/en/advanced/loader.md#life-cycles)，应该在configDidLoad()前完成自定义配置的加载，目前放在app.beforeStart()
- [ ] 限制只能重载项目config目录内、或不在app.config内的配置
- [ ] 日志记录变更值
- [ ] 优化配置加载过程
- [ ] IPC

## DONE
- [x] 监听特定目录或文件变更，将变动应用于配置的重载
- [x] 在app.ready()前完成自定义配置的加载，借助了app.beforeStart()
- [x] 优化拷贝过程，支持嵌套对象的内部变更
- [x] 删除自定义配置后，重新加载项目内对应配置
- [x] 支持配置多个文件，参考[chokidar API](https://github.com/paulmillr/chokidar#api)#paths：(string or array of strings) "Paths to files, dirs to be watched recursively, or glob patterns"。 但不做优先级处理，仅在配置加载过程中按照数组顺序来覆盖相同配置。
- [x] 支持目录，~~以egg的方式加载其中配置~~，通过require.resolve修正路径，按照module的形式读取
- [x] 限制文件类型(可选)，例如只监视`.json`，避免`.js`文件破坏运行状态
- [x] 文件变更防抖动

---
_Source: https://npm.io/package/egg-extra-config · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
