This commit is contained in:
@@ -50,12 +50,17 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
npm init -y
|
npm init -y
|
||||||
|
|
||||||
# 1. Create a dynamic index.ts that exports everything from the subfolders
|
# 1. Create a dynamic index.ts using Namespace exports
|
||||||
# This makes 'import { PisMapping } from "@owlboard/backend-data-contracts"' work.
|
# This converts 'rail_backend/v1/pis_mapping.ts'
|
||||||
find . -name "*.ts" | sed 's|^\./||; s|\.ts$||' | xargs -I {} echo "export * from './{}';" > index.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
|
||||||
|
}' > index.ts
|
||||||
|
|
||||||
# 2. Update package.json
|
# 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" |
|
jq '.name = "@owlboard/backend-data-contracts" |
|
||||||
.version = "${{ steps.get_version.outputs.VERSION }}" |
|
.version = "${{ steps.get_version.outputs.VERSION }}" |
|
||||||
.type = "module" |
|
.type = "module" |
|
||||||
@@ -64,8 +69,7 @@ jobs:
|
|||||||
.publishConfig = { "registry": "https://git.fjla.uk/api/packages/owlboard/npm" }' \
|
.publishConfig = { "registry": "https://git.fjla.uk/api/packages/owlboard/npm" }' \
|
||||||
package.json > temp.json && mv temp.json package.json
|
package.json > temp.json && mv temp.json package.json
|
||||||
|
|
||||||
# 3. Compile using the created index.ts as the entry point
|
# 3. Compile
|
||||||
# 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/
|
npx tsc index.ts --declaration --module esnext --target es2022 --moduleResolution node --outDir dist/
|
||||||
|
|
||||||
npm publish
|
npm publish
|
||||||
|
|||||||
Reference in New Issue
Block a user