auto-git:
[change] main.js
This commit is contained in:
77
main.js
77
main.js
@@ -293,20 +293,6 @@ function buildCommitMessageFromStatus(status, prefix = '[auto]') {
|
|||||||
return prefix + '\n' + changes.map(l => ` ${l}`).join('\n');
|
return prefix + '\n' + changes.map(l => ` ${l}`).join('\n');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function ensureInGitignore(folderPath, name) {
|
|
||||||
const gitignorePath = path.join(folderPath, '.gitignore');
|
|
||||||
let lines = [];
|
|
||||||
if (fs.existsSync(gitignorePath)) {
|
|
||||||
lines = fs.readFileSync(gitignorePath, 'utf-8').split(/\r?\n/);
|
|
||||||
}
|
|
||||||
// Schon drin?
|
|
||||||
if (lines.some(line => line.trim() === name)) return;
|
|
||||||
// Anfügen
|
|
||||||
fs.appendFileSync(gitignorePath, '\n' + name + '\n');
|
|
||||||
}
|
|
||||||
|
|
||||||
const IGNORED_NAMES = [
|
const IGNORED_NAMES = [
|
||||||
// Betriebssystem-spezifische Dateien
|
// Betriebssystem-spezifische Dateien
|
||||||
'.DS_Store', // macOS
|
'.DS_Store', // macOS
|
||||||
@@ -669,6 +655,26 @@ const IGNORED_NAMES = [
|
|||||||
const monitoringQueues = new Map(); // Map: folderPath -> Array<Function>
|
const monitoringQueues = new Map(); // Map: folderPath -> Array<Function>
|
||||||
const monitoringActive = new Map(); // Map: folderPath -> Boolean (ob Task aktiv)
|
const monitoringActive = new Map(); // Map: folderPath -> Boolean (ob Task aktiv)
|
||||||
|
|
||||||
|
const MONITOR_DEFAULT_IGNORES = [
|
||||||
|
'.git',
|
||||||
|
'node_modules',
|
||||||
|
'dist',
|
||||||
|
'build',
|
||||||
|
'out',
|
||||||
|
'.next',
|
||||||
|
'.nuxt',
|
||||||
|
'.turbo',
|
||||||
|
'.parcel-cache',
|
||||||
|
'.cache',
|
||||||
|
'coverage',
|
||||||
|
'logs',
|
||||||
|
'tmp',
|
||||||
|
'temp',
|
||||||
|
'*.log',
|
||||||
|
'*.tmp',
|
||||||
|
'*.swp'
|
||||||
|
];
|
||||||
|
|
||||||
function enqueueTask(folderPath, fn) {
|
function enqueueTask(folderPath, fn) {
|
||||||
if (!monitoringQueues.has(folderPath)) monitoringQueues.set(folderPath, []);
|
if (!monitoringQueues.has(folderPath)) monitoringQueues.set(folderPath, []);
|
||||||
monitoringQueues.get(folderPath).push(fn);
|
monitoringQueues.get(folderPath).push(fn);
|
||||||
@@ -693,7 +699,7 @@ async function processQueue(folderPath) {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
function ensureInGitignore(folderPath, name) {
|
function ensureInGitignore(folderPath, name, igInstance) {
|
||||||
const gitignorePath = path.join(folderPath, '.gitignore');
|
const gitignorePath = path.join(folderPath, '.gitignore');
|
||||||
let lines = [];
|
let lines = [];
|
||||||
if (fs.existsSync(gitignorePath)) {
|
if (fs.existsSync(gitignorePath)) {
|
||||||
@@ -701,6 +707,9 @@ function ensureInGitignore(folderPath, name) {
|
|||||||
}
|
}
|
||||||
if (lines.some(line => line.trim() === name)) return false;
|
if (lines.some(line => line.trim() === name)) return false;
|
||||||
fs.appendFileSync(gitignorePath, name + '\n');
|
fs.appendFileSync(gitignorePath, name + '\n');
|
||||||
|
if (igInstance) {
|
||||||
|
igInstance.add(name);
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -709,6 +718,7 @@ function startMonitoringWatcher(folderPath, win) {
|
|||||||
|
|
||||||
// 1. Load .gitignore (and add default rules for .git, node_modules, etc.)
|
// 1. Load .gitignore (and add default rules for .git, node_modules, etc.)
|
||||||
const ig = ignore();
|
const ig = ignore();
|
||||||
|
ig.add(MONITOR_DEFAULT_IGNORES);
|
||||||
const gitignorePath = path.join(folderPath, '.gitignore');
|
const gitignorePath = path.join(folderPath, '.gitignore');
|
||||||
if (fs.existsSync(gitignorePath)) {
|
if (fs.existsSync(gitignorePath)) {
|
||||||
ig.add(fs.readFileSync(gitignorePath, 'utf-8'));
|
ig.add(fs.readFileSync(gitignorePath, 'utf-8'));
|
||||||
@@ -731,7 +741,7 @@ function startMonitoringWatcher(folderPath, win) {
|
|||||||
// 3. Create the watcher, now with deep ignore support!
|
// 3. Create the watcher, now with deep ignore support!
|
||||||
const watcher = chokidar.watch(folderPath, {
|
const watcher = chokidar.watch(folderPath, {
|
||||||
ignored: ignoredFunc,
|
ignored: ignoredFunc,
|
||||||
ignoreInitial: false,
|
ignoreInitial: true,
|
||||||
persistent: true,
|
persistent: true,
|
||||||
depth: 99,
|
depth: 99,
|
||||||
awaitWriteFinish: { stabilityThreshold: 300, pollInterval: 100 }
|
awaitWriteFinish: { stabilityThreshold: 300, pollInterval: 100 }
|
||||||
@@ -739,11 +749,14 @@ function startMonitoringWatcher(folderPath, win) {
|
|||||||
|
|
||||||
let debounceTimer = null;
|
let debounceTimer = null;
|
||||||
let pendingNames = new Set();
|
let pendingNames = new Set();
|
||||||
|
let pendingPaths = new Set();
|
||||||
|
|
||||||
function handleDebounced() {
|
function handleDebounced() {
|
||||||
enqueueTask(folderPath, async () => {
|
enqueueTask(folderPath, async () => {
|
||||||
const namesArr = Array.from(pendingNames);
|
const namesArr = Array.from(pendingNames);
|
||||||
|
const pathsArr = Array.from(pendingPaths);
|
||||||
pendingNames.clear();
|
pendingNames.clear();
|
||||||
|
pendingPaths.clear();
|
||||||
|
|
||||||
// .gitignore sofort synchron aktualisieren (im Event-Handler)
|
// .gitignore sofort synchron aktualisieren (im Event-Handler)
|
||||||
let gitignoreChanged = false;
|
let gitignoreChanged = false;
|
||||||
@@ -751,16 +764,30 @@ function startMonitoringWatcher(folderPath, win) {
|
|||||||
for (const name of IGNORED_NAMES) {
|
for (const name of IGNORED_NAMES) {
|
||||||
if (name.includes('*')) {
|
if (name.includes('*')) {
|
||||||
if (micromatch.isMatch(fileOrDirName, name)) {
|
if (micromatch.isMatch(fileOrDirName, name)) {
|
||||||
gitignoreChanged = ensureInGitignore(folderPath, name) || gitignoreChanged;
|
gitignoreChanged = ensureInGitignore(folderPath, name, ig) || gitignoreChanged;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (fileOrDirName === name.replace(/\/$/, '')) {
|
if (fileOrDirName === name.replace(/\/$/, '')) {
|
||||||
gitignoreChanged = ensureInGitignore(folderPath, name) || gitignoreChanged;
|
gitignoreChanged = ensureInGitignore(folderPath, name, ig) || gitignoreChanged;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (gitignoreChanged) {
|
||||||
|
const toUnwatch = [];
|
||||||
|
for (const p of pathsArr) {
|
||||||
|
const rel = path.relative(folderPath, p);
|
||||||
|
if (ig.ignores(rel)) {
|
||||||
|
toUnwatch.push(p);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (toUnwatch.length) {
|
||||||
|
watcher.unwatch(toUnwatch);
|
||||||
|
debug(`[MONITOR] Unwatched ${toUnwatch.length} path(s) after adding ignores for ${folderPath}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Danach wie gehabt:
|
// Danach wie gehabt:
|
||||||
const git = simpleGit(folderPath);
|
const git = simpleGit(folderPath);
|
||||||
const status = await git.status();
|
const status = await git.status();
|
||||||
@@ -782,11 +809,25 @@ function startMonitoringWatcher(folderPath, win) {
|
|||||||
watcher.on(ev, filePath => {
|
watcher.on(ev, filePath => {
|
||||||
const fileOrDirName = path.basename(filePath);
|
const fileOrDirName = path.basename(filePath);
|
||||||
pendingNames.add(fileOrDirName);
|
pendingNames.add(fileOrDirName);
|
||||||
|
pendingPaths.add(filePath);
|
||||||
if (debounceTimer) clearTimeout(debounceTimer);
|
if (debounceTimer) clearTimeout(debounceTimer);
|
||||||
debounceTimer = setTimeout(handleDebounced, 500);
|
debounceTimer = setTimeout(handleDebounced, 500);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
watcher.on('error', err => {
|
||||||
|
debug(`[MONITOR] Watcher error for ${folderPath}: ${err.message || err}`);
|
||||||
|
if (err && err.code === 'EMFILE') {
|
||||||
|
let folders = store.get('folders') || [];
|
||||||
|
folders = folders.map(f =>
|
||||||
|
f.path === folderPath ? { ...f, monitoring: false } : f
|
||||||
|
);
|
||||||
|
store.set('folders', folders);
|
||||||
|
stopMonitoringWatcher(folderPath);
|
||||||
|
win.webContents.send('monitoring-error', { path: folderPath, code: 'EMFILE' });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// Initialer Commit (direkt in Queue, wie ein Event)
|
// Initialer Commit (direkt in Queue, wie ein Event)
|
||||||
enqueueTask(folderPath, async () => {
|
enqueueTask(folderPath, async () => {
|
||||||
debug(`[MONITOR] Starte initialen Commit-Check für ${folderPath}`);
|
debug(`[MONITOR] Starte initialen Commit-Check für ${folderPath}`);
|
||||||
|
|||||||
Reference in New Issue
Block a user