#
# This is the core snootobuf config.
# It drives the versions of external dependences, contains the go plugins, and proto checks.
# It's primarily executed by the gen-proto.sh script.
#
# See the schema at
# https://github.snooguts.net/reddit/snootobuf/blob/master/docs/jsonschema/Plugin.json.

checks:
  breaking_change:
    lock_branch: main
  
  linting:
    buf_raw_config:
      input_config:
        version: 'v1'
        lint:
          use:
            - BASIC
          ignore:
            - .snootobuf
        breaking:
          ignore_unstable_packages: true

remote_sources:
  - git: github.snooguts.net/reddit/cloudroutines/proto@v0.28.8
  
  - git: github.snooguts.net/reddit/devplatform-api/api/proto/devvit/dev_portal@v1.9.51 # for local development

dependencies:
  # production; this should probably be kept in sync with the identical
  # dependency in remote sources above?
  - git: github.snooguts.net/reddit/devplatform-api/api/proto@v1.9.51

# for local development
# - local_path: ../../../../../devplatform-api/api/proto
plugins:
  - well_known_spec:
      name: SPEC_NAME_GO
    outputs:
      - from: github.snooguts.net/reddit/reddit-devplatform-monorepo
        into: ../../..
  
  - well_known_spec:
      name: SPEC_NAME_GO_GRPC
    outputs:
      - from: github.snooguts.net/reddit/reddit-devplatform-monorepo
        into: ../../..
  
  - go: github.com/bufbuild/connect-go/cmd/protoc-gen-connect-go@v1.8.0
    outputs:
      - from: github.snooguts.net/reddit/reddit-devplatform-monorepo
        into: ../../..
  
  - name: protoc-gen-devvit
    path: ../../../go-common/cmd/protoc-gen-devvit/run.sh
    options:
      - skip=devvit.actor.test
      - skip=
    outputs:
      - into: ../../../go-common/generated
  
  - name: ts_proto_files
    # This is installed with a `yarn install` in the root of the monorepo.
    path: ../../../node_modules/.bin/protoc-gen-ts_proto
    options:
      - esModuleInterop=true
      - exportCommonSymbols=false
      - useOptionals=messages
      - metadataType=Metadata@./../lib/Types.js
      - outputServices=default
      - outputTypeAnnotations=static-only
      - outputTypeRegistry=no-tags
      - addGrpcMetadata=true
      - useExactTypes=false
      - outputServices=generic-definitions
      - useNumericEnumForJson=true
      - importSuffix=.js
    outputs:
      - into: ../src/types
  
  # JSON compatible typing of the above. Default values are nonoptional. Eg,
  # `type Foo = {bar: string}` not `type Foo = {bar?: string | undefined}`.
  # Enums are the only functional exports. See
  # https://protobuf.dev/programming-guides/json/.
  #
  # These outputs are designed to match the typing of the old `src/types`
  # messages hydrated with default values except for `NaN` and `Infinity`. eg,
  # `const foo: NewFoo = JSON.parse(JSON.stringify(OldFoo.fromJSON({})))`
  # assuming no `bytes` or `Duration` fields or a float field with `NaN` or
  # `Infinity` values.
  - name: ts_proto_json_files
    # This is installed with a `yarn install` in the root of the monorepo.
    path: ../../../node_modules/.bin/protoc-gen-ts_proto
    options:
      # Omit `export const protobufPackage = "devvit.actor.reddit";`.
      - exportCommonSymbols=false
      - useOptionals=messages
      - outputServices=none
      - importSuffix=.js
      - onlyTypes=true
      - useDate=string
      - useDuration=string # Broken. Patched in cleanup script.
    outputs:
      - into: ../src/json
  
  - name: twirp_files
    # This is installed with a `yarn install` in the root of the monorepo.
    path: ../../../node_modules/.bin/protoc-gen-twirp_ts
    options:
      - ts_proto,standalone
    outputs:
      - into: ../src/types
