native-copyfiles v0.3.2
Copyfiles
native-copyfiles
Copy files easily via JavaScript or the CLI, it uses tinyglobby internally for glob patterns and yargs for the CLI.
The library is similar to the copyfiles package, it is however written with more native NodeJS APIs and less dependencies. The package options are exactly the same (except for --soft
which is not implemented).
There is 1 major difference though, any options must be provided after the command as a suffix (the original project had them as prefix)
Install
npm install native-copyfiles -g
Command Line
Usage: copyfiles inFile [more files ...] outDirectory [options]
Options:
-u, --up slice a path off the bottom of the paths [number]
-a, --all include files & directories begining with a dot (.) [boolean]
-f, --flat flatten the output [boolean]
-e, --exclude pattern or glob to exclude (may be passed multiple times) [string|string[]]
-E, --error throw error if nothing is copied [boolean]
-V, --verbose print more information to console [boolean]
-F, --follow follow symbolink links [boolean]
-v, --version Show version number [boolean]
-h, --help Show help [boolean]
Note: as opposed to the original copyfiles project, any options must be provided as a suffix.
copy some files, give it a bunch of arguments, (which can include globs), the last one is the out directory (which it will create if necessary). Note: on windows globs must be double quoted, everybody else can quote however they please.
copyfiles foo foobar foo/bar/*.js out
you now have a directory called out, with the files foo and foobar in it, it also has a directory named foo with a directory named bar in it that has all the files from foo/bar that match the glob.
If all the files are in a folder that you don't want in the path out path, ex:
copyfiles something/*.js out
which would put all the js files in out/something
, you can use the --up
(or -u
) option
copyfiles something/*.js out -u 1
which would put all the js files in out
you can also just do -f
which will flatten all the output into one directory, so with files "./foo/a.txt" and "./foo/bar/b.txt"
copyfiles ./foo/*.txt ./foo/bar/*.txt out -f
will put "a.txt" and "b.txt" into out
if your terminal doesn't support globstars then you can quote them
copyfiles ./foo/**/*.txt out -f
does not work by default on a mac
but
copyfiles "./foo/**/*.txt" out -f
does.
You could quote globstars as a part of input:
copyfiles some.json "./some_folder/*.json" ./dist/ && echo 'JSON files copied.'
You can use the -e
option to exclude some files from the pattern, so to exclude all files ending in ".test.js" you could do
copyfiles "**/*.test.js" -f ./foo/**/*.js out -e
Other options include
-a
or--all
which includes files that start with a dot.-F
or--follow
which follows symbolinks
JavaScript API
import { copyfiles } from 'native-copyfiles';
copyfiles([paths], opt, callback);
The first argument is an array of paths whose last element is assumed the destination path.
The second argument (opt
) being the options argument
and finally the third and last argument is a callback function which is executed after after all files copied
{
verbose: bool, // enable debug messages
up: number, // -u value
soft: bool, // soft copy (skip existing dirs & files)
exclude: string, // exclude pattern
all: bool, // include dot files
follow: bool, // Follow symlinked directories when expanding ** patterns
error: bool // raise errors if no files copied
}