svelteesp32
Version:
Convert Svelte (or any frontend) JS application to serve it from ESP32 webserver (PsychicHttp)
49 lines (48 loc) • 2.14 kB
JavaScript
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getFiles = void 0;
const node_crypto_1 = require("node:crypto");
const node_fs_1 = require("node:fs");
const node_path_1 = __importDefault(require("node:path"));
const glob_1 = require("glob");
const commandLine_1 = require("./commandLine");
const consoleColor_1 = require("./consoleColor");
const findSimilarFiles = (files) => {
const contentComparer = new Map();
for (const [filename, content] of files.entries()) {
const hash = (0, node_crypto_1.createHash)('sha256').update(content).digest('hex');
if (contentComparer.has(hash))
contentComparer.get(hash).push(filename);
else
contentComparer.set(hash, [filename]);
}
const result = [];
for (const filenames of contentComparer.values())
if (filenames.length > 1)
result.push(filenames);
return result;
};
const getFiles = () => {
let filenames = (0, glob_1.globSync)('**/*', { cwd: commandLine_1.cmdLine.sourcepath, nodir: true });
filenames = filenames.filter((filename) => {
const extension = node_path_1.default.extname(filename);
if (['.gz', '.brottli', '.br'].includes(extension)) {
const original = filename.slice(0, -1 * extension.length);
if (filenames.includes(original)) {
console.log((0, consoleColor_1.redLog)(` ${filename} skipped because is perhaps a compressed version of ${original}`));
return false;
}
}
return true;
});
const result = new Map();
for (const filename of filenames)
result.set(filename, (0, node_fs_1.readFileSync)(node_path_1.default.join(commandLine_1.cmdLine.sourcepath, filename), { flag: 'r' }));
for (const sameFile of findSimilarFiles(result))
console.log((0, consoleColor_1.yellowLog)(` ${sameFile.join(', ')} files look like identical`));
return result;
};
exports.getFiles = getFiles;
;