Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add quicktype tool #60

Merged
merged 3 commits into from
Sep 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions generate-event-registry.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ fi

echo "Building event registry generator"
# Note: the command line flags here are all to just produce minimal output unless there's a problem
dotnet build -nologo -clp:NoSummary -v quiet tools/Google.Events.Tools.GenerateRegistry
dotnet build -nologo -clp:NoSummary -v quiet tools/registry/Google.Events.Tools.GenerateRegistry

echo "Running event registry generator"
# Command line arguments to the registry generator:
# - Path to the protobuf file descriptor set (created in compile.sh)
# - Path to the README.md to update
dotnet run --no-build -p tools/Google.Events.Tools.GenerateRegistry \
dotnet run --no-build -p tools/registry/Google.Events.Tools.GenerateRegistry \
-- $PROTO_DESCRIPTOR_SET README.md
4 changes: 3 additions & 1 deletion proto/google/events/cloud/audit/v1/schema.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{
"$schema": "http://json-schema.org/schema",
"title": "google.events.cloud.audit.v1",
"$id": "google.events.cloud.audit.v1",
"title": "Cloud Audit Log LogEntry v1",
"name": "LogEntryData",
"goPackage": "auditv1",
"properties": {
"AuditLogWrittenEvent": {
Expand Down
4 changes: 3 additions & 1 deletion proto/google/events/cloud/pubsub/v1/schema.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{
"$schema": "http://json-schema.org/schema",
"title": "google.events.cloud.pubsub.v1",
"$id": "google.events.cloud.pubsub.v1",
"title": "Cloud Pub/Sub Message v1",
"name": "MessagePublishedData",
"goPackage": "pubsubv1",
"properties": {
"MessagePublishedEvent": {
Expand Down
8 changes: 7 additions & 1 deletion tools/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,16 @@ build and run, this is purely incidental. Pull requests to rewrite
the tools in languages more commonly used at Google (e.g. Java, Go
or Python) are welcome.

## Google.Events.Tools.GenerateRegistry
## registry

This tool edits the top-level [README](../README.md) to maintain the
event registry. It requires that the protobuf descriptor set (a
protobuf representation of all the .proto files) is already
compiled via protoc. (The [root compile.sh script](../compile.sh)
does this.)

## quicktype-wrapper

This tool wraps the quicktype tool to generate code using JSON Schema.

See [`quicktype-wrapper/`](./quicktype-wrapper/README.md).
3 changes: 3 additions & 0 deletions tools/quicktype-wrapper/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "./node_modules/gts/"
}
3 changes: 3 additions & 0 deletions tools/quicktype-wrapper/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

node_modules
build/
3 changes: 3 additions & 0 deletions tools/quicktype-wrapper/.prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
...require('gts/.prettierrc.json')
}
57 changes: 57 additions & 0 deletions tools/quicktype-wrapper/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# quicktype-wrapper

This node module that wraps the `quicktype` tool to generate code using JSON Schema.

## Install

This tool can be installed as a global CLI or run as a Node script. Requires Node 8+.

### CLI (Recommended)

Install the CLI globally:

```sh
npm run cli
```

This will install a `qt` CLI globally.

### RunNode Script

You can also run as a script. Build then run:

```sh
npm run compile
npm run start
```

## Configure

To configure the script, set required environment variables. (Command-line flags aren't supported yet.)

Here's an example:

```sh
IN=~/Documents/github/googleapis/google-cloudevents/proto
OUT=~/Documents/out
L=typescript
```

Then run `qt`, which will pick up these environment variables.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, I find it odd to use environment variables rather than command line arguments, but maybe that's just a Node convention.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will create a GitHub issue.


## Develop/Watch

To continually watch the script insead of building after every change,
run this command in a separate terminal:

```sh
npm run watch
```

## Lint/Fix

To fix style/lint mistakes in this generator, run:

```sh
npm run fix
```
Loading