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(node-legacy): initial setup + version bumps #323

Merged
merged 3 commits into from
Nov 17, 2021
Merged
Show file tree
Hide file tree
Changes from 2 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
37 changes: 36 additions & 1 deletion .github/workflows/packages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:

- uses: actions/setup-node@v2
with:
node-version: "14.x"
node-version: "16.x"
registry-url: "https://npm.pkg.github.com"
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -61,6 +61,41 @@ jobs:
npm version $RELEASE_TAG
npm publish


node-legacy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- uses: actions/setup-node@v2
with:
node-version: "14.x"
registry-url: "https://npm.pkg.github.com"
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: npm ci
run: npm ci
working-directory: node-legacy

- name: make
run: make LANGUAGE=node-legacy

- name: Run node checks
run: npm run checks
working-directory: node-legacy

- name: npm publish
working-directory: node-legacy
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
RELEASE_TAG=${GITHUB_REF/refs\/tags\/v/}
echo $RELEASE_TAG
npm version $RELEASE_TAG
npm publish


go:
runs-on: ubuntu-latest
steps:
Expand Down
21 changes: 20 additions & 1 deletion .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:

- uses: actions/setup-node@v2
with:
node-version: "14.x"
node-version: "16.x"

- name: npm ci
run: npm ci
Expand All @@ -55,6 +55,25 @@ jobs:
run: npm run checks
working-directory: node

node-legacy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- uses: actions/setup-node@v2
with:
node-version: "14.x"

- name: npm ci
run: npm ci
working-directory: node-legacy

- run: make LANGUAGE=node-legacy

- name: Run node checks
run: npm run checks
working-directory: node-legacy

go:
runs-on: ubuntu-latest
steps:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
# node
node_modules
node/stroeer
node-legacy/stroeer
bin/protoc
*.tgz

Expand Down
8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
DIR = $(shell pwd)
JAVA_DIR = ./java/src/main/java
NODE_DIR = ./node
NODE_LEGACY_DIR = ./node-legacy
GO_DIR = ./gen/go
GATEWAY_DIR = ./gen/gateway

Expand All @@ -30,6 +31,13 @@ ifeq ($(LANGUAGE),node)
FLAGS += --js_out=import_style=commonjs,binary:$(OUTPUT)
FLAGS += --ts_out=service=grpc-node,mode=grpc-js:$(OUTPUT)
FLAGS += --grpc_out=grpc_js:$(OUTPUT)
else ifeq ($(LANGUAGE),node-legacy)
OUTPUT := $(NODE_LEGACY_DIR)
FLAGS += --plugin=protoc-gen-ts=/node_modules/.bin/protoc-gen-ts
FLAGS += --plugin=protoc-gen-grpc=/node_modules/.bin/grpc_tools_node_protoc_plugin
FLAGS += --js_out=import_style=commonjs,binary:$(OUTPUT)
FLAGS += --ts_out=service=grpc-node:$(OUTPUT)
FLAGS += --grpc_out=$(OUTPUT)
else ifeq ($(LANGUAGE),go)
OUTPUT := $(GO_DIR)
FLAGS += --$(LANGUAGE)_out=$(OUTPUT)
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ generation.

Then you can run `make LANGUAGE=xxx` to generate the source code for a specific language.

It's also possible to generate gRPC source code for `java`, `node` and `go` at once: `make generate`.
It's also possible to generate gRPC source code for `java`, `node`, `node-legacy` and `go` at once: `make generate`.

### quality assurance

