Skip to content
Open
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
15 changes: 15 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
version: 2
updates:
- package-ecosystem: 'npm'
directory: '/'
target-branch: 'main'
schedule:
interval: 'weekly'
day: 'monday'
time: '19:00'
commit-message:
prefix: 'dependencies'
prefix-development: 'devDependencies'
include: 'scope'
open-pull-requests-limit: 5
versioning-strategy: 'increase-if-necessary'
119 changes: 104 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ grpc_tools_node_protoc_ts

* [Aim](#aim)
* [Breaking changes](#breaking-changes)
* [How To Install Make GNU](#how-to-install-make-gnu)
* [How to use](#how-to-use)
* [Example](#example)
* [Changes](#changes)
Expand Down Expand Up @@ -52,26 +53,114 @@ Though the usage of tool, and generated codes shall not been changed, it's good

TSLint has been disabled in generated files. Please see the conversation: [#13](https://github.com/agreatfool/grpc_tools_node_protoc_ts/issues/13).

### How To Install Make GNU

- MacOs
```sh
brew install make
```

- Linux
```sh
apt-get install make
```

- Windows
```sh
choco install make
```

## How to use

```bash
npm install grpc_tools_node_protoc_ts --save-dev

# generate js codes via grpc-tools
grpc_tools_node_protoc \
--js_out=import_style=commonjs,binary:./your_dest_dir \
--grpc_out=./your_dest_dir \
--plugin=protoc-gen-grpc=`which grpc_tools_node_protoc_plugin` \
-I ./proto \
./your_proto_dir/*.proto

# generate d.ts codes
protoc \
--plugin=protoc-gen-ts=./node_modules/.bin/protoc-gen-ts \
--ts_out=./your_dest_dir \
-I ./proto \
./your_proto_dir/*.proto
```

+ ### Makefile
```makefile
#run command -> make grpcwin || make grpclinmac

INPUT_DIR := ${realpath your_proto_dir}
OUTPUT_DIR := ${realpath your_output_dir}
FIND_FILE := ${wildcard ${OUTPUT_DIR}/*.ts}
GRPC_TOOLS = npx grpc_tools_node_protoc
PROTOC_GEN_TS_PATH_WINDOWS := ${realpath node_modules/.bin/protoc-gen-ts.cmd}
PROTOC_GEN_TS_PATH_LINMAC := ${realpath node_modules/.bin/protoc-gen-ts}

#################################################################################
##===============================================================================
## GENERATE PROTO FILE FOR WINDOWS USING grpc_tools_node_protoc FOR @grpc/grpc-js
##===============================================================================
#################################################################################

grpcwin:
ifneq (${FIND_FILE}, )
#remove old all file typedefs
rm ${OUTPUT_DIR}/**.{ts,js}

#generate protofile typedefs
${shell exec} ${GRPC_TOOLS} \
--plugin=protoc-gen-ts=${PROTOC_GEN_TS_PATH_WINDOWS} \
--grpc_out=grpc_js:${OUTPUT_DIR} \
--js_out=import_style=commonjs,binary:${OUTPUT_DIR} \
--ts_out=grpc_js:${OUTPUT_DIR} \
--proto_path ${INPUT_DIR} ${INPUT_DIR}/*.proto
else
#generate protofile typedefs if file not exist
${shell exec} ${GRPC_TOOLS} \
--plugin=protoc-gen-ts=${PROTOC_GEN_TS_PATH_WINDOWS} \
--grpc_out=grpc_js:${OUTPUT_DIR} \
--js_out=import_style=commonjs,binary:${OUTPUT_DIR} \
--ts_out=grpc_js:${OUTPUT_DIR} \
--proto_path ${INPUT_DIR} ${INPUT_DIR}/*.proto
endif

####################################################################################
##==================================================================================
## GENERATE PROTO FILE FOR LINUX/MAC USING grpc_tools_node_protoc FOR @grpc/grpc-js
##==================================================================================
####################################################################################

grpclinmac:
ifneq (${FIND_FILE}, )
#remove old all file typedefs
rm ${OUTPUT_DIR}/**.{ts,js}

#generate protofile typedefs
${shell exec} ${GRPC_TOOLS} \
--plugin=protoc-gen-ts=${PROTOC_GEN_TS_PATH_LINMAC} \
--grpc_out=grpc_js:${OUTPUT_DIR} \
--js_out=import_style=commonjs,binary:${OUTPUT_DIR} \
--ts_out=grpc_js:${OUTPUT_DIR} \
--proto_path ${INPUT_DIR} ${INPUT_DIR}/*.proto
else
#generate protofile typedefs if file not exist
${shell exec} ${GRPC_TOOLS} \
--plugin=protoc-gen-ts=${PROTOC_GEN_TS_PATH_LINMAC} \
--grpc_out=grpc_js:${OUTPUT_DIR} \
--js_out=import_style=commonjs,binary:${OUTPUT_DIR} \
--ts_out=grpc_js:${OUTPUT_DIR} \
--proto_path ${INPUT_DIR} ${INPUT_DIR}/*.proto
endif
```
+ ### Shell/Bash
```sh
# generate js codes via grpc-tools
grpc_tools_node_protoc \
--js_out=import_style=commonjs,binary:./your_dest_dir \
--grpc_out=./your_dest_dir \
--plugin=protoc-gen-grpc=`which grpc_tools_node_protoc_plugin` \
-I ./proto \
./your_proto_dir/*.proto

# generate d.ts codes
protoc \
--plugin=protoc-gen-ts=./node_modules/.bin/protoc-gen-ts \
--ts_out=./your_dest_dir \
-I ./proto \
./your_proto_dir/*.proto
```

## Example
There is a complete & runnable example in folder `examples`.

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
12 changes: 12 additions & 0 deletions examples/example-student/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[*]
root = true
end_of_line = crlf
charset = utf-8

[*.{ts,spec.ts,test.ts,json}]
tab_width = 2
indent_style = tab

[Makefile,Dockerfile,proto]
tab_width = 2
indent_style = tab
3 changes: 3 additions & 0 deletions examples/example-student/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
dist
.env
16 changes: 16 additions & 0 deletions examples/example-student/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"parserOptions": {
"ecmaVersion": 2018,
"sourceType": "module"
},
"parser": "@typescript-eslint/parser",
"extends": ["standard", "plugin:@typescript-eslint/recommended", "plugin:security/recommended", "plugin:prettier/recommended"],
"rules": {
"prettier/prettier": 0,
"@typescript-eslint/no-explicit-any": 0,
"node/handle-callback-err": 0,
"prefer-const": 0,
"camelcase": 0,
"ts(2559)": 0
}
}
3 changes: 3 additions & 0 deletions examples/example-student/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
dist
.env
5 changes: 5 additions & 0 deletions examples/example-student/.huskyrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"hooks": {
"pre-commit": "npm run lint:fix"
}
}
2 changes: 2 additions & 0 deletions examples/example-student/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
dist
11 changes: 11 additions & 0 deletions examples/example-student/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"proseWrap": "always",
"quoteProps": "consistent",
"trailingComma": "none",
"bracketSpacing": true,
"tabWidth": 2,
"useTabs": true,
"printWidth": 130,
"singleQuote": true,
"semi": false
}
10 changes: 10 additions & 0 deletions examples/example-student/.protolint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
lint:
rules:
no_default: true
add:
- MESSAGE_NAMES_UPPER_CAMEL_CASE
- SERVICE_NAMES_UPPER_CAMEL_CASE
- ENUM_NAMES_UPPER_CAMEL_CASE
- ENUM_FIELD_NAMES_UPPER_SNAKE_CASE
- IMPORTS_SORTED
- SYNTAX_CONSISTENT
126 changes: 126 additions & 0 deletions examples/example-student/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
NPM := npm
FLAG := run

INPUT_DIR := ${realpath src/protos}
OUTPUT_DIR := ${realpath src/typedefs}
FIND_FILE := ${wildcard ${OUTPUT_DIR}/*.ts}
GRPC_TOOLS = npx grpc_tools_node_protoc
PROTOC_GEN_TS_PATH_WINDOWS := ${realpath node_modules/.bin/protoc-gen-ts.cmd}
PROTOC_GEN_TS_PATH_LINMAC := ${realpath node_modules/.bin/protoc-gen-ts}

###############################
## RUNNING PROD APP ENVIRONMENT
################################

prod:

ifdef type
${NPM} ${FLAG} ${type}:start
endif

###############################
## RUNNING DEV APP ENVIRONMENT
################################

dev:

ifdef type
${NPM} ${FLAG} ${type}:dev
endif

###############################
## GITHUB AUTOMATION
################################

GIT := git

gh: add.o commit.o push.o

add.o:
${GIT} add .

commit.o:

ifdef msg
${GIT} commit -m ${msg}
endif

push.o:
${GIT} push origin main

#################################################################################
##===============================================================================
## GENERATE PROTO FILE FOR WINDOWS USING grpc_tools_node_protoc FOR @grpc/grpc-js
##===============================================================================
#################################################################################

grpcwin:
ifneq (${FIND_FILE}, )
#remove old all file typedefs
rm ${OUTPUT_DIR}/**.{ts,js}

#generate protofile typedefs
${shell exec} ${GRPC_TOOLS} \
--plugin=protoc-gen-ts=${PROTOC_GEN_TS_PATH_WINDOWS} \
--grpc_out=grpc_js:${OUTPUT_DIR} \
--js_out=import_style=commonjs,binary:${OUTPUT_DIR} \
--ts_out=grpc_js:${OUTPUT_DIR} \
--proto_path ${INPUT_DIR} ${INPUT_DIR}/*.proto
else
#generate protofile typedefs if file not exist
${shell exec} ${GRPC_TOOLS} \
--plugin=protoc-gen-ts=${PROTOC_GEN_TS_PATH_WINDOWS} \
--grpc_out=grpc_js:${OUTPUT_DIR} \
--js_out=import_style=commonjs,binary:${OUTPUT_DIR} \
--ts_out=grpc_js:${OUTPUT_DIR} \
--proto_path ${INPUT_DIR} ${INPUT_DIR}/*.proto
endif

####################################################################################
##==================================================================================
## GENERATE PROTO FILE FOR LINUX/MAC USING grpc_tools_node_protoc FOR @grpc/grpc-js
##==================================================================================
####################################################################################

grpclinmac:
ifneq (${FIND_FILE}, )
#remove old all file typedefs
rm ${OUTPUT_DIR}/**.{ts,js}

#generate protofile typedefs
${shell exec} ${GRPC_TOOLS} \
--plugin=protoc-gen-ts=${PROTOC_GEN_TS_PATH_LINMAC} \
--grpc_out=grpc_js:${OUTPUT_DIR} \
--js_out=import_style=commonjs,binary:${OUTPUT_DIR} \
--ts_out=grpc_js:${OUTPUT_DIR} \
--proto_path ${INPUT_DIR} ${INPUT_DIR}/*.proto
else
#generate protofile typedefs if file not exist
${shell exec} ${GRPC_TOOLS} \
--plugin=protoc-gen-ts=${PROTOC_GEN_TS_PATH_LINMAC} \
--grpc_out=grpc_js:${OUTPUT_DIR} \
--js_out=import_style=commonjs,binary:${OUTPUT_DIR} \
--ts_out=grpc_js:${OUTPUT_DIR} \
--proto_path ${INPUT_DIR} ${INPUT_DIR}/*.proto
endif


###############################
## BUILD AUTOMATION
################################

build:
${NPM} ${FLAG} build

###############################
## BUILD AUTOMATION AND LINT FIX
################################

buildfix: linfix.o build.o

linfix.o:

${NPM} ${FLAG} lint:fix

build.o:
${NPM} ${FLAG} build
Loading