mirror of
https://github.com/spacebarchat/server.git
synced 2026-05-28 03:15:00 +00:00
Basic client patching system
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
const { execSync } = require("child_process");
|
||||
const path = require("path");
|
||||
const fs = require("fs");
|
||||
const { argv, stdout, exit } = require("process");
|
||||
const { execIn, parts, getDirs, walk, sanitizeVarName } = require("../utils");
|
||||
|
||||
//apply patches
|
||||
const patchDir = path.join(__dirname, "..", "..", "assets", "testclient_patches");
|
||||
const targetDir = path.join(__dirname, "..", "..", "assets", "cache");
|
||||
const files = fs.readdirSync(patchDir);
|
||||
files.forEach((file) => {
|
||||
const filePath = path.join(patchDir, file);
|
||||
const stats = fs.statSync(filePath);
|
||||
if (stats.isFile()) {
|
||||
const ext = path.extname(file);
|
||||
if (ext === ".patch") {
|
||||
execSync(`git apply ${filePath}`, {
|
||||
cwd: targetDir,
|
||||
maxBuffer: 1024 * 1024 * 10,
|
||||
});
|
||||
console.log(`Applied patch ${file} to ${newFilePath}`);
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,40 @@
|
||||
const { execSync } = require("child_process");
|
||||
const path = require("path");
|
||||
const fs = require("fs");
|
||||
const { argv, stdout, exit } = require("process");
|
||||
const { execIn, parts, getDirs, walk, sanitizeVarName } = require("../utils");
|
||||
|
||||
//generate git patch for each file in assets/cache
|
||||
const srcDir = path.join(__dirname, "..", "..", "assets", "cache");
|
||||
const destDir = path.join(__dirname, "..", "..", "assets", "cache_src");
|
||||
const patchDir = path.join(__dirname, "..", "..", "assets", "testclient_patches");
|
||||
if(!fs.existsSync(patchDir)) fs.mkdirSync(patchDir);
|
||||
const files = fs.readdirSync(srcDir);
|
||||
files.forEach((file) => {
|
||||
const filePath = path.join(srcDir, file);
|
||||
const stats = fs.statSync(filePath);
|
||||
if (stats.isFile()) {
|
||||
const ext = path.extname(file);
|
||||
if (ext === ".js" || ext === ".css") {
|
||||
const newFilePath = path.join(destDir, file);
|
||||
//check if file has been modified
|
||||
let patch;
|
||||
try {
|
||||
let es = execSync(`diff -du --speed-large-files --horizon-lines=0 ${newFilePath} ${filePath}`, {
|
||||
maxBuffer: 1024 * 1024 * 10,
|
||||
}).toString();
|
||||
patch="";
|
||||
} catch (e) {
|
||||
patch = e.stdout.toString().replaceAll(path.join(destDir, file), file).replaceAll(path.join(srcDir, file), file);
|
||||
}
|
||||
if (patch.length > 0) {
|
||||
//generate patch;
|
||||
fs.writeFileSync(path.join(patchDir, file + ".patch"), patch);
|
||||
console.log(`Generated patch for ${file}: ${patch.length} bytes, ${patch.split("\n").length} lines, ${patch.split("\n").filter((x) => x.startsWith("+")).length} additions, ${patch.split("\n").filter((x) => x.startsWith("-")).length} deletions`);
|
||||
}
|
||||
else {
|
||||
//console.log(`No changes for ${file}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,75 @@
|
||||
const { execSync } = require("child_process");
|
||||
const path = require("path");
|
||||
const fs = require("fs");
|
||||
const { argv, stdout, exit } = require("process");
|
||||
const { execIn, parts, getDirs, walk, sanitizeVarName } = require("../utils");
|
||||
|
||||
//copy all js and css files from assets/cache to assets/dist
|
||||
const srcDir = path.join(__dirname, "..", "..", "assets", "cache");
|
||||
const destDir = path.join(__dirname, "..", "..", "assets", "cache_src");
|
||||
if(!fs.existsSync(destDir)) fs.mkdirSync(destDir);
|
||||
const files = fs.readdirSync(srcDir);
|
||||
files.forEach((file) => {
|
||||
const filePath = path.join(srcDir, file);
|
||||
const stats = fs.statSync(filePath);
|
||||
if (stats.isFile()) {
|
||||
const ext = path.extname(file);
|
||||
if (ext === ".js" || ext === ".css") {
|
||||
const newFilePath = path.join(destDir, file);
|
||||
if(!fs.existsSync(newFilePath)) {
|
||||
fs.copyFileSync(filePath, newFilePath);
|
||||
console.log(`Copied ${file} to ${newFilePath}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
if(!fs.existsSync(path.join(srcDir, ".vscode"))) fs.mkdirSync(path.join(srcDir, ".vscode"));
|
||||
fs.writeFileSync(path.join(srcDir, ".vscode", "settings.json"), JSON.stringify({
|
||||
"codemetrics.basics.DecorationModeEnabled": false,
|
||||
"codemetrics.basics.CodeLensEnabled": false,
|
||||
"editor.codeLens": false,
|
||||
//"editor.minimap.enabled": false,
|
||||
"codemetrics.basics.MetricsForArrowFunctionsToggled": false,
|
||||
"codemetrics.basics.MetricsForClassDeclarationsToggled": false,
|
||||
"codemetrics.basics.MetricsForConstructorsToggled": false,
|
||||
"codemetrics.basics.MetricsForEnumDeclarationsToggled": false,
|
||||
"codemetrics.basics.MetricsForFunctionExpressionsToggled": false,
|
||||
"codemetrics.basics.MetricsForFunctionDeclarationsToggled": false,
|
||||
"codemetrics.basics.MetricsForMethodDeclarationsToggled": false,
|
||||
"codemetrics.basics.OverviewRulerModeEnabled": false,
|
||||
"editor.fontFamily": "'JetBrainsMono Nerd Font', 'JetBrainsMono', 'Droid Sans Mono', 'monospace', monospace",
|
||||
"editor.accessibilityPageSize": 1,
|
||||
"editor.accessibilitySupport": "off",
|
||||
"editor.autoClosingDelete": "never",
|
||||
//"editor.autoIndent": "none",
|
||||
//"editor.colorDecorators": false,
|
||||
"editor.comments.ignoreEmptyLines": false,
|
||||
"editor.copyWithSyntaxHighlighting": false,
|
||||
"editor.comments.insertSpace": false,
|
||||
"editor.detectIndentation": false,
|
||||
"editor.dragAndDrop": false,
|
||||
"editor.dropIntoEditor.enabled": false,
|
||||
"editor.experimental.pasteActions.enabled": false,
|
||||
"editor.guides.highlightActiveIndentation": false,
|
||||
"color-highlight.enable": false,
|
||||
"gitlens.blame.highlight.locations": [
|
||||
"gutter"
|
||||
],
|
||||
"todohighlight.isEnable": false,
|
||||
"todohighlight.maxFilesForSearch": 1,
|
||||
"editor.maxTokenizationLineLength": 1200,
|
||||
"editor.minimap.maxColumn": 140,
|
||||
"explorer.openEditors.visible": 0,
|
||||
"editor.fontLigatures": false,
|
||||
"files.exclude": {
|
||||
"*.mp3": true,
|
||||
"*.png": true,
|
||||
"*.svg": true,
|
||||
"*.webm": true,
|
||||
"*.webp": true,
|
||||
"*.woff2": true,
|
||||
"**/.vscode/": true
|
||||
},
|
||||
"editor.guides.bracketPairs": true
|
||||
}, null, 4));
|
||||
console.log(`Workspace prepared at ${srcDir}!`);
|
||||
@@ -0,0 +1,24 @@
|
||||
const { execSync } = require("child_process");
|
||||
const path = require("path");
|
||||
const fs = require("fs");
|
||||
const { argv, stdout, exit } = require("process");
|
||||
const { execIn, parts, getDirs, walk, sanitizeVarName } = require("../utils");
|
||||
|
||||
//copy all js and css files from assets/cache_src to assets/cache
|
||||
const srcDir = path.join(__dirname, "..", "..", "assets", "cache_src");
|
||||
const destDir = path.join(__dirname, "..", "..", "assets", "cache");
|
||||
if(!fs.existsSync(destDir)) fs.mkdirSync(destDir);
|
||||
const files = fs.readdirSync(srcDir);
|
||||
files.forEach((file) => {
|
||||
const filePath = path.join(srcDir, file);
|
||||
const stats = fs.statSync(filePath);
|
||||
if (stats.isFile()) {
|
||||
const ext = path.extname(file);
|
||||
if (ext === ".js" || ext === ".css") {
|
||||
const newFilePath = path.join(destDir, file);
|
||||
fs.rmSync(newFilePath);
|
||||
fs.copyFileSync(filePath, newFilePath);
|
||||
console.log(`Copied ${file} to ${newFilePath}`);
|
||||
}
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user