-
Notifications
You must be signed in to change notification settings - Fork 17
/
reducio.js
55 lines (47 loc) · 1.06 KB
/
reducio.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/env node
var tar=require('tar');
var chalk=require('chalk');
var fs = require('fs-extra');
if(process.argv.length < 4){
console.log(chalk.red('IndexError: Index out of range!'));
return;
}
else{
var sources = [];
for (var i = 2; i < process.argv.length-1; i++)
{
sources.push(process.argv[i]);
}
var destination = process.argv[process.argv.length-1];
var destination=destination.split("/");
if(destination.length != 1){
var filename = destination.pop();
destination = destination.join("/");
if (!fs.existsSync(destination)){
destination = '/' + destination;
}
if(!filename.endsWith('.tgz')){
filename += '.tgz';
}
destination += "/" + filename;
}
else{
filename=destination.pop();
if(!filename.endsWith('.tgz')){
filename += '.tgz';
}
destination = filename;
}
tar.c(
{
gzip: true,
file: destination
},
sources
).then(function(res) {
console.log(chalk.yellow('Successfully compressed'));
}).
catch(function(err){
console.log(chalk.red('FileError: No such file/directory exists'));
});
}