initial refactoring

This commit is contained in:
Sebastien L
2023-12-04 23:25:57 -05:00
parent d03678ea81
commit c0ddf0a997
331 changed files with 29663 additions and 16553 deletions

View File

@@ -0,0 +1,59 @@
"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');
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);
fs.unlinkSync(filePath);
}
}
}
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
}
GrpcToolsNodeProtocPlugin.prototype.apply = function (compiler) {
var _this = this;
compiler.hooks.environment.tap('GrpcToolsNodeProtocPlugin', function () {
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(' '));
execSync(command, { stdio: 'inherit' });
}
catch (error) {
console.error('Error running grpc tools', error);
}
});
};
return GrpcToolsNodeProtocPlugin;
}());
module.exports = GrpcToolsNodeProtocPlugin;

View File

@@ -0,0 +1,70 @@
import { Compiler } from 'webpack';
const grpcTools = require('grpc-tools');
const { execSync } = require('child_process');
const path = require('path');
const fs = require('fs');
const glob = require('glob');
function clearOutputDirectory(directory:string) {
if (fs.existsSync(directory)) {
const files = fs.readdirSync(directory);
for (const file of files) {
const filePath = path.join(directory, file);
fs.unlinkSync(filePath);
}
}
}
export = GrpcToolsNodeProtocPlugin;
// Define the interface for the plugin options
interface GrpcToolsNodeProtocPluginOptions {
protoPaths?: string[];
protoSources?: string[];
outputDir?: string;
}
class GrpcToolsNodeProtocPlugin {
private protoPaths: string[];
private protoSources: string[];
private outputDir: string;
constructor(options: GrpcToolsNodeProtocPluginOptions) {
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
}
apply(compiler:Compiler) {
compiler.hooks.environment.tap('GrpcToolsNodeProtocPlugin', () => {
try {
console.log(`Cleaning existing files, if any`)
clearOutputDirectory(this.outputDir);
console.log(`Writing protocol buffer files into ${this.outputDir}`)
// Resolve proto_path directories
const resolvedProtoPaths = this.protoPaths.map(p => path.resolve(__dirname, p));
var resolvedProtoSources:string[] = [];
this.protoSources.forEach(function (s) {
var matches = glob.sync(path.resolve(__dirname, s));
resolvedProtoSources = resolvedProtoSources.concat(matches);
});
const protocArgs = [
`--js_out=import_style=commonjs,binary:${this.outputDir}`,
// `--grpc_out=generate_package_definition:${this.outputDir}`,
...resolvedProtoPaths.map(p => `--proto_path=${p}`),
...resolvedProtoSources
];
const command = `npx grpc_tools_node_protoc ${protocArgs.join(' ')}`;
execSync(command, { stdio: 'inherit' });
} catch (error) {
console.error('Error running grpc tools', error);
}
});
}
}

View File

