From 5d426c39962f6ea1df6279f5582adf652a9a7618 Mon Sep 17 00:00:00 2001 From: Mikko Tikkanen Date: Sun, 16 May 2021 11:38:28 +0300 Subject: [PATCH] feat(config): Support for config files (#68) * Added config file and package.json config props * Added testing config file * Added documentation * Clean documentation --- README.md | 49 +++++++++++++++++++++++++++++++++++++++++++++---- src/bin/cli.ts | 10 ++++++---- supermon.json | 3 +++ 3 files changed, 54 insertions(+), 8 deletions(-) create mode 100644 supermon.json diff --git a/README.md b/README.md index 23fbcaa..8c7d250 100644 --- a/README.md +++ b/README.md @@ -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] @@ -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 diff --git a/src/bin/cli.ts b/src/bin/cli.ts index 0bbb219..58e502c 100644 --- a/src/bin/cli.ts +++ b/src/bin/cli.ts @@ -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: '.', @@ -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 */ diff --git a/supermon.json b/supermon.json new file mode 100644 index 0000000..c439823 --- /dev/null +++ b/supermon.json @@ -0,0 +1,3 @@ +{ + "delay": 1000 +} \ No newline at end of file