Simple NodeJS CLI which allows you zip and unzip files with support for .gitignore files
Install it locally with
npm i https://github.com/matteosacchetto/node-zip-cli/releases/download/v0.5.1/node-zip-cli-0.5.1.tgz
Or install it globally with
npm i --location=global https://github.com/matteosacchetto/node-zip-cli/releases/download/v0.5.1/node-zip-cli-0.5.1.tgz
Go to the release section of the GitHub repository
Copy the link the node-zip-cli-{version}.tgz
Install it locally with
npm i <link-to-node-zip-cli-{version}.tgz>
Or install it globally with
npm i --location=global <link-to-node-zip-cli-{version}.tgz>
where you have to replace {version}
with the version number you downloaded (ex: 0.1.5)
Since version 0.2.0, the package also includes a bash completion script. If you install the package globally, you are on Linux and you use bash as your main shell, I highly suggest installing bash completion, as it improves the UX of this module.
To install it, i recommend to perform the following steps.
Find where did npm isntall this package. To do so you can run the following command
npm list -g -p | grep node-zip-cli
Then we can link bash-completion.sh
script contained within the folder shown by the previous command to /usr/share/bash-completion/completions/node-zip-cli
ln -s <path-found-previously>/bash-completion.sh /usr/share/bash-completion/completions/node-zip-cli
One-liner to do so
sudo ln -s `npm list -g -p | grep -m 1 node-zip-cli`/bash-completion.sh /usr/share/bash-completion/completions/node-zip-cli
To remove the completion file
sudo rm /usr/share/bash-completion/completions/node-zip-cli
You can alternatively install bash completion locally with the following commands
mkdir -p ~/.local/share/bash-completion/completions
ln -s `npm list -g -p | grep -m 1 node-zip-cli`/bash-completion.sh ~/.local/share/bash-completion/completions/node-zip-cli
To remove it
rm ~/.local/share/bash-completion/completions/node-zip-cli
If you installed it locally you can run it with
npx node-zip-cli
If instead you installed it globally you can run it with
node-zip-cli
Usage: node-zip-cli [options] [command]
Options:
-v, --version output the version number
-h, --help display help for command
Commands:
zip [options] zip files and directories ignoring files specified in .zipignore and .gitignore
unzip [options] unzip the content of a zip file
help [command] display help for command
Allows you to create a zip file of the specified files and directories. For each directory it will also go through it and scan recursively it ignoring every file and directory listed in the .gitignore and .zipignore files, if present.
Usage: node-zip-cli zip [options]
zip files and directories ignoring files specified in .zipignore and .gitignore
Options:
-v, --version output the version number
-i, --input <input...> the files or directories to zip (default: ["."])
-d, --deflate <compression-level> deflate the files (default: 0)
-o, --output <output-file> the filename of the zip file to create (default: "out.zip")
-y, --yes answers yes to every question (default: false)
-e, --exclude <paths...> ignore the following paths
--allow-git allow .git to be included in the zip (default: false)
--dry-run lists the files that will be zipped WITHOUT creating the zip file (default: false)
-h, --help display help for command
Specify the list of input files/directories. Defaults to the current directory
Specify the compression level of the deflate operation. The compression level can be a value between 0 (no compression) and 9 (maximum compression). Defaults to 0
Specify the filename of the zip file. Defaults to out.zip
Answers yes to every confirmation question
Allows you to specify paths that you want to exclude. This option follows the same syntax and rules of the traditional .gitignore file.
NOTE: the specified paths must be specified considering as root directory the input directory specified with the -i
flag
Example:
If you have the following structure and you want to ignore the file two
, if you run the command with -i test/
, you need to exclude it with -e two
and NOT -e test/two
test/
├── one
├── two
└── three
Note
Up to the current version (0.5.1) the list of paths to ignore which are specified with this options are applied after default ignore paths (like .git
) BUT before any .gitignore or .zipignore file. This means that paths you specify here could be overridden by the aforementioned files.
Starting from version 0.2.0
, the directory .git
is ignored by default. Use this flag if you want instead to include the .git
directory in your zip file
Prints the files that will be zipped, without creating the zip file. The structure that is printed out is the same structure of files and directories which will be created in the zip file.
Allows you to unzip the content of a zip file to a directory which will be created if non existing
Usage: node-zip-cli unzip [options]
Unzip the content of a zip file
Options:
-v, --version output the version number
-i, --input <file> the input zip file to unzip
-o, --output <output> the output directory where to store the zip content (default: ".")
--dry-run lists the files that will be unzipped WITHOUT unzipping the archive (default: false)
-h, --help display help for command
The input zip file to unzip. This option is REQUIRED
The directory where to store the content of the zip file. Defaults to the current directory
Prints the files that will be unzipped, without extracting them from the zip file. The structure that is printed out is the same structure of files and directories which will be created when unzipping the zip file.
Simply run this CLI providing to each command all the necessary options.
This file is meant to be placed in a folder which you plan to zip. It is meant to be used instead of the .gitignore, if the content of the folder is not related to git, or as an extension of the .gitignore, where you can specify additional rules related only to the zip file creation. The .zipignore file follow the same syntax and rules of the traditional .gitignore
Note
Up to the current version (0.5.1) the .zipignore builds on top of already existing .gitignore rules, so if you only want to ignore some additional files you do not need to copy paste the content of the .gitignore. Keep in mind that this behavior may change in the future