Skip to content

Commit

Permalink
refactor: deprecate index.bzl
Browse files Browse the repository at this point in the history
  • Loading branch information
thesayyn committed Sep 27, 2023
1 parent 37feb71 commit 6066bd8
Show file tree
Hide file tree
Showing 53 changed files with 4,978 additions and 3,326 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Release
on:
push:
tags:
- "*.*.*"
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
with:
node-version: '20.x'
registry-url: 'https://registry.npmjs.org'
- run: npm ci
- run: bazel build package
- run: rsync --copy-links --recursive --times --group --no-perms --chmod=ugo=rwX ./bazel-bin/package/package/ ./tmp_pkg
- run: npm version ${{ github.ref_name }}
working-directory: ./tmp_pkg
- run: npm publish --dry-run
working-directory: ./tmp_pkg
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_RELEASE_TOKEN }}
8 changes: 4 additions & 4 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
node_version: [14.x, 16.x]
node_version: [16.x, 20.x]
protoc_version: [3.x]
folder:
- '.'
- 'examples/grpc'
- 'examples/pure'

steps:
Expand Down Expand Up @@ -54,10 +55,9 @@ jobs:
if: ${{ matrix.os != 'windows-latest' }}
- name: install dependencies
run: yarn --frozen-lockfile
run: npm ci
working-directory: ${{ matrix.folder }}
if: ${{ matrix.folder != '.' }}

- name: test
run: yarn test --test_tag_filters=-no-${{ matrix.os }}
run: npm test -- --test_tag_filters=-no-${{ matrix.os }}
working-directory: ${{ matrix.folder }}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ bazel-*

.DS_Store
user.bazelrc

tmp_pkg
23 changes: 4 additions & 19 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,31 +1,16 @@
load("@build_bazel_rules_nodejs//:index.bzl", "pkg_npm")
load("@bazel_gazelle//:def.bzl", "gazelle")

package(default_visibility = ["//visibility:public"])
exports_files(["README.md"])

# gazelle:prefix github.com/thesayyn/protoc-gen-ts
gazelle(name = "gazelle")

gazelle(
name = "gazelle-update-repos",
args = [
"-from_file=go.mod",
"-to_macro=deps.bzl%go_dependencies",
"-from_file=private/go.mod",
"-to_macro=private/deps.bzl%go_dependencies",
"-prune",
],
command = "update-repos",
)

pkg_npm(
name = "package",
package_name = "protoc-gen-ts",
srcs = [
"README.md",
"index.bzl",
"package.json",
"//bin:protoc-gen-ts.js",
],
deps = [
"//src:pkg",
],
)
)
45 changes: 15 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,13 @@

Compile `.proto` files to plain TypeScript. Supports gRPC Node and gRPC Web.

## Key Differences
## Usage

- No `d.ts` files. Just plain typescript sources with actual code.
- Fields as **getter** **setters**.
- Enums as **enums**.
- Messages within a **namespace** if the proto has a **package** directive. (can be controlled via --ts_opt=no_namespace)
- **fromObject** and **toObject** methods to work with json data.
- Support for gRPC Node and gRPC Web.
- You get what you define in proto files. No such prefixes as "getField" or "getFieldList".
- Generates bindings with either as-is names (`message.field_name`) or JSON-compatible names (`message.fieldName`).
```properties
npm install -g protoc-gen-ts

protoc -I=sourcedir --ts_out=dist myproto.proto
```

## Example

Expand Down Expand Up @@ -97,37 +94,25 @@ const change = Change.fromObject({
console.log(change.author instanceof Author) // true
```


## Usage with `@grpc/grpc-js` or `grpc`

There is a seperate documentation for the usage of protoc-gen-ts along with either `@grpc/grpc-js` or `grpc`. By default
this generated gRPC interfaces will use `@grpc/grpc-js`.

Checkout [rpcs](docs/rpc.md).

## Usage

### Without Bazel
```properties
npm install -g protoc-gen-ts

protoc -I=sourcedir --ts_out=dist myproto.proto
```
### With Bazel
```py
# Add protoc-gen-ts to dependencies section of your package.json file.

load("@npm//protoc-gen-ts:index.bzl", "ts_proto_library")
## Key Differences

ts_proto_library(
name = "protos",
deps = [
":some_proto_library_target"
]
)
- No `d.ts` files. Just plain typescript sources with actual code.
- Fields as **getter** **setters**.
- Enums as **enums**.
- Messages within a **namespace** if the proto has a **package** directive. (can be controlled via --ts_opt=no_namespace)
- **fromObject** and **toObject** methods to work with json data.
- Support for gRPC Node and gRPC Web.
- You get what you define in proto files. No such prefixes as "getField" or "getFieldList".
- Generates bindings with either as-is names (`message.field_name`) or JSON-compatible names (`message.fieldName`).

# Checkout the examples/bazel directory for an example.
```

## Supported Options

Expand Down
11 changes: 5 additions & 6 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,13 @@ http_archive(
load("@build_bazel_rules_nodejs//:repositories.bzl", "build_bazel_rules_nodejs_dependencies")
build_bazel_rules_nodejs_dependencies()

load("@build_bazel_rules_nodejs//:index.bzl", "node_repositories", "yarn_install")
load("@build_bazel_rules_nodejs//:index.bzl", "node_repositories", "npm_install")
node_repositories(node_version = "16.3.0")

yarn_install(
npm_install(
name = "npm",
exports_directories_only = False,
package_json = "//:package.json",
yarn_lock = "//:yarn.lock",
package_lock_json = "//:package-lock.json",
)

load("@build_bazel_rules_nodejs//toolchains/cypress:cypress_repositories.bzl", "cypress_repositories")
Expand Down Expand Up @@ -74,8 +73,8 @@ http_archive(
load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies")
gazelle_dependencies()

load("//:deps.bzl", "go_dependencies")
# gazelle:repository_macro deps.bzl%go_dependencies
load("//private:deps.bzl", "go_dependencies")
# gazelle:repository_macro private/deps.bzl%go_dependencies
go_dependencies()


Expand Down
21 changes: 0 additions & 21 deletions bin/BUILD.bazel

This file was deleted.

2 changes: 0 additions & 2 deletions bin/protoc-gen-ts.js

This file was deleted.

3 changes: 3 additions & 0 deletions examples/grpc/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
dist
src/test.ts
48 changes: 0 additions & 48 deletions examples/grpc/BUILD.bazel

This file was deleted.

3 changes: 0 additions & 3 deletions examples/grpc/README.md

This file was deleted.

83 changes: 0 additions & 83 deletions examples/grpc/WORKSPACE

This file was deleted.

Loading

0 comments on commit 6066bd8

Please sign in to comment.