scripts/create-validators.js
/**
 * Create a standalone JS module including pre-compiled validation functions of
 * the core VDA 5050 JSON schemas that can be used without additional runtime
 * dependencies.
 *
 * @param vdaVersion the VDA 5050 specification version the schemas are related
 * to
 * @param moduleFormat generated JS module format, either "esm" or "commonjs"
 * (optional, default is "commonjs")
 */
Create a standalone JS module including pre-compiled validation functions of
the core VDA 5050 JSON schemas that can be used without additional runtime
dependencies.


Create a standalone JS module including pre - compiled validation functions of the core VDA 5050 JSON schemas that can be used without additional runtime dependencies .
async function createCoreValidators(vdaVersion, moduleFormat) {
    const moduleFile = "src/common/vda-5050-validators.js";
    const exportFolder = fse.mkdtempSync(path.join(os.tmpdir(), "vda-5050-schema-"));
    try {
        const config = require("../.vda-5050-cli.schema.config.json");
        await jsonSchemaToLang({ lang: "json", vda: vdaVersion, out: exportFolder, vda5050SchemaDir });
        const schemas = [];
        fse.readdirSync(exportFolder).forEach(file => {
            if (file !== "common.schema.json") {
                schemas.push(path.join(exportFolder, file));
            }
        });
        createValidators(
            schemas,
            [path.join(exportFolder, "common.schema.json")],
            moduleFile,
            moduleFormat);
        console.log(`Generated file '${moduleFile}' with ${schemas.length} validation functions.`);
    } finally {
        try {
            fse.removeSync(exportFolder);
        } catch { }
    }
}
async function createCoreValidators ( vdaVersion , moduleFormat ) { const moduleFile = "src/common/vda-5050-validators.js" ; const exportFolder = fse . mkdtempSync ( path . join ( os . tmpdir ( ) , "vda-5050-schema-" ) ) ; try { const config = require ( "../.vda-5050-cli.schema.config.json" ) ; await jsonSchemaToLang ( { lang : "json" , vda : vdaVersion , out : exportFolder , vda5050SchemaDir } ) ; const schemas = [ ] ; fse . readdirSync ( exportFolder ) . forEach ( file => { if ( file !== "common.schema.json" ) { schemas . push ( path . join ( exportFolder , file ) ) ; } } ) ; createValidators ( schemas , [ path . join ( exportFolder , "common.schema.json" ) ] , moduleFile , moduleFormat ) ; console . log ( ` ${ moduleFile } ${ schemas . length } ` ) ; } finally { try { fse . removeSync ( exportFolder ) ; } catch { } } }
Create a standalone JS module including pre-compiled validation functions of
 the core VDA 5050 JSON schemas that can be used without additional runtime
 dependencies.
Create a standalone JS module including pre - compiled validation functions of the core VDA 5050 JSON schemas that can be used without additional runtime dependencies .