What is cpy-cli?
The cpy-cli npm package is a command-line interface for the cpy module, which is used to copy files and directories with various options. It is designed to be simple and efficient, making it easy to copy files from one location to another with additional features like glob patterns, renaming, and more.
What are cpy-cli's main functionalities?
Basic File Copy
This command copies the file 'source.txt' to the 'destination' directory.
cpy 'source.txt' 'destination/'
Copy Multiple Files
This command copies all .txt files from the 'src' directory to the 'dist' directory using glob patterns.
cpy 'src/*.txt' 'dist/'
Rename Files While Copying
This command copies 'source.txt' to the 'destination' directory and renames it to 'renamed.txt'.
cpy 'source.txt' 'destination/renamed.txt'
Copy Files Recursively
This command copies all files and directories from 'src' to 'dist' recursively.
cpy 'src/**/*' 'dist/'
Preserve Timestamps
This command copies 'source.txt' to the 'destination' directory and preserves the original file timestamps.
cpy 'source.txt' 'destination/' --preserve-timestamps
Other packages similar to cpy-cli
ncp
The ncp (Node Copy) package is another tool for copying files and directories in Node.js. It offers similar functionality to cpy-cli but is more focused on being a programmatic API rather than a CLI tool. It supports recursive copying and can handle large directories efficiently.
fs-extra
The fs-extra package extends the native Node.js fs module with additional methods, including file and directory copying. It provides a more extensive API for file system operations and is widely used for its simplicity and reliability. Unlike cpy-cli, fs-extra is primarily used as a library within Node.js scripts.
shelljs
ShellJS is a portable (Windows/Linux/macOS) implementation of Unix shell commands on top of the Node.js API. It provides a wide range of shell commands, including file copying. ShellJS is more versatile than cpy-cli as it supports a broader range of shell operations, but it may be overkill if you only need to copy files.
cpy-cli
Copy files
Why
- Fast by using streams.
- Resilient by using graceful-fs.
- User-friendly by accepting globs and creating non-existant destination directories.
- User-friendly error messages.
Install
$ npm install --global cpy-cli
Usage
$ cpy --help
Usage
$ cpy <source>... <destination>
Options
--no-overwrite Don't overwrite the destination
--parents Preserve path structure
--cwd=<dir> Working directory for source files
--rename=<filename> Rename all <source> filenames to <filename>
<source> can contain globs if quoted
Examples
Copy all .png files in src folder into dist except src/goat.png
$ cpy 'src/*.png' '!src/goat.png' dist
Copy all .html files inside src folder into dist and preserve path structure
$ cpy '**/*.html' '../dist/' --cwd=src --parents
Related
- cpy - API for this module
License
MIT © Sindre Sorhus