mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-03-11 17:23:41 +00:00
feat: migrate to esm
This commit is contained in:
@@ -13,21 +13,20 @@
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import {Logger} from '@openstapps/logger';
|
||||
import {Command} from 'commander';
|
||||
import {mkdirSync, readFileSync, writeFileSync} from 'fs';
|
||||
import got from 'got';
|
||||
import path from 'path';
|
||||
import {exit} from 'process';
|
||||
import {generateTemplate} from './mapping';
|
||||
import {getProjectReflection} from './project-reflection';
|
||||
import {ElasticsearchTemplateCollection} from './types/mapping';
|
||||
import {generateTemplate} from './mapping.js';
|
||||
import {getProjectReflection} from './project-reflection.js';
|
||||
import {ElasticsearchTemplateCollection} from './types/mapping.js';
|
||||
|
||||
// handle unhandled promise rejections
|
||||
process.on('unhandledRejection', async (reason: unknown) => {
|
||||
if (reason instanceof Error) {
|
||||
await Logger.error(reason.message);
|
||||
Logger.info(reason.stack);
|
||||
await console.error(reason.message);
|
||||
console.info(reason.stack);
|
||||
}
|
||||
process.exit(1);
|
||||
});
|
||||
@@ -57,9 +56,9 @@ commander
|
||||
|
||||
const result = generateTemplate(projectReflection, ignoredTagsList, true);
|
||||
if (result.errors.length > 0) {
|
||||
await Logger.error('Mapping generated with errors!');
|
||||
await console.error('Mapping generated with errors!');
|
||||
} else {
|
||||
Logger.ok('Mapping generated without errors!');
|
||||
console.log('Mapping generated without errors!');
|
||||
}
|
||||
|
||||
// write documentation to file
|
||||
@@ -68,24 +67,24 @@ commander
|
||||
mkdirSync(path.dirname(aggPath), {recursive: true});
|
||||
// tslint:disable-next-line:no-magic-numbers
|
||||
writeFileSync(aggPath, JSON.stringify(result.aggregations, null, 2));
|
||||
Logger.ok(`Elasticsearch aggregations written to ${aggPath}.`);
|
||||
console.log(`Elasticsearch aggregations written to ${aggPath}.`);
|
||||
}
|
||||
if (typeof options.mappingPath !== 'undefined') {
|
||||
const mappingPath = path.resolve(options.mappingPath);
|
||||
mkdirSync(path.dirname(mappingPath), {recursive: true});
|
||||
// tslint:disable-next-line:no-magic-numbers
|
||||
writeFileSync(mappingPath, JSON.stringify(result.mappings, null, 2));
|
||||
Logger.ok(`Elasticsearch mappings written to ${mappingPath}.`);
|
||||
console.log(`Elasticsearch mappings written to ${mappingPath}.`);
|
||||
}
|
||||
if (typeof options.errorPath !== 'undefined') {
|
||||
const errorPath = path.resolve(options.errorPath);
|
||||
mkdirSync(path.dirname(errPath), {recursive: true});
|
||||
// tslint:disable-next-line:no-magic-numbers
|
||||
writeFileSync(errorPath, JSON.stringify(result.errors, null, 2));
|
||||
Logger.ok(`Mapping errors written to ${errorPath}.`);
|
||||
console.log(`Mapping errors written to ${errorPath}.`);
|
||||
} else if (result.errors.length > 0) {
|
||||
for (const error of result.errors) {
|
||||
await Logger.error(error);
|
||||
await console.error(error);
|
||||
}
|
||||
|
||||
throw new Error('Mapping generation failed');
|
||||
@@ -113,14 +112,14 @@ commander
|
||||
|
||||
const HTTP_STATUS_OK = 200;
|
||||
if (response.statusCode !== HTTP_STATUS_OK) {
|
||||
await Logger.error(
|
||||
await console.error(
|
||||
`Template for "${template}" failed in Elasticsearch:\n${JSON.stringify(response.body)}`,
|
||||
);
|
||||
exit(-1);
|
||||
}
|
||||
}
|
||||
|
||||
Logger.ok(`Templates accepted by Elasticsearch.`);
|
||||
console.log(`Templates accepted by Elasticsearch.`);
|
||||
});
|
||||
|
||||
commander.parse(process.argv);
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import {MappingProperty} from '@elastic/elasticsearch/lib/api/types';
|
||||
import {ElasticsearchFieldmap, SimpleType} from '../types/mapping';
|
||||
import {ElasticsearchFieldmap, SimpleType} from '../types/mapping.js';
|
||||
|
||||
const ducetSort = {
|
||||
type: 'icu_collation_keyword',
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import {MappingFloatNumberProperty} from '@elastic/elasticsearch/lib/api/types';
|
||||
import {ElasticsearchTypemap} from '../types/mapping';
|
||||
import {ElasticsearchTypemap} from '../types/mapping.js';
|
||||
|
||||
export const PARSE_ERROR = 'PARSE_ERROR' as MappingFloatNumberProperty['type'];
|
||||
export const MISSING_PREMAP = 'MISSING_PREMAP' as MappingFloatNumberProperty['type'];
|
||||
|
||||
@@ -33,12 +33,13 @@ import {
|
||||
TypeParameterType,
|
||||
UnionType,
|
||||
} from 'typedoc/dist/lib/models';
|
||||
import {fieldmap, filterableMap, filterableTagName} from './config/fieldmap';
|
||||
import {premaps} from './config/premap';
|
||||
import {settings} from './config/settings';
|
||||
import {dynamicTypes, isTagType, MISSING_PREMAP, PARSE_ERROR, TYPE_CONFLICT, typemap} from './config/typemap';
|
||||
import {AggregationSchema, ESNestedAggregation} from './types/aggregation';
|
||||
import {ElasticsearchTemplateCollection, MappingGenTemplate} from './types/mapping';
|
||||
import {fieldmap, filterableMap, filterableTagName} from './config/fieldmap.js';
|
||||
import {premaps} from './config/premap.js';
|
||||
import {settings} from './config/settings.js';
|
||||
import {dynamicTypes, isTagType, MISSING_PREMAP, PARSE_ERROR, TYPE_CONFLICT, typemap} from './config/typemap.js';
|
||||
import {AggregationSchema, ESNestedAggregation} from './types/aggregation.js';
|
||||
import {ElasticsearchTemplateCollection, MappingGenTemplate} from './types/mapping.js';
|
||||
import * as console from "console";
|
||||
|
||||
let dynamicTemplates: Record<string, MappingDynamicTemplate>[] = [];
|
||||
let errors: string[] = [];
|
||||
@@ -118,7 +119,7 @@ function composeErrorMessage(
|
||||
errors.push(error);
|
||||
if (showErrors) {
|
||||
// tslint:disable-next-line:no-floating-promises
|
||||
void Logger.error(error);
|
||||
void console.error(error);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -170,7 +171,7 @@ function getReflectionGeneric(
|
||||
properties: {},
|
||||
});
|
||||
|
||||
Logger.warn(
|
||||
console.warn(
|
||||
`Type "${type.name}": Defaults of generics (Foo<T = any>) currently don't work due to a bug` +
|
||||
` in TypeDoc. It has been replaced by a dynamic type.`,
|
||||
);
|
||||
@@ -808,16 +809,16 @@ export function generateTemplate(
|
||||
typeName = typeObject.type.reflection.defaultValue.replace('"', '').replace('"', '');
|
||||
} else {
|
||||
// tslint:disable-next-line:no-floating-promises
|
||||
void Logger.error(
|
||||
void console.error(
|
||||
'Your input files seem to be incorrect, or there is a major bug in the mapping generator.',
|
||||
);
|
||||
}
|
||||
} else if (typeObject.type instanceof StringLiteralType) {
|
||||
Logger.warn(`The interface ${_interface.name} uses a string literal as type, please use SCThingType.`);
|
||||
console.warn(`The interface ${_interface.name} uses a string literal as type, please use SCThingType.`);
|
||||
typeName = typeObject.type.value;
|
||||
} else {
|
||||
// tslint:disable-next-line:no-floating-promises
|
||||
void Logger.error(
|
||||
void console.error(
|
||||
`The interface ${_interface.name} is required to use an SCThingType as a type, please do so.`,
|
||||
);
|
||||
}
|
||||
@@ -858,16 +859,16 @@ export function generateTemplate(
|
||||
typeName = typeObject.type.reflection.defaultValue.replace('"', '').replace('"', '');
|
||||
} else {
|
||||
// tslint:disable-next-line:no-floating-promises
|
||||
void Logger.error(
|
||||
void console.error(
|
||||
'Your input files seem to be incorrect, or there is a major bug in the mapping generator.',
|
||||
);
|
||||
}
|
||||
} else if (typeObject.type instanceof StringLiteralType) {
|
||||
Logger.warn(`The interface ${_interface.name} uses a string literal as type, please use SCThingType.`);
|
||||
console.warn(`The interface ${_interface.name} uses a string literal as type, please use SCThingType.`);
|
||||
typeName = typeObject.type.value;
|
||||
} else {
|
||||
// tslint:disable-next-line:no-floating-promises
|
||||
void Logger.error(
|
||||
void console.error(
|
||||
`The interface ${_interface.name} is required to use an SCThingType as a type, please do so.`,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -12,12 +12,10 @@
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import {Logger} from '@openstapps/logger';
|
||||
import {existsSync, PathLike} from 'fs';
|
||||
import {platform} from 'os';
|
||||
import path from 'path';
|
||||
import {Application, ProjectReflection} from 'typedoc';
|
||||
import {ModuleKind, ScriptTarget} from 'typescript';
|
||||
|
||||
/**
|
||||
* Get a project reflection from a path
|
||||
@@ -26,7 +24,7 @@ import {ModuleKind, ScriptTarget} from 'typescript';
|
||||
* @param excludeExternals Exclude external dependencies
|
||||
*/
|
||||
export function getProjectReflection(sourcePath: PathLike, excludeExternals = true): ProjectReflection {
|
||||
Logger.info(`Generating project reflection for ${sourcePath.toString()}.`);
|
||||
console.info(`Generating project reflection for ${sourcePath.toString()}.`);
|
||||
|
||||
const tsconfigPath = getTsconfigPath(sourcePath.toString());
|
||||
|
||||
@@ -37,8 +35,6 @@ export function getProjectReflection(sourcePath: PathLike, excludeExternals = tr
|
||||
excludeExternals: excludeExternals,
|
||||
ignoreCompilerErrors: true,
|
||||
includeDeclarations: true,
|
||||
module: ModuleKind.CommonJS,
|
||||
target: ScriptTarget.Latest,
|
||||
tsconfig: path.join(tsconfigPath, 'tsconfig.json'),
|
||||
});
|
||||
|
||||
@@ -85,7 +81,7 @@ export function getTsconfigPath(startPath: string): string {
|
||||
tsconfigPath = tsconfigPathParts.join(path.sep);
|
||||
}
|
||||
|
||||
Logger.info(`Using 'tsconfig.json' from ${tsconfigPath}.`);
|
||||
console.info(`Using 'tsconfig.json' from ${tsconfigPath}.`);
|
||||
|
||||
return tsconfigPath;
|
||||
}
|
||||
|
||||
0
packages/es-mapping-generator/src/types/mapping.d.ts
vendored
Normal file
0
packages/es-mapping-generator/src/types/mapping.d.ts
vendored
Normal file
Reference in New Issue
Block a user