feat: add automatic mapping generation

Fixes #6
This commit is contained in:
Anselm Stordeur
2019-02-05 14:54:52 +01:00
committed by Wieland Schöbl
parent 969badfb29
commit 7b198f95ce
13 changed files with 1267 additions and 78 deletions

View File

@@ -22,6 +22,7 @@ import {
readFilePromisified,
toArray,
} from './common';
import {generateTemplate} from './mapping';
import {pack} from './pack';
import {
gatherRouteInformation,
@@ -77,6 +78,30 @@ commander
Logger.ok(`Route documentation written to ${mdPath}.`);
});
commander
.command('mapping <srcPath> <destPath> [ignoredTags]')
.action(async (relativeSrcPath, relativeMappingPath, ignoredTags) => {
// get absolute paths
const srcPath = resolve(relativeSrcPath);
const mappingPath = resolve(relativeMappingPath);
let ignoredTagsList: string[] = [];
if (typeof ignoredTags === 'string') {
ignoredTagsList = ignoredTags.split(',');
}
// get project reflection
const projectReflection = getProjectReflection(srcPath);
const mapping = generateTemplate(projectReflection, ignoredTagsList);
// write documentation to file
// tslint:disable-next-line:no-magic-numbers
writeFileSync(mappingPath, JSON.stringify(mapping.template, null, 2));
Logger.ok(`Elasticsearch mapping written to ${mappingPath}.`);
});
commander
.command('schema <srcPath> <schemaPath>')
.action(async (relativeSrcPath, relativeSchemaPath) => {