grpc-code-gen
Advanced tools
Comparing version 3.4.16 to 3.5.0
@@ -8,3 +8,4 @@ import { IOption } from 'load-proto'; | ||
configFilePath: string; | ||
grpcNative?: boolean; | ||
} | ||
export declare function gen(opt: Options): Promise<string>; |
@@ -217,8 +217,8 @@ "use strict"; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const { baseDir = BASE_DIR, target = 'typescript', serviceCode = true, jsonSemanticTypes = false, configFilePath, } = opt; | ||
const { baseDir = BASE_DIR, target = 'typescript', serviceCode = true, jsonSemanticTypes = false, configFilePath, gitUrls, branch, accessToken, resolvePath, grpcNative, } = opt; | ||
const typescript = target === 'typescript'; | ||
const grpcNpmName = grpcNative ? 'grpc' : '@grpc/grpc-js'; | ||
fs.removeSync(baseDir); | ||
console.info(`Clean dir: ${baseDir}`); | ||
fs.mkdirpSync(baseDir); | ||
const { gitUrls, branch, accessToken, resolvePath } = opt; | ||
const root = yield load_proto_1.loadProto({ | ||
@@ -287,3 +287,3 @@ gitUrls, | ||
fileTip, | ||
`import * as grpc from '@grpc/grpc-js';`, | ||
`import * as grpc from '${grpcNpmName}';`, | ||
`import * as fs from 'fs';`, | ||
@@ -321,3 +321,3 @@ `import { forOwn } from 'lodash';`, | ||
fileTip, | ||
`const grpc = require('@grpc/grpc-js');`, | ||
`const grpc = require('${grpcNpmName}');`, | ||
`const { loadFromJson } = require('load-proto');`, | ||
@@ -381,3 +381,3 @@ `const root = require('${getImportPath(grpcObjPath, jsonPath)}');\n`, | ||
`import grpcObject from '${getImportPath(servicePath, grpcObjPath)}';\n`, | ||
`import { ChannelCredentials } from "@grpc/grpc-js/build/src/channel-credentials";`, | ||
`import { ChannelCredentials } from "${grpcNative ? 'grpc' : '@grpc/grpc-js/build/src/channel-credentials'}";`, | ||
`import { promisify } from 'util';`, | ||
@@ -454,3 +454,3 @@ `import * as types from '${getImportPath(servicePath, typesPath)}';\n`, | ||
fileTip, | ||
`import { ChannelCredentials } from "@grpc/grpc-js/build/src/channel-credentials";`, | ||
`import { ChannelCredentials } from "${grpcNative ? 'grpc' : '@grpc/grpc-js/build/src/channel-credentials'}";`, | ||
`import * as types from '${getImportPath(serviceDTsPath, typesPath)}';\n`, | ||
@@ -457,0 +457,0 @@ `export class ${service.name} {`, |
{ | ||
"name": "grpc-code-gen", | ||
"version": "3.4.16", | ||
"version": "3.5.0", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "repository": "https://github.com/yunkeCN/grpc-code-gen.git", |
@@ -59,2 +59,3 @@ # grpc-code-gen | ||
target? | `javascript typescript` | 目标语言 | `null` | ||
grpcNative? | boolean | 是否使用grpc native包 | `false` | ||
jsonSemanticTypes? | boolean | 生成json semantic types | `false` | ||
@@ -61,0 +62,0 @@ serviceCode? | boolean | 生成客户端代码 | `true` |
@@ -253,2 +253,3 @@ import * as fs from 'fs-extra'; | ||
configFilePath: string; | ||
grpcNative?: boolean; | ||
} | ||
@@ -263,5 +264,11 @@ | ||
configFilePath, | ||
gitUrls, | ||
branch, | ||
accessToken, | ||
resolvePath, | ||
grpcNative, | ||
} = opt; | ||
const typescript = target === 'typescript'; | ||
const grpcNpmName = grpcNative ? 'grpc' : '@grpc/grpc-js'; | ||
@@ -273,3 +280,2 @@ fs.removeSync(baseDir); | ||
const { gitUrls, branch, accessToken, resolvePath } = opt; | ||
const root = await loadProto({ | ||
@@ -354,3 +360,3 @@ gitUrls, | ||
fileTip, | ||
`import * as grpc from '@grpc/grpc-js';`, | ||
`import * as grpc from '${grpcNpmName}';`, | ||
`import * as fs from 'fs';`, | ||
@@ -387,3 +393,3 @@ `import { forOwn } from 'lodash';`, | ||
fileTip, | ||
`const grpc = require('@grpc/grpc-js');`, | ||
`const grpc = require('${grpcNpmName}');`, | ||
`const { loadFromJson } = require('load-proto');`, | ||
@@ -456,3 +462,3 @@ `const root = require('${getImportPath(grpcObjPath, jsonPath)}');\n`, | ||
`import grpcObject from '${getImportPath(servicePath, grpcObjPath)}';\n`, | ||
`import { ChannelCredentials } from "@grpc/grpc-js/build/src/channel-credentials";`, | ||
`import { ChannelCredentials } from "${grpcNative ? 'grpc' : '@grpc/grpc-js/build/src/channel-credentials'}";`, | ||
`import { promisify } from 'util';`, | ||
@@ -529,3 +535,3 @@ `import * as types from '${getImportPath(servicePath, typesPath)}';\n`, | ||
fileTip, | ||
`import { ChannelCredentials } from "@grpc/grpc-js/build/src/channel-credentials";`, | ||
`import { ChannelCredentials } from "${grpcNative ? 'grpc' : '@grpc/grpc-js/build/src/channel-credentials'}";`, | ||
`import * as types from '${getImportPath(serviceDTsPath, typesPath)}';\n`, | ||
@@ -532,0 +538,0 @@ `export class ${service.name} {`, |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
124219
1840
107