mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-01-20 08:33:11 +00:00
refactor: revert json schema changes
This commit is contained in:
@@ -40,7 +40,7 @@ export function transformProject(project: JSONSchema7) {
|
||||
};
|
||||
}
|
||||
|
||||
export const OPTIONS: GeneratorOptions = {
|
||||
const OPTIONS: GeneratorOptions = {
|
||||
template: {
|
||||
name: 'template_{_type}',
|
||||
index_patterns: 'stapps_{_type}*',
|
||||
|
||||
@@ -1,48 +1,5 @@
|
||||
import {OPTIONS, transformProject} from './generator/index.js';
|
||||
import {transformProject} from './generator/index.js';
|
||||
import {SchemaConsumer} from '@openstapps/json-schema-generator';
|
||||
import {Plugin} from 'esbuild';
|
||||
// eslint-disable-next-line unicorn/import-style
|
||||
import {dirname} from 'path';
|
||||
import {MappingGenerator} from './generator/mapping-generator.js';
|
||||
|
||||
export const esbuildElasticsearchMappingPlugin: Plugin = {
|
||||
name: 'elasticsearch-mappings',
|
||||
setup(build) {
|
||||
const fileRegex = /^elasticsearch:/;
|
||||
const namespace = 'elasticsearch-mappings-ns';
|
||||
const mappings = new Map<string, string>();
|
||||
|
||||
build.onResolve({filter: fileRegex}, async ({path, importer}) => {
|
||||
const [from, name] = path.replace(fileRegex, '').split('#', 2);
|
||||
|
||||
return {
|
||||
path: `${
|
||||
from
|
||||
? await build
|
||||
.resolve(from, {resolveDir: dirname(importer), kind: 'import-statement'})
|
||||
.then(it => it.path)
|
||||
: importer
|
||||
}#${name}`,
|
||||
namespace,
|
||||
};
|
||||
});
|
||||
|
||||
build.onLoad({filter: /.*/, namespace}, async ({path}) => {
|
||||
if (!mappings.has(path)) {
|
||||
const result = await build.resolve(`schema:${path}`, {kind: 'import-statement'});
|
||||
console.log(result);
|
||||
const context = new MappingGenerator(result.pluginData.schema, OPTIONS);
|
||||
const name = path.split('#', 2)[1];
|
||||
|
||||
mappings.set(path, JSON.stringify(context.buildTemplate(name)));
|
||||
}
|
||||
return {
|
||||
contents: mappings.get(path),
|
||||
loader: 'json',
|
||||
};
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
* JSON Schema Generator plugin for Elasticsearch Mappings
|
||||
|
||||
Reference in New Issue
Block a user