mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-04-22 06:09:14 +00:00
refactor: change function of put es templates
This commit is contained in:
30
src/cli.ts
30
src/cli.ts
@@ -20,6 +20,7 @@ import {resolve} from 'path';
|
||||
import {exit} from 'process';
|
||||
import {generateTemplate} from './mapping';
|
||||
import {getProjectReflection} from './project-reflection';
|
||||
import {ElasticsearchTemplateCollection} from './types/mapping';
|
||||
|
||||
// handle unhandled promise rejections
|
||||
process.on('unhandledRejection', async (reason: unknown) => {
|
||||
@@ -81,38 +82,31 @@ commander
|
||||
// tslint:disable-next-line:no-magic-numbers
|
||||
writeFileSync(errPath, JSON.stringify(result.errors, null, 2));
|
||||
Logger.ok(`Mapping errors written to ${errPath}.`);
|
||||
} else {
|
||||
for (const error of result.errors) {
|
||||
await Logger.error(error);
|
||||
}
|
||||
|
||||
throw new Error('Mapping generation failed');
|
||||
}
|
||||
});
|
||||
|
||||
commander
|
||||
.command('put-es-templates <srcPath> <esAddress> [ignoredTags]')
|
||||
.action(async (relativeSrcPath, esAddress, ignoredTags) => {
|
||||
.action(async (relativeSrcPath, esAddress) => {
|
||||
// get absolute paths
|
||||
const srcPath = resolve(relativeSrcPath);
|
||||
|
||||
let ignoredTagsList: string[] = [];
|
||||
if (typeof ignoredTags === 'string') {
|
||||
ignoredTagsList = ignoredTags.split(',');
|
||||
}
|
||||
|
||||
// get project reflection
|
||||
const projectReflection = getProjectReflection(srcPath);
|
||||
const templates = JSON.parse(srcPath) as ElasticsearchTemplateCollection;
|
||||
|
||||
const result = generateTemplate(projectReflection, ignoredTagsList, true);
|
||||
if (result.errors.length !== 0) {
|
||||
await Logger.error(`Mapping generated with errors:\n${JSON.stringify(result.errors)}`);
|
||||
exit(-1);
|
||||
} else {
|
||||
Logger.ok('Mapping generated without errors!');
|
||||
}
|
||||
|
||||
for (const template in result.mappings) {
|
||||
if (!result.mappings.hasOwnProperty(template)) {
|
||||
for (const template in templates) {
|
||||
if (!templates.hasOwnProperty(template)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const response = await got.put(`${esAddress}_template/${template}`, {
|
||||
json: result.mappings[template],
|
||||
json: templates[template],
|
||||
});
|
||||
|
||||
const HTTP_STATUS_OK = 200;
|
||||
|
||||
Reference in New Issue
Block a user