diff --git a/resources/standards-data/ldml-keyboards/45/fetch-latest-cldr.sh b/resources/standards-data/ldml-keyboards/fetch-latest-cldr.sh old mode 100755 new mode 100644 similarity index 53% rename from resources/standards-data/ldml-keyboards/45/fetch-latest-cldr.sh rename to resources/standards-data/ldml-keyboards/fetch-latest-cldr.sh index e12c8f8cbc..7234c69fb9 --- a/resources/standards-data/ldml-keyboards/45/fetch-latest-cldr.sh +++ b/resources/standards-data/ldml-keyboards/fetch-latest-cldr.sh @@ -7,25 +7,43 @@ set -eu -if [[ $# -ne 1 ]]; +if [[ $# -ne 2 ]]; then - echo >&2 "Usage: $0 " + echo >&2 "Usage: $0 " exit 1 fi ## START STANDARD BUILD SCRIPT INCLUDE # adjust relative paths as necessary THIS_SCRIPT="$(readlink -f "${BASH_SOURCE[0]}")" -. "${THIS_SCRIPT%/*}/../../../../resources/build/build-utils.sh" +. "${THIS_SCRIPT%/*}/../../../resources/build/build-utils.sh" ## END STANDARD BUILD SCRIPT INCLUDE . "$KEYMAN_ROOT/resources/build/jq.inc.sh" cd "$THIS_SCRIPT_PATH" +KEYMAN_CORE_LDML="../../../core/include/ldml" + +builder_echo debug "Building ${KEYMAN_CORE_LDML}" + +"${KEYMAN_CORE_LDML}/build.sh" || builder_die "building core/include/ldml failed" + +KEYMAN_CORE_LDML_JS="${KEYMAN_CORE_LDML}/build/keyman_core_ldml.js" + +if [ ! -f "${KEYMAN_CORE_LDML_JS}" ]; +then + builder_die "Could not read ${KEYMAN_CORE_LDML_JS} - check build." +fi + +CLDR_VERSION="$1" +shift + CLDR_DIR="$1" shift +node verify-version.mjs "${CLDR_VERSION}" || builder_die "Check CLDR version" + KEYBOARDS_DIR="${CLDR_DIR}/keyboards" DTD_DIR="${KEYBOARDS_DIR}/dtd" IMPORT_DIR="${KEYBOARDS_DIR}/import" @@ -51,8 +69,15 @@ GIT_DESCRIBE=$(cd "${CLDR_DIR}" && git describe HEAD || echo unknown) GIT_SHA=$(cd "${CLDR_DIR}" && git rev-parse HEAD || echo unknown) NOW=$(date -u -R) -echo "${CLDR_DIR}" - "${GIT_DESCRIBE}" - "${GIT_SHA}" -echo "---" + +builder_echo heading "Ready to copy v${CLDR_VERSION} from ${CLDR_DIR}" +builder_echo debug "${GIT_DESCRIBE} - ${GIT_SHA}" + +mkdir -pv "${CLDR_VERSION}" + +cd "${CLDR_VERSION}" + +pwd # delete the old files in case some were removed from CLDR rm -rf ./import ./3.0 ./dtd ./test @@ -64,19 +89,32 @@ rm -vf dtd/{ldmlKeyboard,ldmlPlatform}.{xsd,dtd} echo "{\"sha\": \"${GIT_SHA}\",\"description\":\"${GIT_DESCRIBE}\",\"date\":\"${NOW}\"}" | ${JQ} . | tee cldr_info.json -echo "Updated cldr_info.json" +builder_echo "Updated cldr_info.json" -echo "Converting XSD to JSON…" +builder_echo heading "Converting XSD to JSON…" for xsd in dtd/*.xsd; do base=$(basename "${xsd}" .xsd | tr A-Z a-z | sed -e 's%^ldml%ldml-%g' ) json=${base}.schema.json - echo "${xsd} -> ${json}" - (cd .. ; npx -p jgexml xsd2json 45/"${xsd}" 45/"${json}") || exit - echo 'fixup-schema.js' "${json}" - node fixup-schema.js "${json}" || builder_die "failed to fixup schema ${json}" + builder_echo debug "${xsd} -> ${json}" + (cd .. ; npx -p jgexml xsd2json ${CLDR_VERSION}/"${xsd}" ${CLDR_VERSION}/"${json}") || exit + builder_echo debug 'fixup-schema.js' "${json}" + node ../fixup-schema.js "${json}" || builder_die "failed to fixup schema ${json}" mv "${json}" tmp.json ${JQ} . -S < tmp.json > "${json}" || (rm tmp.json ; builder_die "failed to transform final schema ${json}") rm tmp.json done + +# verify that the CLDR version we just converted is the requested version. +FOUND_VERSION=$(jq -r '.definitions.version.properties.cldrVersion.enum[0]' < ldml-keyboard3.schema.json) + +if [ ${FOUND_VERSION} -ne ${CLDR_VERSION} ]; +then + # It's a little late to cleanup more gracefully, but we can at least complain. + builder_die "You requested CLDR ${CLDR_VERSION} but the copied schema is for ${FOUND_VERSION} - something is wrong." +fi + +echo +builder_echo success "CLDR ${CLDR_VERSION} copied correctly from ${CLDR_DIR}" +echo diff --git a/resources/standards-data/ldml-keyboards/45/fixup-schema.js b/resources/standards-data/ldml-keyboards/fixup-schema.js similarity index 100% rename from resources/standards-data/ldml-keyboards/45/fixup-schema.js rename to resources/standards-data/ldml-keyboards/fixup-schema.js diff --git a/resources/standards-data/ldml-keyboards/readme.md b/resources/standards-data/ldml-keyboards/readme.md index aec3717571..22189fcfd6 100644 --- a/resources/standards-data/ldml-keyboards/readme.md +++ b/resources/standards-data/ldml-keyboards/readme.md @@ -2,6 +2,12 @@ Data is versioned, so each directory has its version such as `45`. +## How to Update + +- Checkout CLDR, preferably a release version, somewhere such as /src/cldr +- run `fetch-latest-cldr.sh 45 /src/cldr` (where '45' is the CLDR version) +- check results, run tests, check in and open a PR + ## Data Format Each directory contains: diff --git a/resources/standards-data/ldml-keyboards/verify-version.mjs b/resources/standards-data/ldml-keyboards/verify-version.mjs new file mode 100644 index 0000000000..0704155c93 --- /dev/null +++ b/resources/standards-data/ldml-keyboards/verify-version.mjs @@ -0,0 +1,12 @@ +import {constants} from '../../../core/include/ldml/build/keyman_core_ldml.js'; +import { argv } from 'node:process'; + +const args = argv.slice(2); +const { cldr_version_latest } = constants; +const ver = args[0]; + +if (cldr_version_latest !== ver) { + throw Error(`Requester CLDR version '${ver}' but cldr_version_latest is '${cldr_version_latest}' - check keyman_core_ldml.ts`); +} else { + console.log(`CLDR version ${ver} OK`); +}