Compare commits

8 Commits

8 changed files with 686 additions and 545 deletions

15
.eslintrc.json Normal file
View File

@@ -0,0 +1,15 @@
{
"env": {
"commonjs": true,
"es2021": true,
"node": true
},
"extends": [
"google"
],
"parserOptions": {
"ecmaVersion": "latest"
},
"rules": {
}
}

6
.vscode/settings.json vendored Normal file
View File

@@ -0,0 +1,6 @@
{
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
},
"eslint.validate": ["javascript"]
}

View File

@@ -7,7 +7,7 @@ This branch is a rewrite of the [previous in Java Developed branch](https://git.
### Requirements
- NodeJS >= 14
You can either: [Build a executeable](#build-a-executeable) or [Runing from Source](#running-from-source)
You can either: [Build a executeable](#build-a-executeable) or [Running from Source](#running-from-source)
### Build a executeable
@@ -43,7 +43,7 @@ pnpm run pkg
yarn run pkg
```
Your builded binary executeable should be in bin/
Your builded binary executeable should be located in `bin/`
### Running from Source

View File

@@ -1,78 +1,79 @@
/* eslint-disable require-jsdoc */
const fs = require('fs');
const path = require('path');
const { EventEmitter } = require('events');
const {EventEmitter} = require('events');
class Archiver {
constructor(backupPath, backupPaths, gzip, gzipLevel) {
this.backupPath = backupPath;
this.backupPaths = backupPaths;
this.eventEmitter = new EventEmitter();
this.archive = require('archiver')('tar', {
gzip: gzip,
gzipOptions: { level: gzipLevel }
});
this.totalFiles = 0;
constructor(backupPath, backupPaths, gzip, gzipLevel) {
this.backupPath = backupPath;
this.backupPaths = backupPaths;
this.eventEmitter = new EventEmitter();
this.archive = require('archiver')('tar', {
gzip: gzip,
gzipOptions: {level: gzipLevel},
});
this.totalFiles = 0;
}
start() {
const EVENT_EMITTER = this.eventEmitter;
const ARCHIVE_LOCATION = path.join(this.backupPath);
const OUTPUT = fs.createWriteStream(ARCHIVE_LOCATION);
OUTPUT.on('close', function() {
EVENT_EMITTER.emit('finish');
});
OUTPUT.on('end', function() {
console.log('Data has been drained');
});
this.archive.on('warning', function(err) {
if (err.code === 'ENOENT') console.log(err);
else throw err;
});
this.archive.on('error', function(err) {
throw err;
});
this.archive.on('progress', function(progressInfo) {
EVENT_EMITTER.emit('progress', progressInfo);
});
// pipe archive data to the file
this.archive.pipe(OUTPUT);
for (const ITEM of this.backupPaths) {
if (!fs.existsSync(ITEM)) continue;
const IS_DIR = fs.lstatSync(ITEM).isDirectory();
if (IS_DIR) {
this.archive.directory(ITEM, path.basename(ITEM));
const COUNTED = require('count-files-dirs').countSync(ITEM);
this.totalFiles += COUNTED.fileCount + COUNTED.dirCount;
} else {
this.archive.file(ITEM, {name: path.basename(ITEM)});
this.totalFiles++;
}
}
}
start() {
const EVENT_EMITTER = this.eventEmitter;
const ARCHIVE_LOCATION = path.join(this.backupPath);
const OUTPUT = fs.createWriteStream(ARCHIVE_LOCATION);
OUTPUT.on('close', function () {
EVENT_EMITTER.emit('finish');
});
OUTPUT.on('end', function () {
console.log('Data has been drained');
});
this.archive.on('warning', function (err) {
if (err.code === 'ENOENT') console.log(err);
else throw err;
});
this.archive.on('error', function (err) {
throw err;
});
this.archive.on('progress', function (progressInfo) {
EVENT_EMITTER.emit('progress', progressInfo);
});
// pipe archive data to the file
this.archive.pipe(OUTPUT);
for (const ITEM of this.backupPaths) {
if (!fs.existsSync(ITEM)) continue;
const IS_DIR = fs.lstatSync(ITEM).isDirectory();
if (IS_DIR) {
this.archive.directory(ITEM, path.basename(ITEM));
const COUNTED = require('count-files-dirs').countSync(ITEM);
this.totalFiles += COUNTED.fileCount + COUNTED.dirCount;
} else {
this.archive.file(ITEM, { name: path.basename(ITEM) });
this.totalFiles++;
}
}
add(item) {
if (!fs.existsSync(item)) return;
const IS_DIR = fs.lstatSync(item).isDirectory();
if (IS_DIR) {
this.archive.directory(item, path.basename(item));
const COUNTED = require('count-files-dirs').countSync(item);
this.totalFiles += COUNTED.fileCount + COUNTED.dirCount;
} else {
this.archive.file(item, {name: path.basename(item)});
this.totalFiles++;
}
}
add(item) {
if (!fs.existsSync(item)) return;
const IS_DIR = fs.lstatSync(item).isDirectory();
if (IS_DIR) {
this.archive.directory(item, path.basename(item));
const COUNTED = require('count-files-dirs').countSync(item);
this.totalFiles += COUNTED.fileCount + COUNTED.dirCount;
} else {
this.archive.file(item, { name: path.basename(item) });
this.totalFiles++;
}
}
pack() {
this.archive.finalize();
}
pack() {
this.archive.finalize();
}
}
module.exports = Archiver;
module.exports = Archiver;

1007
index.js

File diff suppressed because it is too large Load Diff

View File

@@ -1,17 +1,17 @@
const ansiColors = require('ansi-colors');
module.exports = {
info(message) {
console.log(ansiColors.bold.blue("🛈") + " " + ansiColors.bold(message));
},
warn(message) {
console.log(ansiColors.bold.yellow("⚠") + " " + ansiColors.bold(message));
},
error(message) {
console.log(ansiColors.red.red("✖") + " " + ansiColors.bold(message));
},
success(message) {
console.log(ansiColors.green("✔") + " " + ansiColors.bold(message));
}
}
info(message) {
console.log(ansiColors.bold.blue('🛈') + ' ' + ansiColors.bold(message));
},
warn(message) {
console.log(ansiColors.bold.yellow('⚠') + ' ' + ansiColors.bold(message));
},
error(message) {
console.log(ansiColors.red.red('✖') + ' ' + ansiColors.bold(message));
},
success(message) {
console.log(ansiColors.green('✔') + ' ' + ansiColors.bold(message));
},
};

View File

@@ -14,6 +14,8 @@
"author": "",
"license": "ISC",
"devDependencies": {
"eslint": ">=5.16.0",
"eslint-config-google": "^0.14.0",
"pkg": "^5.8.0"
},
"dependencies": {
@@ -21,12 +23,25 @@
"ansi-colors": "^4.1.3",
"archiver": "^5.3.1",
"count-files-dirs": "^0.2.3",
"crontab": "^1.4.2",
"fs-extra": "^10.1.0",
"moment": "^2.29.4",
"mysqldump": "^3.2.0",
"ora": "5.4.1",
"prettytime": "^1.0.0",
"prompts": "^2.4.2",
"recursive-readdir": "^2.2.2",
"tiny-glob": "^0.2.9"
},
"pnpm": {
"overrides": {
"minimist@<1.2.6": ">=1.2.6",
"braces@<2.3.1": ">=2.3.1",
"diff@<3.5.0": ">=3.5.0",
"minimatch@<3.0.2": ">=3.0.2",
"debug@<2.6.9": ">=2.6.9",
"minimist@<0.2.1": ">=0.2.1",
"glob-parent@<5.1.2": ">=5.1.2",
"growl@<1.10.0": ">=1.10.0"
}
}
}

View File

@@ -1,13 +1,14 @@
const prettytime = require('prettytime')
/* eslint-disable require-jsdoc */
const prettytime = require('prettytime');
class Timer {
startTimer() {
this.start = Date.now();
return this;
}
startTimer() {
this.start = Date.now();
return this;
}
endTimer() {
return prettytime(Date.now() - this.start, { decimals: 2 });
}
endTimer() {
return prettytime(Date.now() - this.start, {decimals: 2});
}
}
module.exports = Timer;
module.exports = Timer;