Skip to content

Commit

Permalink
feat(config): Support for config files (#68)
Browse files Browse the repository at this point in the history
* Added config file and package.json config props

* Added testing config file

* Added documentation

* Clean documentation
  • Loading branch information
mikkotikkanen authored May 16, 2021
1 parent eb8ece0 commit 5d426c3
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 8 deletions.
49 changes: 45 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ supermon npm run server
## Options

```help
Options:
--watch Directory to watch for file changes [string] [default: "."]
--ignore Directories to ignore for file changes [array]
Expand All @@ -55,17 +56,57 @@ Options:
--help Show help [boolean]
--debug Show debug information [boolean]
Note: If supermon arguments are provided, it is recommended to use "--" as separator between supermon and application command
Note: If both, supermon and application arguments are provided, it is recommended
to use "--" as separator between supermon and application command & arguments.
Example: "supermon --watch=dist -- app.js --port=80"
Note: Boolean options do not require value to be specified
Note: All options can also be configured through environment variables with
"SUPERMON_" prefix. (fe. "SUPERMON_LEGACYWATCH=true")
Example use: "supermon app.js"
Example use: "supermon --watch=dist -- app.js --port=80"
```

### Config file

Supermon supports setting all your options through single configuration file, `supermon.json`.

__Example:__

```json
{
"delay": 2000
}
```

### package.json

If you want to keep your amount of config files to minimum, you can also set the options through `supermon`
object in `package.json`.

__Example:__

```json
{
"name": "my-awesome-project",
"version": "0.0.1",
"...": "...",
"supermon": {
"delay": "2000"
}
}
```

### Environment variables

All options can also be set though environment variables with `SUPERMON_` prefix.

Example:

```env
SUPERMON_DELAY=2000
```


## Contributing

### Master branch
Expand Down
10 changes: 6 additions & 4 deletions src/bin/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ const argv = yargs
'unknown-options-as-args': true, // Make sure to pass all unknown options to the command
})
.env('SUPERMON')
.config('config')
.default('config', 'supermon.json')
.pkgConf('supermon')
.option('watch', {
describe: 'Directory to watch for file changes',
default: '.',
Expand Down Expand Up @@ -72,13 +75,12 @@ if (yargs.argv.version) {
if (yargs.argv.help) {
yargs.showHelp('log');
console.log('');
console.log('Note: If supermon arguments are provided, it is recommended to use "--" as separator between supermon and application command');
console.log('Note: If both, supermon and application arguments are provided, it is recommended');
console.log(' to use "--" as separator between supermon and application command & arguments.');
console.log(' Example: "supermon --watch=dist -- app.js --port=80"');
console.log('');
console.log('Note: Boolean options do not require value to be specified');
console.log('');
console.log('Note: All options can also be configured through environment variables with');
console.log(' "SUPERMON_" prefix. (fe. "SUPERMON_LEGACYWATCH=true")');
console.log('');
console.log('Example use: "supermon app.js"');
console.log('Example use: "supermon --watch=dist -- app.js --port=80"');
process.exit(); /* eslint-disable-line no-process-exit */
Expand Down
3 changes: 3 additions & 0 deletions supermon.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"delay": 1000
}

0 comments on commit 5d426c3

Please sign in to comment.