Adjust workflow for correct module generation
Some checks failed
Generate and Release Protos / release (push) Failing after 23s
Some checks failed
Generate and Release Protos / release (push) Failing after 23s
This commit is contained in:
@@ -40,31 +40,29 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
npm init -y
|
npm init -y
|
||||||
|
|
||||||
# 1. Create a dynamic index.ts using Namespace exports
|
# 1. Create the Namespaced index.ts from the FLAT files
|
||||||
# This converts 'rail_backend/v1/pis_mapping.ts'
|
# This turns 'rail_backend_v1_pis_mapping.ts' into 'RailBackendV1PisMapping'
|
||||||
# into 'export * as PisMapping from "./rail_backend/v1/pis_mapping";'
|
find . -maxdepth 1 -name "*.ts" -not -name "index.ts" | sed 's|^\./||; s|\.ts$||' | awk '{
|
||||||
# We use awk to handle the naming conversion (snake_case to PascalCase-ish)
|
split($0, parts, "_");
|
||||||
find . -name "*.ts" -not -name "index.ts" | sed 's|^\./||; s|\.ts$||' | awk -F'/' '{
|
namespace="";
|
||||||
name=$NF;
|
for (i in parts) {
|
||||||
gsub(/_/, "", name);
|
namespace = namespace toupper(substr(parts[i],1,1)) substr(parts[i],2);
|
||||||
printf "export * as %s from \"./%s\";\n", toupper(substr(name,1,1)) substr(name,2), $0
|
}
|
||||||
|
printf "export * as %s from \"./%s.js\";\n", namespace, $0
|
||||||
}' > index.ts
|
}' > index.ts
|
||||||
|
|
||||||
# 2. Update package.json
|
# 2. Update package.json
|
||||||
jq '.name = "@owlboard/backend-data-contracts" |
|
VERSION="${{ steps.get_version.outputs.VERSION }}"
|
||||||
.version = "${{ steps.get_version.outputs.VERSION }}" |
|
jq --arg ver "$VERSION" '.name = "@owlboard/backend-data-contracts" |
|
||||||
.type = "module" |
|
.version = $ver | .type = "module" | .main = "./dist/index.js" | .types = "./dist/index.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
|
package.json > temp.json && mv temp.json package.json
|
||||||
|
|
||||||
# 3. Compile
|
# 3. Compile (No tsconfig needed with these flags)
|
||||||
npx tsc index.ts --declaration --module esnext --target es2022 --moduleResolution node --outDir dist/
|
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
|
npm publish
|
||||||
env:
|
|
||||||
NODE_AUTH_TOKEN: ${{ secrets.PACKAGE_PUSH }}
|
|
||||||
|
|
||||||
- name: Publish Go
|
- name: Publish Go
|
||||||
run: |
|
run: |
|
||||||
|
|||||||
@@ -14,9 +14,8 @@ for file in $FILES; do
|
|||||||
# Get a clean name (e.g., data-ingress_pis-mapping)
|
# Get a clean name (e.g., data-ingress_pis-mapping)
|
||||||
clean_name=$(echo "${file#schemas/}" | sed 's/\//_/g' | sed 's/\.json//g')
|
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"
|
npx --yes json-schema-to-typescript "$file" > "gen/ts/${clean_name}.ts"
|
||||||
echo "export * from './${clean_name}.js';" >> gen/ts/index.ts
|
|
||||||
|
|
||||||
# Generate Go
|
# Generate Go
|
||||||
go-jsonschema -p models "$file" > "gen/go/models/${clean_name}.go"
|
go-jsonschema -p models "$file" > "gen/go/models/${clean_name}.go"
|
||||||
|
|||||||
Reference in New Issue
Block a user