grpc-code-gen
Advanced tools
Comparing version 3.1.0 to 3.2.0
@@ -7,19 +7,4 @@ import { IOption } from 'load-proto'; | ||
serviceCode?: boolean; | ||
loaderOptions?: { | ||
/** Keeps field casing instead of converting to camel case */ | ||
keepCase?: boolean; | ||
/** Recognize double-slash comments in addition to doc-block comments. */ | ||
alternateCommentMode?: boolean; | ||
/** Also sets default values on the resulting object */ | ||
defaults?: boolean; | ||
/** Sets empty arrays for missing repeated fields even if `defaults=false` */ | ||
arrays?: boolean; | ||
/** Sets empty objects for missing map fields even if `defaults=false` */ | ||
objects?: boolean; | ||
/** Includes virtual oneof properties set to the present field's name, if any */ | ||
oneofs?: boolean; | ||
/** Performs additional JSON compatibility conversions, i.e. NaN and Infinity to strings */ | ||
json?: boolean; | ||
}; | ||
configFilePath: string; | ||
} | ||
export declare function gen(opt: Options): Promise<string>; |
@@ -217,3 +217,3 @@ "use strict"; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const { baseDir = BASE_DIR, target = 'typescript', serviceCode = true, jsonSemanticTypes = false, loaderOptions = { defaults: true }, } = opt; | ||
const { baseDir = BASE_DIR, target = 'typescript', serviceCode = true, jsonSemanticTypes = false, configFilePath, } = opt; | ||
const typescript = target === 'typescript'; | ||
@@ -241,5 +241,13 @@ fs.removeSync(baseDir); | ||
`import * as grpc from '@grpc/grpc-js';`, | ||
`import * as fs from 'fs';`, | ||
`import { loadFromJson } from 'load-proto';\n`, | ||
`const root = require('${getImportPath(grpcObjPath, jsonPath)}');\n`, | ||
`const grpcObject = grpc.loadPackageDefinition(loadFromJson(root, ${JSON.stringify(loaderOptions)}));`, | ||
`let config;`, | ||
`if (fs.existsSync(require.resolve('${getImportPath(grpcObjPath, configFilePath)}'))) {`, | ||
` config = require('${getImportPath(grpcObjPath, configFilePath)}');`, | ||
`}`, | ||
`const grpcObject = grpc.loadPackageDefinition(loadFromJson(`, | ||
` root,`, | ||
` (config && config.loaderOptions) || { defaults: true },`, | ||
`));`, | ||
`export default grpcObject;`, | ||
@@ -246,0 +254,0 @@ ].join('\n')); |
@@ -22,10 +22,14 @@ "use strict"; | ||
const opt = {}; | ||
let configFilePath = undefined; | ||
if (fs.existsSync(config)) { | ||
if (path.isAbsolute(config)) { | ||
configFilePath = config; | ||
Object.assign(opt, require(config)); | ||
} | ||
else { | ||
Object.assign(opt, require(path.join(process.cwd(), config))); | ||
configFilePath = path.join(process.cwd(), config); | ||
Object.assign(opt, require(configFile)); | ||
} | ||
} | ||
opt.configFilePath = configFilePath; | ||
if (url) { | ||
@@ -32,0 +36,0 @@ opt.gitUrls = url; |
{ | ||
"name": "grpc-code-gen", | ||
"version": "3.1.0", | ||
"version": "3.2.0", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "repository": "https://github.com/yunkeCN/grpc-code-gen.git", |
@@ -61,17 +61,4 @@ # grpc-code-gen | ||
serviceCode? | boolean | 生成客户端代码 | `true` | ||
loaderOptions? | [LoaderOptions](#LoaderOptions) | loader生成配置 | `{ defaults: true }` | ||
loaderOptions? | [LoaderOptions](https://github.com/grpc/grpc-node/tree/master/packages/proto-loader) | loader生成配置 | `{ defaults: true }` | ||
### LoaderOptions | ||
参数 | 类型 | 说明 | 默认值 | ||
---|---|---|--- | ||
keepCase? | boolean | Keeps field casing instead of converting to camel case | true | ||
alternateCommentMode? | boolean | Recognize double-slash comments in addition to doc-block comments. | false | ||
defaults? | boolean | Also sets default values on the resulting object | true | ||
arrays? | boolean | Sets empty arrays for missing repeated fields even if `defaults=false` | true | ||
objects? | boolean | Sets empty objects for missing map fields even if `defaults=false` | true | ||
oneofs? | boolean | Includes virtual oneof properties set to the present field's name, if any | true | ||
json? | boolean | Performs additional JSON compatibility conversions, i.e. NaN and Infinity to strings | true | ||
## Program usage | ||
@@ -78,0 +65,0 @@ ```js |
@@ -252,24 +252,3 @@ import * as fs from 'fs-extra'; | ||
serviceCode?: boolean; | ||
loaderOptions?: { | ||
/** Keeps field casing instead of converting to camel case */ | ||
keepCase?: boolean; | ||
/** Recognize double-slash comments in addition to doc-block comments. */ | ||
alternateCommentMode?: boolean; | ||
/** Also sets default values on the resulting object */ | ||
defaults?: boolean; | ||
/** Sets empty arrays for missing repeated fields even if `defaults=false` */ | ||
arrays?: boolean; | ||
/** Sets empty objects for missing map fields even if `defaults=false` */ | ||
objects?: boolean; | ||
/** Includes virtual oneof properties set to the present field's name, if any */ | ||
oneofs?: boolean; | ||
/** Performs additional JSON compatibility conversions, i.e. NaN and Infinity to strings */ | ||
json?: boolean; | ||
}; | ||
configFilePath: string; | ||
} | ||
@@ -283,3 +262,3 @@ | ||
jsonSemanticTypes = false, | ||
loaderOptions = { defaults: true }, | ||
configFilePath, | ||
} = opt; | ||
@@ -317,5 +296,13 @@ | ||
`import * as grpc from '@grpc/grpc-js';`, | ||
`import * as fs from 'fs';`, | ||
`import { loadFromJson } from 'load-proto';\n`, | ||
`const root = require('${getImportPath(grpcObjPath, jsonPath)}');\n`, | ||
`const grpcObject = grpc.loadPackageDefinition(loadFromJson(root, ${JSON.stringify(loaderOptions)}));`, | ||
`let config;`, | ||
`if (fs.existsSync(require.resolve('${getImportPath(grpcObjPath, configFilePath)}'))) {`, | ||
` config = require('${getImportPath(grpcObjPath, configFilePath)}');`, | ||
`}`, | ||
`const grpcObject = grpc.loadPackageDefinition(loadFromJson(`, | ||
` root,`, | ||
` (config && config.loaderOptions) || { defaults: true },`, | ||
`));`, | ||
`export default grpcObject;`, | ||
@@ -322,0 +309,0 @@ ].join('\n')); |
@@ -32,10 +32,15 @@ import * as program from 'commander'; | ||
let configFilePath = undefined; | ||
if (fs.existsSync(config)) { | ||
if (path.isAbsolute(config)) { | ||
configFilePath = config; | ||
Object.assign(opt, require(config)); | ||
} else { | ||
Object.assign(opt, require(path.join(process.cwd(), config))); | ||
configFilePath = path.join(process.cwd(), config); | ||
Object.assign(opt, require(configFile)); | ||
} | ||
} | ||
opt.configFilePath = configFilePath; | ||
if (url) { | ||
@@ -42,0 +47,0 @@ opt.gitUrls = url; |
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
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
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
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
115431
1688
99