11import chalk from 'chalk' ;
22import fs from 'fs' ;
33import { globSync } from 'glob' ;
4- import jsonschema from 'jsonschema' ;
4+ import { Validator } from 'jsonschema' ;
55import path from 'path' ;
66import shell from 'shelljs' ;
77import YAML from 'js-yaml' ;
@@ -21,6 +21,8 @@ const discardedSchema = require('../schemas/discarded.json');
2121
2222let _currBuild = null ;
2323
24+ const jsonschema = new Validator ( ) ;
25+
2426function validateData ( options ) {
2527 const START = '🔬 ' + chalk . yellow ( 'Validating schema...' ) ;
2628 const END = '👍 ' + chalk . green ( 'schema okay' ) ;
@@ -203,6 +205,9 @@ function read(f) {
203205
204206
205207function validateSchema ( file , instance , schema ) {
208+ // add this schema to the cache, so $ref can be resolved faster
209+ jsonschema . addSchema ( schema ) ;
210+
206211 let validationErrors = jsonschema . validate ( instance , schema ) . errors ;
207212
208213 if ( validationErrors . length ) {
@@ -362,6 +367,15 @@ function generatePresets(dataDir, tstrings, searchableFieldIDs, listReusedIcons)
362367 if ( ! icons [ icon ] ) icons [ icon ] = [ ] ;
363368 icons [ icon ] . push ( id ) ;
364369 }
370+
371+ if ( preset . relation ) {
372+ tstrings . presets [ id ] . relation_roles = { } ;
373+ for ( const member of preset . relation . members ) {
374+ for ( const role in member . roles ) {
375+ tstrings . presets [ id ] . relation_roles [ role ] = member . roles [ role ] ;
376+ }
377+ }
378+ }
365379 } ) ;
366380
367381 if ( listReusedIcons ) {
@@ -454,8 +468,10 @@ function generateTranslations(fields, presets, tstrings, searchableFieldIDs) {
454468 let tags = preset . tags || { } ;
455469 let keys = Object . keys ( tags ) ;
456470
471+ const tagsString = keys . map ( k => `${ k } =${ tags [ k ] } ` ) . join ( ' + ' ) ;
472+
457473 if ( keys . length ) {
458- yamlPreset [ '#name' ] = keys . map ( k => ` ${ k } = ${ tags [ k ] } ` ) . join ( ' + ' ) ;
474+ yamlPreset [ '#name' ] = tagsString ;
459475 if ( yamlPreset . aliases ) {
460476 yamlPreset [ '#name' ] += ' | ' + yamlPreset . aliases . split ( '\n' ) . join ( ', ' ) ;
461477 }
@@ -466,6 +482,12 @@ function generateTranslations(fields, presets, tstrings, searchableFieldIDs) {
466482 yamlPreset [ '#name' ] += ` | Local preset for countries ${ preset . locationSet . include . map ( country => `"${ country . toUpperCase ( ) } "` ) . join ( ', ' ) } ` ;
467483 }
468484
485+ if ( yamlPreset . relation_roles ) {
486+ for ( const role in yamlPreset . relation_roles ) {
487+ yamlPreset . relation_roles [ `#${ role } ` ] = `Relation role “${ role } ” when used with ${ tagsString } ` ;
488+ }
489+ }
490+
469491 if ( preset . searchable !== false ) {
470492 if ( yamlPreset . terms ) {
471493 yamlPreset [ '#terms' ] = 'terms: ' + yamlPreset . terms ;
0 commit comments