diff --git a/.gitea/workflows/release.yaml b/.gitea/workflows/release.yaml index 3f6b1d8..3a1ffa5 100644 --- a/.gitea/workflows/release.yaml +++ b/.gitea/workflows/release.yaml @@ -50,19 +50,23 @@ jobs: run: | npm init -y - # 1. Update package.json to be a proper ESM module - # We point "main" and "types" to the expected generated location + # 1. Create a dynamic index.ts that exports everything from the subfolders + # This makes 'import { PisMapping } from "@owlboard/backend-data-contracts"' work. + find . -name "*.ts" | sed 's|^\./||; s|\.ts$||' | xargs -I {} echo "export * from './{}';" > index.ts + + # 2. Update package.json + # We point main/types to the root dist/index file we are about to create jq '.name = "@owlboard/backend-data-contracts" | .version = "${{ steps.get_version.outputs.VERSION }}" | .type = "module" | - .main = "./dist/rail_backend/v1/pis_mapping.js" | - .types = "./dist/rail_backend/v1/pis_mapping.d.ts" | + .main = "./dist/index.js" | + .types = "./dist/index.d.ts" | .publishConfig = { "registry": "https://git.fjla.uk/api/packages/owlboard/npm" }' \ package.json > temp.json && mv temp.json package.json - # 2. Compile all TS files found in any subdirectories - # Using '**/*.ts' allows tsc to find the nested files - npx tsc **/*.ts --declaration --module esnext --target es2022 --moduleResolution node --outDir dist/ + # 3. Compile using the created index.ts as the entry point + # tsc will automatically follow the imports in index.ts and find the nested files + npx tsc index.ts --declaration --module esnext --target es2022 --moduleResolution node --outDir dist/ npm publish env: