mirror of
https://github.com/sle118/squeezelite-esp32.git
synced 2025-12-13 15:07:01 +03:00
Start of 5.X work
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -4,6 +4,11 @@ const { execSync } = require('child_process');
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
const glob = require('glob');
|
||||
function ensureOutputDirectory(directory) {
|
||||
if (!fs.existsSync(directory)) {
|
||||
fs.mkdirSync(directory, { recursive: true });
|
||||
}
|
||||
}
|
||||
|
||||
function clearOutputDirectory(directory:string) {
|
||||
if (fs.existsSync(directory)) {
|
||||
|
||||
32
components/wifi-manager/webapp/webpack/testProtocPlugin.js
Normal file
32
components/wifi-manager/webapp/webpack/testProtocPlugin.js
Normal file
@@ -0,0 +1,32 @@
|
||||
const path = require('path');
|
||||
const GrpcToolsNodeProtocPlugin = require('./GrpcToolsNodeProtocPlugin.js');
|
||||
const glob = require('glob');
|
||||
|
||||
// Define the paths as they are in your Webpack script
|
||||
const buildRootPath = path.join(process.cwd(), '..', '..', '..');
|
||||
const ComponentsPath = glob.sync(path.join(buildRootPath, 'components/'))[0];
|
||||
const buildCRootPath = glob.sync(buildRootPath)[0];
|
||||
|
||||
// Instantiate the plugin
|
||||
const plugin = new GrpcToolsNodeProtocPlugin({
|
||||
protoPaths: [
|
||||
path.join(ComponentsPath, 'spotify/cspot/bell/external/nanopb/generator/proto'),
|
||||
path.join(buildCRootPath, 'protobuf/proto')
|
||||
],
|
||||
protoSources: [
|
||||
path.join(buildCRootPath, 'protobuf/proto/*.proto'),
|
||||
path.join(ComponentsPath, 'spotify/cspot/bell/external/nanopb/generator/proto/*.proto')
|
||||
],
|
||||
outputDir: './src/js/proto'
|
||||
});
|
||||
|
||||
// Manually execute the plugin
|
||||
plugin.apply({
|
||||
hooks: {
|
||||
environment: {
|
||||
tap: (name, fn) => fn()
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
console.log('GrpcToolsNodeProtocPlugin test executed.');
|
||||
Reference in New Issue
Block a user