diff --git a/.gitea/workflows/release.yaml b/.gitea/workflows/release.yaml index 567897f..c119825 100644 --- a/.gitea/workflows/release.yaml +++ b/.gitea/workflows/release.yaml @@ -40,31 +40,29 @@ jobs: run: | npm init -y - # 1. Create a dynamic index.ts using Namespace exports - # This converts 'rail_backend/v1/pis_mapping.ts' - # into 'export * as PisMapping from "./rail_backend/v1/pis_mapping";' - # We use awk to handle the naming conversion (snake_case to PascalCase-ish) - find . -name "*.ts" -not -name "index.ts" | sed 's|^\./||; s|\.ts$||' | awk -F'/' '{ - name=$NF; - gsub(/_/, "", name); - printf "export * as %s from \"./%s\";\n", toupper(substr(name,1,1)) substr(name,2), $0 + # 1. Create the Namespaced index.ts from the FLAT files + # This turns 'rail_backend_v1_pis_mapping.ts' into 'RailBackendV1PisMapping' + find . -maxdepth 1 -name "*.ts" -not -name "index.ts" | sed 's|^\./||; s|\.ts$||' | awk '{ + split($0, parts, "_"); + namespace=""; + for (i in parts) { + namespace = namespace toupper(substr(parts[i],1,1)) substr(parts[i],2); + } + printf "export * as %s from \"./%s.js\";\n", namespace, $0 }' > index.ts # 2. Update package.json - jq '.name = "@owlboard/backend-data-contracts" | - .version = "${{ steps.get_version.outputs.VERSION }}" | - .type = "module" | - .main = "./dist/index.js" | - .types = "./dist/index.d.ts" | - .publishConfig = { "registry": "https://git.fjla.uk/api/packages/owlboard/npm" }' \ + VERSION="${{ steps.get_version.outputs.VERSION }}" + jq --arg ver "$VERSION" '.name = "@owlboard/backend-data-contracts" | + .version = $ver | .type = "module" | .main = "./dist/index.js" | .types = "./dist/index.d.ts"' \ package.json > temp.json && mv temp.json package.json - # 3. Compile - npx tsc index.ts --declaration --module esnext --target es2022 --moduleResolution node --outDir dist/ + # 3. Compile (No tsconfig needed with these flags) + npx tsc index.ts --declaration --module nodenext --target es2022 --moduleResolution nodenext --outDir dist/ --skipLibCheck true + # 4. Publish + npm config set //git.fjla.uk/api/packages/owlboard/npm/:_authToken ${{ secrets.PACKAGE_PUSH }} npm publish - env: - NODE_AUTH_TOKEN: ${{ secrets.PACKAGE_PUSH }} - name: Publish Go run: | diff --git a/scripts/build.sh b/scripts/build.sh index f177ec5..9e94393 100644 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -14,9 +14,8 @@ for file in $FILES; do # Get a clean name (e.g., data-ingress_pis-mapping) clean_name=$(echo "${file#schemas/}" | sed 's/\//_/g' | sed 's/\.json//g') - # Output to one folder and add to index + # OGenerate TS npx --yes json-schema-to-typescript "$file" > "gen/ts/${clean_name}.ts" - echo "export * from './${clean_name}.js';" >> gen/ts/index.ts # Generate Go go-jsonschema -p models "$file" > "gen/go/models/${clean_name}.go"