@tryghost/zip 1.1.15
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/LICENSE +21 -0
- package/README.md +50 -0
- package/index.js +4 -0
- package/lib/compress.js +54 -0
- package/lib/extract.js +25 -0
- package/package.json +35 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2013-2021 Ghost Foundation
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# Zip
|
|
2
|
+
|
|
3
|
+
## Install
|
|
4
|
+
|
|
5
|
+
`npm install @tryghost/zip --save`
|
|
6
|
+
|
|
7
|
+
or
|
|
8
|
+
|
|
9
|
+
`yarn add @tryghost/zip`
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
## Usage
|
|
13
|
+
|
|
14
|
+
```
|
|
15
|
+
const zip = require('@tryghost/zip');
|
|
16
|
+
|
|
17
|
+
// Create a zip from a folder
|
|
18
|
+
|
|
19
|
+
let res = await zip.compress('path/to/a/folder', 'path/to/archive.zip', [options])
|
|
20
|
+
|
|
21
|
+
// Extract a zip to a folder
|
|
22
|
+
|
|
23
|
+
let res = await zip.extract('path/to/archive.zip', 'path/to/files', [options])
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Develop
|
|
27
|
+
|
|
28
|
+
This is a mono repository, managed with [lerna](https://lernajs.io/).
|
|
29
|
+
|
|
30
|
+
Follow the instructions for the top-level repo.
|
|
31
|
+
1. `git clone` this repo & `cd` into it as usual
|
|
32
|
+
2. Run `yarn` to install top-level dependencies.
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
## Run
|
|
36
|
+
|
|
37
|
+
- `yarn dev`
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
## Test
|
|
41
|
+
|
|
42
|
+
- `yarn lint` run just eslint
|
|
43
|
+
- `yarn test` run lint and tests
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
# Copyright & License
|
|
49
|
+
|
|
50
|
+
Copyright (c) 2013-2021 Ghost Foundation - Released under the [MIT license](LICENSE).
|
package/index.js
ADDED
package/lib/compress.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
const fs = require('fs-extra');
|
|
2
|
+
const Promise = require('bluebird');
|
|
3
|
+
|
|
4
|
+
const defaultOptions = {
|
|
5
|
+
type: 'zip',
|
|
6
|
+
glob: '**/*',
|
|
7
|
+
dot: true,
|
|
8
|
+
ignore: ['node_modules/**']
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Compress
|
|
13
|
+
*
|
|
14
|
+
* - Create a zip file from a folder
|
|
15
|
+
*
|
|
16
|
+
* @param {String} folderToZip - full path to the folder to be zipped
|
|
17
|
+
* @param {String} destination - full path to the resulting zip file
|
|
18
|
+
* @param {Object} [options]
|
|
19
|
+
* @param {String} options.type - zip by default see archiver for other options
|
|
20
|
+
* @param {String} options.glob - the files to include, defaults to all files and folders
|
|
21
|
+
* @param {Boolean} options.dot - include all dotfiles and dotfolders
|
|
22
|
+
* @param {Array} options.ignore - any paths that should be ignored, sets node_modules by default
|
|
23
|
+
*
|
|
24
|
+
*/
|
|
25
|
+
module.exports = (folderToZip, destination, options = {}) => {
|
|
26
|
+
const opts = Object.assign({}, defaultOptions, options);
|
|
27
|
+
|
|
28
|
+
const archiver = require('archiver');
|
|
29
|
+
const output = fs.createWriteStream(destination);
|
|
30
|
+
const archive = archiver.create(opts.type);
|
|
31
|
+
|
|
32
|
+
return new Promise((resolve, reject) => {
|
|
33
|
+
// If folder to zip is a symlink, we want to get the target
|
|
34
|
+
// of the link and zip that instead of zipping the symlink
|
|
35
|
+
if (fs.lstatSync(folderToZip).isSymbolicLink()) {
|
|
36
|
+
folderToZip = fs.realpathSync(folderToZip);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
output.on('close', function () {
|
|
40
|
+
resolve({path: destination, size: archive.pointer()});
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
archive.on('error', function (err) {
|
|
44
|
+
reject(err);
|
|
45
|
+
});
|
|
46
|
+
archive.glob(opts.glob, {
|
|
47
|
+
cwd: folderToZip,
|
|
48
|
+
dot: opts.dot,
|
|
49
|
+
ignore: opts.ignore
|
|
50
|
+
});
|
|
51
|
+
archive.pipe(output);
|
|
52
|
+
archive.finalize();
|
|
53
|
+
});
|
|
54
|
+
};
|
package/lib/extract.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
const defaultOptions = {};
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Extract
|
|
5
|
+
*
|
|
6
|
+
* - Unzip an archive to a folder
|
|
7
|
+
*
|
|
8
|
+
* @param {String} zipToExtract - full path to zip file that should be extracted
|
|
9
|
+
* @param {String} destination - full path of the extraction target
|
|
10
|
+
* @param {Object} [options]
|
|
11
|
+
* @param {Integer} options.defaultDirMode - Directory Mode (permissions), defaults to 0o755
|
|
12
|
+
* @param {Integer} options.defaultFileMode - File Mode (permissions), defaults to 0o644
|
|
13
|
+
* @param {Function} options.onEntry - if present, will be called with (entry, zipfile) for every entry in the zip
|
|
14
|
+
*/
|
|
15
|
+
module.exports = (zipToExtract, destination, options) => {
|
|
16
|
+
const opts = Object.assign({}, defaultOptions, options);
|
|
17
|
+
|
|
18
|
+
const extract = require('extract-zip');
|
|
19
|
+
|
|
20
|
+
opts.dir = destination;
|
|
21
|
+
|
|
22
|
+
return extract(zipToExtract, opts).then(() => {
|
|
23
|
+
return {path: destination};
|
|
24
|
+
});
|
|
25
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@tryghost/zip",
|
|
3
|
+
"version": "1.1.15",
|
|
4
|
+
"repository": "https://github.com/TryGhost/Utils/tree/master/packages/zip",
|
|
5
|
+
"author": "Ghost Foundation",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"main": "index.js",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"dev": "echo \"Implement me!\"",
|
|
10
|
+
"test": "NODE_ENV=testing c8 mocha './test/**/*.test.js'",
|
|
11
|
+
"lint": "eslint . --ext .js --cache",
|
|
12
|
+
"posttest": "yarn lint"
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"index.js",
|
|
16
|
+
"lib"
|
|
17
|
+
],
|
|
18
|
+
"publishConfig": {
|
|
19
|
+
"access": "public"
|
|
20
|
+
},
|
|
21
|
+
"devDependencies": {
|
|
22
|
+
"c8": "7.9.0",
|
|
23
|
+
"folder-hash": "4.0.1",
|
|
24
|
+
"mocha": "9.0.0",
|
|
25
|
+
"should": "13.2.3",
|
|
26
|
+
"sinon": "11.0.0"
|
|
27
|
+
},
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"archiver": "^4.0.2",
|
|
30
|
+
"bluebird": "^3.7.2",
|
|
31
|
+
"extract-zip": "2.0.1",
|
|
32
|
+
"fs-extra": "^9.1.0"
|
|
33
|
+
},
|
|
34
|
+
"gitHead": "9545d13a14c1b0ac70cd80ee111f66f642eb0a4d"
|
|
35
|
+
}
|