Skip to content

Commit 51009be

Browse files
committed
feat(cli): support for filter-regexp and mapFilename
1 parent 2505ad0 commit 51009be

File tree

4 files changed

+149
-12
lines changed

4 files changed

+149
-12
lines changed

packages/cli/README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,17 @@ Generate documentation for JSON schemas through a command line interface.
66
> - [**Charts, simple as a URL**. No more server-side rendering pain, 1 url = 1 chart](https://image-charts.com)
77
> - [Looking for a free **Redis GUI**?](http://redsmin.com) [Or for **real-time alerting** & monitoring for Redis?](http://redsmin.com)
88
9+
<!--
910
### Install (docker)
1011
11-
<!-- add a terminal gif here -->
12+
[add a terminal gif here
1213
1314
```bash
1415
docker run -it fgribreau/json-schema-documentation-cli
1516
```
1617
18+
-->
19+
1720
### Install (nodejs)
1821

1922
```bash

packages/cli/package-lock.json

Lines changed: 121 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/cli/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"json-schema-documentation-generator": "^1.1.0",
3333
"json-schema-documentation-sample-generator": "^1.1.0",
3434
"json-schema-documentation-theme-default": "^1.1.0",
35+
"slug": "^0.9.1",
3536
"yargs": "^10.0.3"
3637
},
3738
"engines": {

packages/cli/src/cli.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const path = require('path');
2+
const slug = require('slug');
23
const generator = require('json-schema-documentation-generator');
34

45
const argv = require('yargs')
@@ -34,6 +35,22 @@ argv
3435
}
3536
},
3637
})
38+
.option('mapFilename', {
39+
describe: 'Mapping function to change each schema filename',
40+
default: '(schema) => slug(schema.$id)',
41+
coerce: mapper => {
42+
const vm = require('vm');
43+
return new vm.Script(mapper);
44+
},
45+
})
46+
.option('filter-regexp', {
47+
describe: 'Only keep schemas where $id match the specified regexp',
48+
default: '.*',
49+
coerce: regexp => {
50+
const reg = new RegExp(regexp);
51+
return schema => reg.test(schema.$id);
52+
},
53+
})
3754
.option('sample', {
3855
default: 'json-schema-documentation-sample-generator',
3956
describe: 'JSON-schema sample generator',
@@ -71,6 +88,8 @@ generator({
7188
require(path.resolve(process.cwd(), filePath))
7289
),
7390

91+
filter: args.filterRegexp,
92+
7493
// (required) schema sample generator
7594
samples: {
7695
generator: args.sample,
@@ -85,6 +104,10 @@ generator({
85104
// (required) override this to specify another generator
86105
directory: {
87106
path: args.output,
107+
mapFilename: args.mapFilename.runInNewContext({
108+
path: path,
109+
slug: slug,
110+
}),
88111
},
89112
},
90113
},

0 commit comments

Comments
 (0)