dir-archiver 1.2.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +16 -5
- package/cli.js +14 -4
- package/index.js +15 -4
- package/package.json +2 -2
- package/CHANGELOG.md +0 -28
package/README.md
CHANGED
|
@@ -25,9 +25,14 @@ const excludes = ['directory_name', 'file.extension'];
|
|
|
25
25
|
* Create a dir-archiver object.
|
|
26
26
|
* @param {string} directoryPath - The path of the folder to archive.
|
|
27
27
|
* @param {string} zipPath - The path of the zip file to create.
|
|
28
|
+
* @param {Boolean} includeBaseDirectory - Includes a base directory at the root of the archive.
|
|
29
|
+
* For example, if the root folder of your project is named "your-project", setting
|
|
30
|
+
* includeBaseDirectory to true will create an archive that includes this base directory.
|
|
31
|
+
* If this option is set to false the archive created will unzip its content to
|
|
32
|
+
* the current directory.
|
|
28
33
|
* @param {array} excludes - A list with the names of the files and folders to exclude.
|
|
29
34
|
*/
|
|
30
|
-
var archive = new DirArchiver('path/to/directory', 'path/to/desination/zipfile.zip', excludes);
|
|
35
|
+
var archive = new DirArchiver('path/to/directory', 'path/to/desination/zipfile.zip', true, excludes);
|
|
31
36
|
|
|
32
37
|
// Create the zip file.
|
|
33
38
|
archive.createZip();
|
|
@@ -35,12 +40,18 @@ archive.createZip();
|
|
|
35
40
|
## Command Line Interface
|
|
36
41
|
|
|
37
42
|
```sh
|
|
38
|
-
Usage: dir-archiver --src <path-to-directory> --dest <path-to-file>.zip --exclude folder-name file-name.extention
|
|
43
|
+
Usage: dir-archiver --src <path-to-directory> --dest <path-to-file>.zip --includebasedir true|false --exclude folder-name file-name.extention
|
|
39
44
|
|
|
40
45
|
Options:
|
|
41
|
-
--src
|
|
42
|
-
--dest
|
|
43
|
-
--
|
|
46
|
+
--src The path of the folder to archive. [string][required]
|
|
47
|
+
--dest The path of the zip file to create. [string][required]
|
|
48
|
+
--includebasedir Includes a base directory at the root of the archive.
|
|
49
|
+
For example, if the root folder of your project is named
|
|
50
|
+
"your-project", setting this option to true will create
|
|
51
|
+
an archive that includes this base directory.
|
|
52
|
+
If this option is set to false the archive created will
|
|
53
|
+
unzip its content to the current directory. [bool]
|
|
54
|
+
--exclude A list with the names of the files and folders to exclude. [array]
|
|
44
55
|
```
|
|
45
56
|
|
|
46
57
|
|
package/cli.js
CHANGED
|
@@ -5,15 +5,22 @@ var DirArchiver = require('./index');
|
|
|
5
5
|
const arguments = process.argv;
|
|
6
6
|
var directoryPath = '';
|
|
7
7
|
var zipPath = '';
|
|
8
|
+
var includeBaseDirectory = true;
|
|
8
9
|
var excludes = [];
|
|
9
10
|
|
|
10
11
|
if ( ! arguments.includes( '--src' ) || ! arguments.includes( '--dest' ) ) {
|
|
11
12
|
console.log(` Dir Archiver could not be executed. Some arguments are missing.
|
|
12
13
|
|
|
13
14
|
Options:
|
|
14
|
-
--src
|
|
15
|
-
--dest
|
|
16
|
-
--
|
|
15
|
+
--src The path of the folder to archive. [string][required]
|
|
16
|
+
--dest The path of the zip file to create. [string][required]
|
|
17
|
+
--includebasedir Includes a base directory at the root of the archive.
|
|
18
|
+
For example, if the root folder of your project is named
|
|
19
|
+
"your-project", setting this option to true will create
|
|
20
|
+
an archive that includes this base directory.
|
|
21
|
+
If this option is set to false the archive created will
|
|
22
|
+
unzip its content to the current directory. [bool]
|
|
23
|
+
--exclude A list with the names of the files and folders to exclude. [array]`);
|
|
17
24
|
process.exit();
|
|
18
25
|
}
|
|
19
26
|
|
|
@@ -24,6 +31,9 @@ for ( argumentIndex in arguments ) {
|
|
|
24
31
|
if( arguments[argumentIndex] === '--dest' ) {
|
|
25
32
|
zipPath = arguments[parseInt(argumentIndex) + 1];
|
|
26
33
|
}
|
|
34
|
+
if( arguments[argumentIndex] === '--includebasedir' ) {
|
|
35
|
+
includeBaseDirectory = ( arguments[parseInt(argumentIndex) + 1] === 'true' );
|
|
36
|
+
}
|
|
27
37
|
if( afterExclude === true ) {
|
|
28
38
|
excludes.push( arguments[argumentIndex] );
|
|
29
39
|
}
|
|
@@ -32,5 +42,5 @@ for ( argumentIndex in arguments ) {
|
|
|
32
42
|
}
|
|
33
43
|
}
|
|
34
44
|
|
|
35
|
-
const archive = new DirArchiver(directoryPath, zipPath, excludes);
|
|
45
|
+
const archive = new DirArchiver(directoryPath, zipPath, includeBaseDirectory, excludes);
|
|
36
46
|
archive.createZip();
|
package/index.js
CHANGED
|
@@ -9,9 +9,10 @@ class DirArchiver {
|
|
|
9
9
|
* The constructor.
|
|
10
10
|
* @param {string} directoryPath - the path of the folder to archive.
|
|
11
11
|
* @param {string} zipPath - The path of the zip file to create.
|
|
12
|
+
* @param {Boolean} includeBaseDirectory - Includes a base directory at the root of the archive. For example, if the root folder of your project is named "your-project", setting includeBaseDirectory to true will create an archive that includes this base directory. If this option is set to false the archive created will unzip its content to the current directory.
|
|
12
13
|
* @param {array} excludes - The name of the files and foldes to exclude.
|
|
13
14
|
*/
|
|
14
|
-
constructor(directoryPath, zipPath, excludes){
|
|
15
|
+
constructor(directoryPath, zipPath, includeBaseDirectory, excludes){
|
|
15
16
|
|
|
16
17
|
// Contains the excluded files and folders.
|
|
17
18
|
this.excludes = excludes;
|
|
@@ -19,6 +20,10 @@ class DirArchiver {
|
|
|
19
20
|
this.directoryPath = directoryPath;
|
|
20
21
|
|
|
21
22
|
this.zipPath = zipPath;
|
|
23
|
+
|
|
24
|
+
this.includeBaseDirectory = includeBaseDirectory;
|
|
25
|
+
|
|
26
|
+
this.baseDirectory = path.basename(path.resolve(directoryPath));
|
|
22
27
|
}
|
|
23
28
|
|
|
24
29
|
/**
|
|
@@ -32,9 +37,15 @@ class DirArchiver {
|
|
|
32
37
|
const stats = fs.statSync( currentPath );
|
|
33
38
|
let relativePath = path.relative(process.cwd(), currentPath);
|
|
34
39
|
if ( stats.isFile() && ! this.excludes.includes( relativePath ) ) {
|
|
35
|
-
this.
|
|
36
|
-
|
|
37
|
-
|
|
40
|
+
if( this.includeBaseDirectory === true) {
|
|
41
|
+
this.archive.file(currentPath, {
|
|
42
|
+
name: `${this.baseDirectory}/${relativePath}`
|
|
43
|
+
});
|
|
44
|
+
} else {
|
|
45
|
+
this.archive.file(currentPath, {
|
|
46
|
+
name: `${relativePath}`
|
|
47
|
+
});
|
|
48
|
+
}
|
|
38
49
|
} else if ( stats.isDirectory() && ! this.excludes.includes( relativePath ) ) {
|
|
39
50
|
this.traverseDirectoryTree( currentPath );
|
|
40
51
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dir-archiver",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "Compress a whole directory (including subdirectories) into a zip file, with options to exclude specific files, or directories.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "index.js",
|
|
@@ -32,6 +32,6 @@
|
|
|
32
32
|
"bugs": "https://github.com/Ismail-elkorchi/dir-archiver/issues",
|
|
33
33
|
"homepage": "https://github.com/Ismail-elkorchi/dir-archiver",
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"archiver": "^5.
|
|
35
|
+
"archiver": "^5.3.1"
|
|
36
36
|
}
|
|
37
37
|
}
|
package/CHANGELOG.md
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
# Changes to Dir Archiver
|
|
2
|
-
|
|
3
|
-
### 1.2.0 (February 28, 2021)
|
|
4
|
-
|
|
5
|
-
* Bump archiver from 4.0.2 to 5.2.0.
|
|
6
|
-
* Make exclude paths relative to run directory ([#4](https://github.com/Ismail-elkorchi/dir-archiver/pull/4))
|
|
7
|
-
* Remove the destination zip if it exists already ([#7](https://github.com/Ismail-elkorchi/dir-archiver/pull/7))
|
|
8
|
-
|
|
9
|
-
### 1.1.2 (July 21, 2020)
|
|
10
|
-
|
|
11
|
-
* Bump lodash from 4.17.15 to 4.17.19.
|
|
12
|
-
* Bump archiver from 4.0.1 to 4.0.2.
|
|
13
|
-
|
|
14
|
-
### 1.1.1 (May 14, 2020)
|
|
15
|
-
|
|
16
|
-
* CLI : prevent execution if the required arguments are missing.
|
|
17
|
-
|
|
18
|
-
### 1.1.0 (May 13, 2020)
|
|
19
|
-
|
|
20
|
-
* Add cli script.
|
|
21
|
-
|
|
22
|
-
### 1.0.1 (May 12, 2020)
|
|
23
|
-
|
|
24
|
-
* Fix the installation instructions.
|
|
25
|
-
|
|
26
|
-
### 1.0.0 (May 12, 2020)
|
|
27
|
-
|
|
28
|
-
* initial release.
|