Skip to content

Commit

Permalink
#3 ignored files feature
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeLit committed Nov 28, 2023
1 parent ad4cfcb commit 68b8b3c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
15 changes: 14 additions & 1 deletion src/backups.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 68b8b3c

Please sign in to comment.