From 008487808e52e155c78571d49fbb946967b3c110 Mon Sep 17 00:00:00 2001 From: about-code Date: Sun, 15 Sep 2019 22:43:49 +0200 Subject: [PATCH] feat: glossarify-md --help fix: make default baseDir ./src rather than "." to prevent copying CWD to outDir. fix: drop parameterless usage example from README.md. --- README.md | 17 +++++++---------- bin/index.js | 17 ++++++++++++++++- conf.schema.json | 14 +++++++------- 3 files changed, 30 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index b0c1edd5..4ea7f626 100644 --- a/README.md +++ b/README.md @@ -51,12 +51,6 @@ This is a text which uses a Glossary Term to describe something. ## Glossarify Command -### ...with default values - -``` -glossarify-md -``` - ### ...with command options ``` glossarify-md @@ -73,7 +67,7 @@ glossarify-md glossarify-md --config ./glossarify-md.conf.json ``` -*glossarify-md.conf.json* (sample with default values) +*glossarify-md.conf.json* ```json { "$schema": "./node_modules/glossarify-md/conf.schema.json", @@ -124,9 +118,12 @@ Most occurrences of a term have been replaced with a link to its glossary defini This is a text which uses a [Glossary Term ↴](../glossary.md#glossary-term) to describe something. ``` - ## Options +### `--help` | `--h` + +Show all options and default values. + ### `--baseUrl` | `--b` - **Range:** string @@ -169,7 +166,7 @@ When true any occurrence of a term will be linked no matter how it was spelled. - **Range:** string[] -Paths or Glob-Patterns for files to include. Default is `./` +Paths or Glob-Patterns for files to include. ### `--keepRawFiles` | `--r` @@ -201,7 +198,7 @@ files or if you are able to roll back any changes or if you know the outcome satisfies your needs. The recommendation is to write outputs to a separate directory such as `./out` -or `./tmp`. Default is `./tmp`. +or `./tmp`. or `./target`. ## Additional Features diff --git a/bin/index.js b/bin/index.js index 26813833..c971704f 100644 --- a/bin/index.js +++ b/bin/index.js @@ -21,12 +21,27 @@ const cliOpts = buildOpts( Object.assign( { "config": { type: "string", alias: "c", default: "" }, + "help": { type: "boolean", alias: "h", default: false} }, confSchema ) ); const args = minimist(proc.argv.slice(2), cliOpts); +if (args.help) { + console.log("Options:\n\n", + Object + .keys(confSchema) + .filter(key => key !== "dev") + .map(key => { + const {alias, type, description, default:_default} = confSchema[key]; + return `--${alias} --${key} (${type})\n${description}\nDefault: ${JSON.stringify(_default)}\n\n`; + }) + .join("") + ); + process.exit(0); +} + // Read file opts let conf = {}; const confPath = args.config; @@ -36,7 +51,7 @@ if (confPath) { conf = JSON.parse(fs.readFileSync(path.resolve(CWD, confPath))); confDir = path.dirname(confPath); } catch (e) { - console.error(`\nFailed to read config '${confPath}'.\n ${e.message}.`); + console.error(`Failed to read config '${confPath}'.\nReason:\n ${e.message}\n`); proc.exit(1); } } diff --git a/conf.schema.json b/conf.schema.json index bca12a0f..3e676fae 100644 --- a/conf.schema.json +++ b/conf.schema.json @@ -4,10 +4,10 @@ "type": "object", "properties": { "baseDir": { - "description": "Path to directory where to search for the glossary file and markdown files. All paths in a config file will be relative to *baseDir*. *baseDir* itself is relative to the location of the config file or the current working directory when provided via command line. Default is '.'", + "description": "Path to directory where to search for the glossary file and markdown files. All paths in a config file will be relative to *baseDir*. *baseDir* itself is relative to the location of the config file or the current working directory when provided via command line.", "type": "string", "alias": "d", - "default": "." + "default": "./src" }, "baseUrl": { "description": "The base url to use when creating absolute links to glossary.", @@ -23,7 +23,7 @@ "type": "string" }, "alias": "e", - "default": ["node_modules"] + "default": ["node_modules", ".git"] }, "glossaries": { "description": "An array of glossaries. Allows for different kinds of glossaries and definitions.", @@ -52,7 +52,7 @@ "default": [] }, "includeFiles": { - "description": "Path or glob patterns of files to include for linking to glossaries. Default '.' (relative to current working directory).", + "description": "Path or glob patterns of files to include for linking to glossaries.", "type": "array", "items": { "type": "string" @@ -61,7 +61,7 @@ "default": ["."] }, "linking": { - "description": "Whether to use relative or absolute links. Default: 'relative'. Choosing 'absolute' requires a 'baseUrl'.", + "description": "Whether to use relative or absolute links. Choosing 'absolute' requires a 'baseUrl'.", "type": "string", "enum": [ "relative", @@ -71,10 +71,10 @@ "default": "relative" }, "outDir": { - "description": "Path to directory where to write processed files to. Default: './tmp'", + "description": "Path to directory where to write processed files to.", "type": "string", "alias": "o", - "default": "./tmp" + "default": "./target" }, "dev": { "descriptions": "Options for testing and debugging",