@@ -40,16 +40,35 @@ function compile_schemas() {
4040 " $KEYMAN_ROOT /common/schemas/keyboard_info/keyboard_info.schema.json"
4141 )
4242
43+ rm -rf " $THIS_SCRIPT_PATH /obj/schemas"
44+ mkdir -p " $THIS_SCRIPT_PATH /obj/schemas"
4345 rm -rf " $THIS_SCRIPT_PATH /src/schemas"
4446 mkdir -p " $THIS_SCRIPT_PATH /src/schemas"
4547 cp " ${schemas[@]} " " $THIS_SCRIPT_PATH /src/schemas/"
4648
4749 # TODO: use https://github.com/tc39/proposal-json-modules instead of this once it stablises
4850 for schema in " ${schemas[@]} " ; do
49- local fn=" $THIS_SCRIPT_PATH /src/schemas/$( basename " $schema " .json) "
51+ local schema_base=" $( basename " $schema " .json) "
52+ local fn=" $THIS_SCRIPT_PATH /src/schemas/$schema_base "
53+ local out=" $THIS_SCRIPT_PATH /obj/schemas/$schema_base .validator.cjs"
54+
55+ # emit a .ts wrapper for the schema file
56+
57+ builder_echo " Compiling schema $schema_base .json"
5058 echo ' export default ' > " $fn .ts"
5159 cat " $fn .json" >> " $fn .ts"
60+
61+ # emit a compiled validator for the schema file
62+
63+ # While would seem obvious to just run 'ajv' directly here, somewhere node
64+ # is picking up the wrong path for the build and breaking the formats
65+ # imports. So it is essential to use `npm run` at this point, even though it
66+ # is painfully slower, at least until we figure out the path discrepancy.
67+ npm run build:schema -- -c ./tools/formats.cjs -s " $fn .json" --strict-types false -o " $out "
5268 done
69+
70+ # the validators now need to be compiled to esm
71+ node tools/schema-bundler.js
5372}
5473
5574function copy_cldr_imports() {
0 commit comments