Skip to content

Commit

Permalink
feat(markdown): list nested schemas in README
Browse files Browse the repository at this point in the history
  • Loading branch information
trieloff committed Dec 3, 2019
1 parent e521541 commit 87e8489
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 4 deletions.
15 changes: 13 additions & 2 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ const filterRefs = require('./lib/filterRefs');
const validate = require('./lib/validateSchemas');
const build = require('./lib/markdownBuilder');
const write = require('./lib/writeMarkdown');
const readme = require('./lib/readmeBuilder');
const formatInfo = require('./lib/formatInfo');

const { info, error, debug } = logger;

Expand Down Expand Up @@ -130,7 +132,6 @@ const metaElements = argv.m;
const schemaPath = argv.d;
const schemaDir = argv.x;
const target = fs.statSync(schemaPath);
const readme = !!argv.n;
const schemaExtension = argv.e;

// list all schema files in the specified directory
Expand All @@ -151,14 +152,24 @@ readdirp.promise(schemaPath, { root: schemaPath, fileFilter: `*.${schemaExtensio
// find contained schemas
map(traverse),
flat,

// remove pure ref schemas
filterRefs,

// format titles and descriptions
formatInfo({ extension: schemaExtension }),

// make a nice object
generate,

// generate Markdown ASTs
build,

// build readme
readme({
readme: !argv.n,
}),

// write to files

write({
Expand All @@ -170,5 +181,5 @@ readdirp.promise(schemaPath, { root: schemaPath, fileFilter: `*.${schemaExtensio
))

.then((schemas) => {
console.log('allschemas', schemas);
// console.log('allschemas', schemas);
});
3 changes: 1 addition & 2 deletions lib/generateName.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
*/
const { foldl } = require('ferrum');
const GithubSlugger = require('github-slugger');
const { formatname } = require('./formatname');

/**
* Turns a sequence of schemas into an object, using a human and
Expand All @@ -35,7 +34,7 @@ function generatenames(schemas) {

return foldl(schemas, {}, (container, schema) => {
const name = {};
name[slugger.slug(formatname(schema))] = schema;
name[slugger.slug(schema.title)] = schema;
return Object.assign(container, name);
});
}
Expand Down
3 changes: 3 additions & 0 deletions lib/traverseSchema.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ function traverse(node) {
direct: false,
pointer: `${pointer}/${key}/${index}`,
id,
root: schema,
// TODO add additional properties for tracking
})),
);
Expand All @@ -83,6 +84,7 @@ function traverse(node) {
direct: false,
pointer: `${pointer}/${key}/${subkey}`,
id,
root: schema,
// TODO add additional properties for tracking
})),
);
Expand All @@ -94,6 +96,7 @@ function traverse(node) {
direct: false,
pointer: `${pointer}/${key}`,
id,
root: schema,
// TODO add additional properties for tracking
}];
}
Expand Down
60 changes: 60 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@
"i18next": "^19.0.1",
"json-pointer": "^0.6.0",
"mdast-builder": "^1.1.1",
"mdast-util-to-string": "^1.0.7",
"mkdirp": "^0.5.1",
"readdirp": "^3.1.1",
"remark-parse": "^7.0.2",
"remark-stringify": "^7.0.4",
"unified": "^8.4.2",
"unist-builder": "^2.0.2",
Expand Down

0 comments on commit 87e8489

Please sign in to comment.