grpc-code-gen
Advanced tools
Comparing version 3.3.0 to 3.3.1
@@ -235,48 +235,2 @@ "use strict"; | ||
const moduleSuffix = typescript ? 'ts' : 'js'; | ||
const grpcObjPath = getAbsPath(`grpcObj.${moduleSuffix}`, baseDir); | ||
if (typescript) { | ||
yield fs.writeFile(grpcObjPath, [ | ||
fileTip, | ||
`import * as grpc from '@grpc/grpc-js';`, | ||
`import { Metadata } from '@grpc/grpc-js/build/src/metadata';`, | ||
`import * as fs from 'fs';`, | ||
`import { forOwn } from 'lodash';`, | ||
`import { loadFromJson } from 'load-proto';\n`, | ||
`const root = require('${getImportPath(grpcObjPath, jsonPath)}');\n`, | ||
`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 },`, | ||
`));\n`, | ||
`// fix: grpc-message header split by comma | ||
Metadata.prototype.getMap = function() { | ||
const result: any = {}; | ||
forOwn((this as any).internalRepr, (values, key) => { | ||
if (values.length > 0) { | ||
// const v = values[0]; | ||
result[key] = values.map((v: any) => { | ||
return v instanceof Buffer ? v.slice() : v; | ||
}).join(',') | ||
} | ||
}); | ||
return result; | ||
} | ||
`, | ||
`export default grpcObject;`, | ||
].join('\n')); | ||
} | ||
else { | ||
yield fs.writeFile(grpcObjPath, [ | ||
fileTip, | ||
`const grpc = require('@grpc/grpc-js');`, | ||
`const { loadFromJson } = require('load-proto');`, | ||
`const root = require('${getImportPath(grpcObjPath, jsonPath)}');\n`, | ||
`const grpcObject = grpc.loadPackageDefinition(loadFromJson(root));`, | ||
`module.exports = grpcObject;`, | ||
`module.exports.default = grpcObject;`, | ||
].join('\n')); | ||
} | ||
const result = pbjs_1.inspectNamespace(root); | ||
@@ -313,2 +267,48 @@ if (!result) { | ||
if (serviceCode) { | ||
const grpcObjPath = getAbsPath(`grpcObj.${moduleSuffix}`, baseDir); | ||
if (typescript) { | ||
yield fs.writeFile(grpcObjPath, [ | ||
fileTip, | ||
`import * as grpc from '@grpc/grpc-js';`, | ||
`import { Metadata } from '@grpc/grpc-js/build/src/metadata';`, | ||
`import * as fs from 'fs';`, | ||
`import { forOwn } from 'lodash';`, | ||
`import { loadFromJson } from 'load-proto';\n`, | ||
`const root = require('${getImportPath(grpcObjPath, jsonPath)}');\n`, | ||
`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 },`, | ||
`));\n`, | ||
`// fix: grpc-message header split by comma | ||
Metadata.prototype.getMap = function() { | ||
const result: any = {}; | ||
forOwn((this as any).internalRepr, (values, key) => { | ||
if (values.length > 0) { | ||
// const v = values[0]; | ||
result[key] = values.map((v: any) => { | ||
return v instanceof Buffer ? v.slice() : v; | ||
}).join(',') | ||
} | ||
}); | ||
return result; | ||
} | ||
`, | ||
`export default grpcObject;`, | ||
].join('\n')); | ||
} | ||
else { | ||
yield fs.writeFile(grpcObjPath, [ | ||
fileTip, | ||
`const grpc = require('@grpc/grpc-js');`, | ||
`const { loadFromJson } = require('load-proto');`, | ||
`const root = require('${getImportPath(grpcObjPath, jsonPath)}');\n`, | ||
`const grpcObject = grpc.loadPackageDefinition(loadFromJson(root));`, | ||
`module.exports = grpcObject;`, | ||
`module.exports.default = grpcObject;`, | ||
].join('\n')); | ||
} | ||
const typesPath = getAbsPath('types.ts', baseDir); | ||
@@ -315,0 +315,0 @@ yield fs.writeFile(typesPath, fileTip + '\n' |
{ | ||
"name": "grpc-code-gen", | ||
"version": "3.3.0", | ||
"version": "3.3.1", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "repository": "https://github.com/yunkeCN/grpc-code-gen.git", |
@@ -289,48 +289,2 @@ import * as fs from 'fs-extra'; | ||
const grpcObjPath = getAbsPath(`grpcObj.${moduleSuffix}`, baseDir); | ||
if (typescript) { | ||
await fs.writeFile(grpcObjPath, [ | ||
fileTip, | ||
`import * as grpc from '@grpc/grpc-js';`, | ||
`import { Metadata } from '@grpc/grpc-js/build/src/metadata';`, | ||
`import * as fs from 'fs';`, | ||
`import { forOwn } from 'lodash';`, | ||
`import { loadFromJson } from 'load-proto';\n`, | ||
`const root = require('${getImportPath(grpcObjPath, jsonPath)}');\n`, | ||
`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 },`, | ||
`));\n`, | ||
`// fix: grpc-message header split by comma | ||
Metadata.prototype.getMap = function() { | ||
const result: any = {}; | ||
forOwn((this as any).internalRepr, (values, key) => { | ||
if (values.length > 0) { | ||
// const v = values[0]; | ||
result[key] = values.map((v: any) => { | ||
return v instanceof Buffer ? v.slice() : v; | ||
}).join(',') | ||
} | ||
}); | ||
return result; | ||
} | ||
`, | ||
`export default grpcObject;`, | ||
].join('\n')); | ||
} else { | ||
await fs.writeFile(grpcObjPath, [ | ||
fileTip, | ||
`const grpc = require('@grpc/grpc-js');`, | ||
`const { loadFromJson } = require('load-proto');`, | ||
`const root = require('${getImportPath(grpcObjPath, jsonPath)}');\n`, | ||
`const grpcObject = grpc.loadPackageDefinition(loadFromJson(root));`, | ||
`module.exports = grpcObject;`, | ||
`module.exports.default = grpcObject;`, | ||
].join('\n')); | ||
} | ||
const result = inspectNamespace(root); | ||
@@ -378,2 +332,48 @@ | ||
if (serviceCode) { | ||
const grpcObjPath = getAbsPath(`grpcObj.${moduleSuffix}`, baseDir); | ||
if (typescript) { | ||
await fs.writeFile(grpcObjPath, [ | ||
fileTip, | ||
`import * as grpc from '@grpc/grpc-js';`, | ||
`import { Metadata } from '@grpc/grpc-js/build/src/metadata';`, | ||
`import * as fs from 'fs';`, | ||
`import { forOwn } from 'lodash';`, | ||
`import { loadFromJson } from 'load-proto';\n`, | ||
`const root = require('${getImportPath(grpcObjPath, jsonPath)}');\n`, | ||
`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 },`, | ||
`));\n`, | ||
`// fix: grpc-message header split by comma | ||
Metadata.prototype.getMap = function() { | ||
const result: any = {}; | ||
forOwn((this as any).internalRepr, (values, key) => { | ||
if (values.length > 0) { | ||
// const v = values[0]; | ||
result[key] = values.map((v: any) => { | ||
return v instanceof Buffer ? v.slice() : v; | ||
}).join(',') | ||
} | ||
}); | ||
return result; | ||
} | ||
`, | ||
`export default grpcObject;`, | ||
].join('\n')); | ||
} else { | ||
await fs.writeFile(grpcObjPath, [ | ||
fileTip, | ||
`const grpc = require('@grpc/grpc-js');`, | ||
`const { loadFromJson } = require('load-proto');`, | ||
`const root = require('${getImportPath(grpcObjPath, jsonPath)}');\n`, | ||
`const grpcObject = grpc.loadPackageDefinition(loadFromJson(root));`, | ||
`module.exports = grpcObject;`, | ||
`module.exports.default = grpcObject;`, | ||
].join('\n')); | ||
} | ||
const typesPath = getAbsPath('types.ts', baseDir); | ||
@@ -380,0 +380,0 @@ |
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
118306