Start of 5.X work

This commit is contained in:
Sebastien L
2025-03-18 17:38:34 -04:00
parent c0ddf0a997
commit 73bd096f37
442 changed files with 227862 additions and 21075 deletions

View File

@@ -1,59 +1,79 @@
"use strict";
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || Array.prototype.slice.call(from));
};
var grpcTools = require('grpc-tools');
var execSync = require('child_process').execSync;
var path = require('path');
var fs = require('fs');
var glob = require('glob');
const os = require('os');
const path = require('path');
const fs = require('fs');
const glob = require('glob');
const execSync = require('child_process').execSync;
function clearOutputDirectory(directory) {
if (fs.existsSync(directory)) {
var files = fs.readdirSync(directory);
for (var _i = 0, files_1 = files; _i < files_1.length; _i++) {
var file = files_1[_i];
var filePath = path.join(directory, file);
console.log(`Clearing output directory: ${directory}`);
const files = fs.readdirSync(directory);
for (const file of files) {
const filePath = path.join(directory, file);
console.log(`Deleting file: ${filePath}`);
fs.unlinkSync(filePath);
}
} else {
console.log(`Output directory does not exist, no need to clear: ${directory}`);
}
}
var GrpcToolsNodeProtocPlugin = /** @class */ (function () {
function GrpcToolsNodeProtocPlugin(options) {
this.protoPaths = options.protoPaths || []; // Array of proto_path directories
this.protoSources = options.protoSources || []; // Array of proto source files or directories
this.outputDir = options.outputDir || './'; // Output directory
class GrpcToolsNodeProtocPlugin {
constructor(options) {
this.protoPaths = options.protoPaths || [];
this.protoSources = options.protoSources || [];
this.outputDir = options.outputDir || './';
console.log('GrpcToolsNodeProtocPlugin initialized with options:', options);
}
GrpcToolsNodeProtocPlugin.prototype.apply = function (compiler) {
var _this = this;
compiler.hooks.environment.tap('GrpcToolsNodeProtocPlugin', function () {
apply(compiler) {
compiler.hooks.environment.tap('GrpcToolsNodeProtocPlugin', () => {
try {
console.log("Cleaning existing files, if any");
clearOutputDirectory(_this.outputDir);
console.log("Writing protocol buffer files into ".concat(_this.outputDir));
// Resolve proto_path directories
var resolvedProtoPaths = _this.protoPaths.map(function (p) { return path.resolve(__dirname, p); });
var resolvedProtoSources = [];
_this.protoSources.forEach(function (s) {
var matches = glob.sync(path.resolve(__dirname, s));
resolvedProtoSources = resolvedProtoSources.concat(matches);
});
var protocArgs = __spreadArray(__spreadArray([
"--js_out=import_style=commonjs,binary:".concat(_this.outputDir)
], resolvedProtoPaths.map(function (p) { return "--proto_path=".concat(p); }), true), resolvedProtoSources, true);
var command = "npx grpc_tools_node_protoc ".concat(protocArgs.join(' '));
clearOutputDirectory(this.outputDir);
console.log(`Preparing to compile protocol buffers into ${this.outputDir}`);
const protocPath = this.resolveProtocExecutable();
const protocGenJsPath = this.resolveProtocGenJsExecutable();
const resolvedProtoPaths = this.protoPaths.map(p => path.resolve(__dirname, p));
console.log('Resolved proto paths:', resolvedProtoPaths);
const resolvedProtoSources = this.protoSources.flatMap(s => glob.sync(path.resolve(__dirname, s)));
console.log('Resolved proto sources:', resolvedProtoSources);
const protocArgs = [
`--js_out=import_style=commonjs,binary:${this.outputDir}`,
`--plugin=protoc-gen-js=${protocGenJsPath}`,
...resolvedProtoPaths.map(p => `--proto_path=${p}`),
...resolvedProtoSources
];
const command = `${protocPath} ${protocArgs.join(' ')}`;
console.log('Executing command:', command);
execSync(command, { stdio: 'inherit' });
}
catch (error) {
console.log('Protocol buffer compilation completed successfully');
} catch (error) {
console.error('Error running grpc tools', error);
}
});
};
return GrpcToolsNodeProtocPlugin;
}());
}
resolveProtocExecutable() {
const isWindows = os.platform() === 'win32';
const protocDir = isWindows ? 'tools/protobuf/win64/bin' : 'tools/protobuf/linux-x86_64/bin';
const protocFileName = isWindows ? 'protoc.exe' : 'protoc';
return path.resolve(__dirname, '../../../..', protocDir, protocFileName);
}
resolveProtocGenJsExecutable() {
const isWindows = os.platform() === 'win32';
const protocGenJsDir = isWindows ? 'tools/protobuf-javascript/win64/bin' : 'tools/protobuf-javascript/linux-x86_64/bin';
const protocGenJsFileName = isWindows ? 'protoc-gen-js.exe' : 'protoc-gen-js';
return path.resolve(__dirname, '../../../..', protocGenJsDir, protocGenJsFileName);
}
}
module.exports = GrpcToolsNodeProtocPlugin;