Skip to content

Commit

Permalink
feat: glossarify-md --help
Browse files Browse the repository at this point in the history
fix: make default baseDir ./src rather than "." to prevent copying CWD to outDir.
fix: drop parameterless usage example from README.md.
  • Loading branch information
about-code committed Sep 15, 2019
1 parent 7ac3b60 commit 0084878
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 18 deletions.
17 changes: 7 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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",
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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`

Expand Down Expand Up @@ -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

Expand Down
17 changes: 16 additions & 1 deletion bin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
}
Expand Down
14 changes: 7 additions & 7 deletions conf.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand All @@ -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.",
Expand Down Expand Up @@ -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"
Expand All @@ -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",
Expand All @@ -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",
Expand Down

0 comments on commit 0084878

Please sign in to comment.