diff --git a/README.md b/README.md index 9ab73a5..de7d833 100644 --- a/README.md +++ b/README.md @@ -137,11 +137,15 @@ How many copies need to be in according folders, file tree will look like this: - `best`: best and slowest compression - `none`: no compression -### 🔧 `filter_ignored_folders` option: +### 🔧 `filter_commonly_ignored_folders` option: -- `true` (default): ignores all **.git, node_modules, vendor**, etc folders +- `true` (default): ignores all **.git, node_modules, vendor**, etc folders; adds it to **filter** option - `false`: does nothing +### 🔧 `filter_ignored` option: + +- `false` (default): does nothing +- `true`: ignores records in .gitignore file; adds it to **filter** option ## Ⓜ️ Mega Online Cloud storage integration diff --git a/src/backups.js b/src/backups.js index 6bc3ebc..3226dad 100644 --- a/src/backups.js +++ b/src/backups.js @@ -45,13 +45,26 @@ async function handeBackup(backupJson, projectPath, rewriteDate = undefined) { // https://www.npmjs.com/package/maximatch backup.filter = backupJson.filter || []; - if (backupJson.filter_ignored_folders !== false) { + if (backupJson.filter_commonly_ignored_folders !== false) { backup.filter = [ ...backup.filter, ...['**/vendor/**', '**/node_modules/**', '.git/**', '**/__pycache__/**'], ]; } + if (backupJson.filter_gitignored === true) { + try { + const gitignoreRules = fs + .readFileSync(path.normalize(`${projectPath}/.gitignore`), 'utf8') + .split('\n') + .map((line) => line.trim()) + .filter((line) => line !== '' && !line.startsWith('#')); + backup.filter = [...backup.filter, ...gitignoreRules]; + } catch (err) { + console.error(`Error reading ${projectPath}/.gitignore: ${err.message}`); + } + } + const compressionMap = { none: zlib.constants.Z_NO_COMPRESSION, default: zlib.constants.Z_DEFAULT_COMPRESSION,