We use [buf](https://buf.build/) to lint our proto files and to detect breaking changes. In addition, we run some basic language specific tests to verify a
successful code generation for `java`, `node` and `go`.
successful code generation for `java`, `node`, `node-legacy` and `go`.

Run `make check` to run all checks.

Expand All @@ -59,7 +59,7 @@ To generate go code for a [grpc-gateway](https://github.com/grpc-ecosystem/grpc-
## protoc docker image

We provide [stroeer/protoc-dockerized](https://github.com/orgs/stroeer/packages/container/package/protoc-dockerized) including `protoc` and all required
grpc plugins to generate source code for `java`, `node` and `go`. This docker image also supports generating a [grpc-gateway](https://github.com/grpc-ecosystem/grpc-gateway)
grpc plugins to generate source code for `java`, `node`, `node-legacy` and `go`. This docker image also supports generating a [grpc-gateway](https://github.com/grpc-ecosystem/grpc-gateway)
reverse-proxy server.

### precondition
Expand Down
1 change: 1 addition & 0 deletions node-legacy/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
engine-strict=true
1 change: 1 addition & 0 deletions node-legacy/.nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
14
95 changes: 95 additions & 0 deletions node-legacy/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# @stroeer/tapir-v1

## Usage

```bash
npm i @stroeer/tapir-v1-legacy
# or
yarn add @stroeer/tapir-v1-legacy
```

## Development

Make sure you generated the gRPC models and services for node.

### node

```bash
# https://github.com/nvm-sh/nvm#installing-and-updating
brew install nvm

# add this to your shell/bash profile:
# source /usr/local/opt/nvm/nvm.sh

nvm install 14
nvm use 14
# optional
nvm alias system 14
```

### install

```bash
npm i
```

### Test/Lint

```bash
npm run test
npm run lint
```

## How to update jest snapshots

```bash
npm run test -- --u
```

## Helpful resources

Examples for generating TypeScript types of generated services / models.

https://github.com/badsyntax/grpc-js-typescript

## Example Script

A very basic example script to call the article page via the given node module and log the plain text to console. The `GRPC_SERVICE` variable needs to be set via environment variables or replaced in code to get this snippet to work.

```js
import ArticlePageService from '@stroeer/tapir-v1/stroeer/page/article/v1/article_page_service_pb.js';
import { ArticlePageServiceClient } from '@stroeer/tapir-v1/stroeer/page/article/v1/article_page_service_grpc_pb.js';
import { ChannelCredentials } from 'grpc';

// Client
const credentials = ChannelCredentials.createSsl();
const client = new ArticlePageServiceClient(process.env.GRPC_SERVICE, credentials);

// Request
const request = new ArticlePageService.GetArticlePageRequest();
// Set Article Id
request.setId(87971076);

// Content
const page = client.getArticlePage(request, (err, response) => {
const page = response.getArticlePage();
const article = page.getArticle();

let articleText = '';

function handleChild(child) {
const children = child.getChildrenList();
if (children.length > 0) {
children.forEach(child => handleChild(child));
} else {
articleText += child.getText();
}
}

const bodyNodes = article.getBody().getChildrenList();

bodyNodes.forEach(handleChild);

console.log(articleText);
});
```
100 changes: 100 additions & 0 deletions node-legacy/__tests__/services.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
import { expect, test } from '@jest/globals';
import CoreArticleService from '../stroeer/core/v1/core_article_service_grpc_pb';
import ArticlePageService from '../stroeer/page/article/v1/article_page_service_grpc_pb';
import SectionPageService from '../stroeer/page/section/v1/section_page_service_grpc_pb';
import FragmentStageService from '../stroeer/fragment/v1/stage_service_grpc_pb';

test('gRPC core article service client is generated and matches the snapshot', () => {
expect(CoreArticleService).toMatchInlineSnapshot(`
Object {
"ArticleServiceClient": [Function],
"ArticleServiceService": Object {
"getArticle": Object {
"path": "/stroeer.core.v1.ArticleService/GetArticle",
"requestDeserialize": [Function],
"requestSerialize": [Function],
"requestStream": false,
"requestType": [Function],
"responseDeserialize": [Function],
"responseSerialize": [Function],
"responseStream": false,
"responseType": [Function],
},
"listArticles": Object {
"path": "/stroeer.core.v1.ArticleService/ListArticles",
"requestDeserialize": [Function],
"requestSerialize": [Function],
"requestStream": false,
"requestType": [Function],
"responseDeserialize": [Function],
"responseSerialize": [Function],
"responseStream": false,
"responseType": [Function],
},
},
}
`);
});

test('gRPC article page service client is generated and matches the snapshot', () => {
expect(ArticlePageService).toMatchInlineSnapshot(`
Object {
"ArticlePageServiceClient": [Function],
"ArticlePageServiceService": Object {
"getArticlePage": Object {
"path": "/stroeer.page.article.v1.ArticlePageService/GetArticlePage",
"requestDeserialize": [Function],
"requestSerialize": [Function],
"requestStream": false,
"requestType": [Function],
"responseDeserialize": [Function],
"responseSerialize": [Function],
"responseStream": false,
"responseType": [Function],
},
},
}
`);
});

test('gRPC section page service client is generated and matches the snapshot', () => {
expect(SectionPageService).toMatchInlineSnapshot(`
Object {
"SectionPageServiceClient": [Function],
"SectionPageServiceService": Object {
"getSectionPage": Object {
"path": "/stroeer.page.section.v1.SectionPageService/GetSectionPage",
"requestDeserialize": [Function],
"requestSerialize": [Function],
"requestStream": false,
"requestType": [Function],
"responseDeserialize": [Function],
"responseSerialize": [Function],
"responseStream": false,
"responseType": [Function],
},
},
}
`);
});

test('gRPC fragment stage service client is generated and matches the snapshot', () => {
expect(FragmentStageService).toMatchInlineSnapshot(`
Object {
"StageServiceClient": [Function],
"StageServiceService": Object {
"getStages": Object {
"path": "/stroeer.fragment.v1.StageService/GetStages",
"requestDeserialize": [Function],
"requestSerialize": [Function],
"requestStream": false,
"requestType": [Function],
"responseDeserialize": [Function],
"responseSerialize": [Function],
"responseStream": false,
"responseType": [Function],
},
},
}
`);
});
3 changes: 3 additions & 0 deletions node-legacy/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
preset: 'ts-jest'
};
Loading