@@ -0,0 +1,143 @@
import { Compiler } from 'webpack';
const path = require('path');
const fs = require('fs');
const zlib = require("zlib");
export = SPIFFSUpdate;
// Define the interface for the plugin options
interface SPIFFSUpdateOptions {
sourceFiles?: string[];
targetFiles?: string[];
compress?: boolean;
}
class SPIFFSUpdate {
private sourceFiles: string[];
private targetFiles: string[];
private compress: boolean;
constructor(options: SPIFFSUpdateOptions) {
this.sourceFiles = options.sourceFiles || []; // Array of proto_path directories
this.targetFiles = options.targetFiles || []; // Array of proto source files or directories
this.compress = options.compress || true; // Output directory
}
apply(compiler: Compiler) {
compiler.hooks.afterEmit.tapAsync('GrpcToolsNodeProtocPlugin', (compilation, callback) => {
try {
fs.appendFileSync('./dist/index.html.gz',
zlib.gzipSync(fs.readFileSync('./dist/index.html'),
{
chunckSize: 65536,
level: zlib.constants.Z_BEST_COMPRESSION
})
);
// if (options.mode !== "production") return;
// let buildRootPath = path.join(process.cwd(), '..', '..', '..');
// let wifiManagerPath = glob.sync(path.join(buildRootPath, 'components/**/wifi-manager*'))[0];
// let buildCRootPath = glob.sync(buildRootPath)[0];
// fs.appendFileSync('./dist/index.html.gz',
// zlib.gzipSync(fs.readFileSync('./dist/index.html'),
// {
// chunckSize: 65536,
// level: zlib.constants.Z_BEST_COMPRESSION
// }));
// var getDirectories = function (src, callback) {
// var searchPath = path.posix.join(src, '/**/*(*.gz|favicon-32x32.png)');
// console.log(`Post build: Getting file list from ${searchPath}`);
// glob(searchPath, callback);
// };
// var cleanUpPath = path.posix.join(buildCRootPath, '/build/*.S');
// console.log(`Post build: Cleaning up previous builds in ${cleanUpPath}`);
// glob(cleanUpPath, function (err, list) {
// if (err) {
// console.error('Error', err);
// } else {
// list.forEach(fileName => {
// try {
// console.log(`Post build: Purging old binary file ${fileName} from C project.`);
// fs.unlinkSync(fileName)
// //file removed
// } catch (ferr) {
// console.error(ferr)
// }
// });
// }
// },
// 'afterEmit'
// );
// console.log('Generating C include files from webpack build output');
// getDirectories('./dist', function (err, list) {
// console.log(`Post build: found ${list.length} files. Relative path: ${wifiManagerPath}.`);
// if (err) {
// console.log('Error', err);
// } else {
// let exportDefHead =
// `/***********************************
// webpack_headers
// ${arguments[1]}
// ***********************************/
// #pragma once
// #include <inttypes.h>
// extern const char * resource_lookups[];
// extern const uint8_t * resource_map_start[];
// extern const uint8_t * resource_map_end[];`;
// let exportDef = '// Automatically generated. Do not edit manually!.\n' +
// '#include <inttypes.h>\n';
// let lookupDef = 'const char * resource_lookups[] = {\n';
// let lookupMapStart = 'const uint8_t * resource_map_start[] = {\n';
// let lookupMapEnd = 'const uint8_t * resource_map_end[] = {\n';
// let cMake = '';
// list.forEach(foundFile => {
// let exportName = path.basename(foundFile).replace(/[\. \-]/gm, '_');
// //take the full path of the file and make it relative to the build directory
// let cmakeFileName = path.posix.relative(wifiManagerPath, glob.sync(path.resolve(foundFile))[0]);
// let httpRelativePath = path.posix.join('/', path.posix.relative('dist', foundFile));
// exportDef += `extern const uint8_t _${exportName}_start[] asm("_binary_${exportName}_start");\nextern const uint8_t _${exportName}_end[] asm("_binary_${exportName}_end");\n`;
// lookupDef += `\t"${httpRelativePath}",\n`;
// lookupMapStart += '\t_' + exportName + '_start,\n';
// lookupMapEnd += '\t_' + exportName + '_end,\n';
// cMake += `target_add_binary_data( __idf_wifi-manager ${cmakeFileName} BINARY)\n`;
// console.log(`Post build: adding cmake file reference to ${cmakeFileName} from C project, with web path ${httpRelativePath}.`);
// });
// lookupDef += '""\n};\n';
// lookupMapStart = lookupMapStart.substring(0, lookupMapStart.length - 2) + '\n};\n';
// lookupMapEnd = lookupMapEnd.substring(0, lookupMapEnd.length - 2) + '\n};\n';
// try {
// fs.writeFileSync('webapp.cmake', cMake);
// fs.writeFileSync('webpack.c', exportDef + lookupDef + lookupMapStart + lookupMapEnd);
// fs.writeFileSync('webpack.h', exportDefHead);
// //file written successfully
// } catch (e) {
// console.error(e);
// }
// }
// });
// console.log('Post build completed.');
// })
} catch (error) {
console.error('Error setting up grpc-tools protoc', error);
}
callback();
});
}
}