diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index bd53ded..6d2eca7 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -21,6 +21,7 @@ jobs: google-ads-api-version: ${{ needs.export-google-ads-api-version.outputs.google-ads-api-version }} test: false build: true + import-suffix: .js publish: name: Publish diff --git a/.github/workflows/template.yml b/.github/workflows/template.yml index 7491ccd..c86b34f 100644 --- a/.github/workflows/template.yml +++ b/.github/workflows/template.yml @@ -21,6 +21,11 @@ on: required: false type: boolean default: false + import-suffix: + description: 'ts-proto will emit file imports using the specified suffix' + required: false + type: string + default: '' jobs: generate: @@ -44,7 +49,7 @@ jobs: run: yarn install --prefer-offline - name: Generate google ads api from protos - run: yarn generate ${{ inputs.google-ads-api-version }} + run: yarn generate ${{ inputs.google-ads-api-version }} ${{ inputs.import-suffix }} - name: Test if: ${{ inputs.test }} diff --git a/scripts/generate.sh b/scripts/generate.sh index 6cf74ca..dcfd2b5 100755 --- a/scripts/generate.sh +++ b/scripts/generate.sh @@ -2,8 +2,10 @@ version=$1 +importSuffix=$2 + if [ -z "$version" ]; then - echo "Version is required! Usage: generate.sh v13" + echo "Version is required! Usage: generate.sh v17" exit 1 fi @@ -27,18 +29,19 @@ mkdir -p $outdir echo 'Generating Protobuf files' +ts_proto_opts="forceLong=string,snakeToCamel=false,useOptionals=all,useAbortSignal=true,useExactTypes=false,esModuleInterop=true" + +if [ -n "$importSuffix" ]; then + ts_proto_opts="$ts_proto_opts,importStyle=commonjs,importSuffix=$importSuffix" +fi + +ts_proto_opts="$ts_proto_opts,outputServices=generic-definitions,outputServices=grpc-js" + protoc --plugin=./node_modules/.bin/protoc-gen-ts_proto \ --experimental_allow_proto3_optional \ --proto_path $path \ --ts_proto_out=$outdir \ - --ts_proto_opt=forceLong=string \ - --ts_proto_opt=snakeToCamel=false \ - --ts_proto_opt=useOptionals=all \ - --ts_proto_opt=useAbortSignal=true \ - --ts_proto_opt=useExactTypes=false \ - --ts_proto_opt=esModuleInterop=true \ - --ts_proto_opt=importSuffix=.js \ - --ts_proto_opt=outputServices=generic-definitions,outputServices=grpc-js \ + --ts_proto_opt=$ts_proto_opts \ $path/google/ads/googleads/$version/**/*.proto node scripts/export-client.js $outdir/google/ads/googleads/$version