Giter Site home page Giter Site logo

copyfiles's Introduction

copyfiles Build Status

copy files easily

Install

npm install copyfiles -g

Command Line

  Usage: copyfiles [options] inFile [more files ...] outDirectory

  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)
    -E, --error    throw error if nothing is copied                      [boolean]
    -V, --verbose  print more information to console                     [boolean]
    -s, --soft     do not overwrite destination files if they exist      [boolean]
    -F, --follow   follow symbolink links                                [boolean]
    -v, --version  Show version number                                   [boolean]
    -h, --help     Show help                                             [boolean]

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 -u 1 something/*.js out

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 -f ./foo/*.txt ./foo/bar/*.txt out

will put a.txt and b.txt into out

if your terminal doesn't support globstars then you can quote them

copyfiles -f ./foo/**/*.txt out

does not work by default on a mac

but

copyfiles -f "./foo/**/*.txt" out

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 -e "**/*.test.js" -f ./foo/**/*.js out

Other options include

  • -a or --all which includes files that start with a dot.
  • -s or --soft to soft copy, which will not overwrite existing files.
  • -F or --follow which follows symbolinks

copyup

also creates a copyup command which is identical to copyfiles but -up defaults to 1

Programic API

var copyfiles = require('copyfiles');

copyfiles([paths], opt, callback);

takes an array of paths, last one is the destination path, also takes an optional argument which the -u option if a number, otherwise if it's true it's the flat option or if it is an object it is a hash of the various options (the long version e.g. up, all, flat, exclude, error, verbose, follow, and soft)

Tilde support for home directory

when the src/dest path start with tilde for home directory under windows, please make sure -u or -f is added in options or use copyup command. if not you will get Error: Illegal characters in path.

copyfiles's People

Contributors

andrew avatar aramk avatar axelhzf avatar blimmer avatar bselwayregis avatar calvinmetcalf avatar cellvia avatar dawsbot avatar dpogue avatar maartenverheul avatar popenkomaksim avatar toddpress avatar vizmi avatar willyrk1 avatar wunaidage avatar zacharykearns avatar zewa666 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

copyfiles's Issues

Problem on recursively on rapsberry

On windows 10 i've no problems but on a raspberryPi, with node 9.11.2 and copyfiles 2.1.0, the glob pattern : "lib/**/*" doesn't include subdirectories. On filesystem :

  • lib
    • folder1
      • subfolder1
        • subfile1
      • file1
    • rootfile1

I will have folder1, file1 and rootfile1, but not subfolder1 and subfile1.

--exclude with quoted glob does not seem to work

I have a npm script like:

"copy:resources": "copyup --exclude \"**/*.ts\" \"./src/**/*\" build",

It copies all files, including the *.ts files. I don't want the *.ts files to be copied.
I'm running on OSX and if understand correctly I should quote the glob.

patterns that include subfolders (i.e. /**/* or /**) fail

I have a folder structure like this:

  • input
    • input1
      • file1.txt
      • file2.txt

When I run this command it fails: node copyfiles input/**/* output
Working theory:

  • the glob pattern includes the input1 folder (on windows it comes earlier than the files).
  • The module tries to open a reader - writer stream on it, which creates an empty file called output/input/input1.
  • Any subsequent operations fail because output/input/input1 is not a directory.

copyup behaving differently for mac and windows

I have a project with the following structure for the folder structure

I_server
I___config
I____app.properties.json 

I and running the following command copyup server/**/*.json dist/

In mac I get the right copy done as expected and the output looks like this

I_dist
I___config
I____app.properties.json 

But in windows 10 the same command gives the following results

I_dist
I__server
I___config
I____app.properties.json 

Can you tell me the correct command so that in windows it should result into the same output as mac

Copying binary files

I started using this package recently to copy assets in an Angular app from dist directory to another directory for Java Spring. Since then, font files in my assets directory seem to have been corrupted. Is copyfiles safe for copying binary files? Should it only be used with ASCII files?

Change CWD

Is it possible, and if not can I suggest it as a feature?

It'd be helpful for stuff like this:

copyfiles src/**/*.php dist/

Here it'd make a new folder in dist called src, while I want to keep the folder layout just bring it a directory up.

doesn't copy hidden files

I'd like to copy a folder that starts with a dot. I guess it is treated as a hidden folder, that's why it's not being copied?

Is there an option to allow that?

Verbose option

It would be good to add a verbose option to copyfiles. It tells nothing about what files were copied to the destination.

Copy without creating of subdirectories

Let's consider we have the following structure:

|-- src
    |-- fonts
        |-- font1.woff
        |-- font2.woff
    |-- index.js
|-- lib

The command copyfiles src/fonts/** lib/fonts/ creates the following structure:

|-- src
    |-- fonts
        |-- font1.woff
        |-- font2.woff
    |-- index.js
|-- lib
    |-- src
        |-- fonts
            |-- font1.woff
            |-- font2.woff

Is there any flag not to created the nested directory structure? I need something like this:

|-- src
    |-- fonts
        |-- font1.woff
        |-- font2.woff
    |-- index.js
|-- lib
    |-- fonts
        |-- font1.woff
        |-- font2.woff

Requires escaped double-quotes for cross-platform globstars **/*

One thing i noticed in the documentation is that your examples show single-quoted strings in order to allow for cross-platform compatibility. I have tried this and it does not work properly in Windows. However using ESCAPED DOUBLE-QUOTES works great!

So instead of...

copyfiles -f './foo/*_/_.txt' out

try...

copyfiles -f \"./foo/*_/_.txt\" out

Can you please update the documentation to show this?

Thanks!

Jeremy Moritz

Better documentation

copyup

also creates a copyup command which is identical to copyfiles but -up defaults to 1

What does that even mean?

Also it is possible to move directories and not only files? I searched but couldn't find another node cli tool to do it with.
I got something like this:
copyfiles -f frontend/assets/images/* app/public/images & copyfiles -f frontend/assets/fonts/* app/public/fonts but it would be a lot easier if I could do:
copyfiles -f frontend/assets/* app/public/

How can i override a file silently?

Error: EEXIST: file already exists, mkdir 'C:\Users\Administrator\Desktop\generator-sy-template\generators\app\config\wcf.config.json'
at Error (native)

I want files be override silently without such kind of errors

Unquoted glob doesn't match correctly

This worked before:

src
  folder 1
    file1.ext
  folder 2
    file2.ext

script in package.json: copyfiles -u 1 src/**/*.ext out

Then I added another file at the root level like this:

src
  folder 1
    file1.ext
  folder 2
    file2.ext
  file3.ext

Now file1 and file2 were missing in the out folder.

I had to change the npm script to use quotes.
e.g.

"copy": "copyfiles -u 1 \"src/**/*.ext\" out"

I had this problem using Arch Linux and also inside of the Docker container using the basic node image.

I think the README was a bit misleading when it said that on windows globs must be double quoted, everybody else can quote however they please.

copyfiles itself didn't report any errors or warnings either.

Works from CLI, but not from npm scripts

I've tried this with a couple commands, and I'm not sure what the issue is, but using npm run to run a script with copyfiles in it doesn't work. The same command as ./node_modules/.bin/copyfiles works fine

glob with hits in multiple folders

Files to copy:

src
    folderA
         filex.ts
         filey.ts
    folderB
        fileZ.ts

I was expecting that

copyfiles src/**/*.ts out

would yield

out
    src
        folderA
            filex.ts
            filey.ts
        folderB
            fileZ.ts

but I only get this (the 2nd folder is skipped)

out
    src
        folderA
            filex.ts
            filey.ts

Programic API

Desperate need for documentation here.

I have been an advocate for npm scripting of build processes for many departments at my work and I sold them a group of npm packages to get the job done, copyfiles being one of them. We have recently converted from npm scripts within package.json to writing out a node build file.

We are going to have to switch away from copyfiles do to the lack of documentation and below.

takes an array of paths, last one is the destination path...

On the command line that makes sense, programatically it is nonsensical. I can't explain to other developers why the "last item in the array is the destination" and any new developer coming on board would have to get taught that as well.

This npm package has been great to me, I would love to see more documentation on "programmatic" usage as well an additional parameter when calling copyfiles in that environment.

Something like:


copyfiles(path, dest [, opts] [, callback])

Example

var copyfiles = require('copyfiles');

copyfiles(["./src/**/*.html"], "./dist/", function (err) {
    if (err) console.error(err);
});

Example w/opts

var copyfiles = require('copyfiles');

// I honestly don't understand how you are taking options here because it isn't documented.
copyfiles(["./src/**/*.html"], "./dist/", "-u", function (err) {
    if (err) console.error(err);
});

Copy folder from folder

I actually have the following structure:
image

I want to copy the config.json and the folder assets from folder src to dist.
Now I use this command:

copyfiles src/config.json src/assets/** dist

But it always copies it itno dist like this: dist/src/asssets for example.
I've tried already parameter --up but it diesn't work. How can I achieve the following structure after copy?

  • dist
    -- assets
    -- config.json

Does not give error when copying fails

Nothing happens when I run the following script. I don't get an error and no files are being produced.

#!/usr/bin/env node --harmony
const copyfiles = require('copyfiles');
const path = require('path');

const RAZOR_PATH = "Microsoft.AspNet.Razor.3.0.0/lib/net45/System.Web.Razor.dll"
const RAZORENG_PATH = "RazorEngine.3.8.2/lib/net45/RazorEngine.dll"
const JSON_PATH = "Newtonsoft.Json.8.0.3/lib/net45/Newtonsoft.Json.dll"
const destination = '.';
const paths = [ RAZOR_PATH, RAZORENG_PATH, JSON_PATH, destination ].map(path.normalize);
const opts = {};

copyfiles(paths, opts, function(err) {
    if(err) {
        console.error(`Failed copying dependencies: ${paths}`);
        process.exit(1);
    }

    console.log('.NET dependencies copied successfully')
});

Argument list too long

This package is pretty cool, thanks for sharing, but unfortunately

Try to copy 6000+ json files and got error:
sh: /usr/local/bin/copyfiles: Argument list too long

npm ERR! Darwin 15.5.0
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "run" "copy-json"
npm ERR! node v6.0.0
npm ERR! npm v3.8.6
npm ERR! code ELIFECYCLE
npm ERR! [email protected] copy-json: copyfiles source/*.json declarations/*.json ./dist/ && echo 'JSON files copied.'
npm ERR! Exit status 126

Could you please confirm that there are some limitations for copping files?

Exclude folder

Hey,

is there an option to exclude a folder?
I am trying to copy my non-script files from ./src to ./dist and exclude the "node_modules" folder.

Regards

Windows: wont work with paths with space

Am using it in Windows
Using the LTS version of the NodeJS windows installer.

angular-cli.json

"apps": [{ "root": "src", "outDir": "dist", "assets": [ "assets/**", "favicon.ico" ], "index": "index.html", }],

package.json
"scripts": { "build": "ng build --base-href .", "postbuild": "npm run deploy", "deploy": "copyfiles -f dist/** ../resources/static", }

My workspace is in

C:\Programfiles (x86)\Workspace\Project1

Command: npm run build

And it does not copy the assets inside the dist directory.
If I have my workspace in

C:\Programfiles\Workspace\Project1

Sadly I cannot change my workspace location. Can you help?

'Empty' folder copy?

I've got a structure like this:

emails
  |->welcome
    |->email.html
  |->registration
    |->new
      |->email.html
    |->referral
      |->email.html

I cannot get copyfiles to copy the 'empty' registration folder and it's contents over. The emails/welcome/email.html file copies over fine.

I'm using copyfiles ./src/emails/**/* ./dist, and have tried a ton of other combos.

How can I get copyfiles to copy the registration folder and it's subfolders?

copy files does not copy dot files even when using the -a flag

Hi,

Im using copyfiles in my npm scripts but the dot files are not being copied at all even when using the -a flag.

"scripts": { "copy": "rimraf ./dist && copyfiles -a -u 1 templates/**/** dist/templates" }

I wonder if you could help with whats going wrong?

Bw
P

unable to run copyfiles

screenshot from 2017-08-07 12 41 48
sir,
i am trying to make a copy of files using npm copyfiles package but it is giving me error, cn you explain me what i am doing wrong

Passing flat(ten) as a parameter errors out

I tried passing both "flat" and "flatten" as a parameter through the Programatic API with no luck. I forked the repo, updated the flatten test to use the format { flatten: true } and the test fails. I've also attempted { flat: true } and the test fails. In terms of the options available, flatten does not seem available.

Update: Looked through the code and saw that the only passable options through the programmatic API are all and exclude. The Programmatic API should be better documented

Exclude option

Great tool (the -u option is especially nice). Would it be possible to add an exclude option in order to f.x. copy all files according to a glob except a specific file type ?

Not coping subfolders when folder names contains "." (dots) (globs)

ex: copyfiles app/assets/**/* dist
expected behaviour:
copy all files from app/assets including subfolders to dist.

actual behaviour:
app/assets/my.images/img.svg is copied
app/assets/my.images/private/pic.svg is NOT copied

ex2: copyfiles app/assets/**// dist
expected behaviour:
copy all files from app/assets including subfolders to dist.

actual behaviour:
app/assets/my.images/img.svg is NOT copied
app/assets/my.images/private/pic.svg is copied

Probably related to #18

could not copy files at all

I have tried to do a simple file copy with this command:

.\node_modules\.bin\copyfiles ./src/index.html ./client

but it fails with the following error message:

\node_modules\copyfiles\node_modules\glob\glob.js:130 throw new Error("must provide pattern")

I have tried to use both ' and " around the paths, / and \ as path separator but I could not get it running.

OS: Windows 7 Pro
Node version: 0.12.0
NPM version: 2.5.1

copyfiles doesn't follow directories that are symlinks

As in title
This is consistent with glob which by default doesn't follow folder symlink. Howewver, glob supports follow flag to override this. It would be cool is copyfiles support that too.

Adding this when preparing globOpts helps:

if (config.follow) {
    globOpts.follow = true;
}

I will prepare PR for this if there is positive feedback.

-u option does not work

Hi Calvin,

apologies for the confusion: I was somewhat convinced the isFile() filtering will fix the -u issue too. It turned out it is not. The 4 test cases with -u are still failing for me.
I have committed the a version to my clone that I believe fixes the issue (the path.normalize call we've been going back and forth) and some logging that helps further diagnostics in the future. I hope you will find it useful.
Let me know if you need a pull request from my end.

Copying all files and directories from one dir to another

I'm using this command to copy all files from build directory to `dist:

copyfiles -u 1 build/* dist

It works fine except it doesn't copy directories, How can we make sure it also copies the directories with files inside recursively?

--up option does not work

This command works:
copyfiles src/*.html test

but this does not:
copyfiles -u 1 src/*.html test

the exception is:
{ [Error: EISDIR, open 'C:\Users\me\project\test'] errno: -4068, code: 'EISDIR', path: ''C:\\Users\\me\\project\\test'' }

As far as I can tell EISDIR error code means the system got a directory but expected something else (file?).

Relative path doesn't seem to work as expected

I have the following structure:

src
|- app
|- common
|- server

and am executing copyfiles ../**/*.json dist from inside server and I end up with:

src
|- app
|- common
|- server
    |- common
    |   |- package.json
    |- server
        |- package.json

I'd have expected:

src
|- app
|- common
|- server
    |- dist
        |- common
        |   |- package.json
        |- server
            |- package.json

Even copyfiles ../**/*.json server/dist results in a server/server folder which contains both common and server which is strange.

The following however works:

(cd .. && copyfiles **/*.json server/dist)

Copy files without extension

Hey Guys,

I am trying to set up a copy after doing a build to get ready for a publish and i'm trying to copy over files in prep. I am able to copy all files except the LICENSE file. I am on windows so i'm not sure if its a windows issue or what but i've been over all the docs and tried with quotes and without, with a path and without and i'm now at a point where i'm unsure what to do next
I feel like this is probably something super obv that i am missing

How to exclude multiple globs from single argument?

copyfiles -e \"./**/*.{test,snap,integration}.js\" -e \"./**/__mocks__/**\" \"./client/**/*\"

Doesn't work because the second one overwrites the first.

copyfiles -e \"./**/*.{test,snap,integration}.js,./**/__mocks__/**\" \"./client/**/*\"
Doesn't work either.

How to copy folder include subfolders?

my folders seems like
dist/xxxx.html
dist/assets/xxx.jpg
dist/assets/xxx/xxx.css
when I run copyfiles -f dist/** ../resources/static, just the files under /dist such as xxxx.html were copied, nothing in other subfolder was not be copied .

Quoted globs don't work unless using -f

Will be using other solutions, so this isn't an urgent bug report or anything. But thought you should know that while the manual is correct that quoted globs can be used with -f, they don't work when using just -u.

-u 1 doesn't work with globstars

When trying to copy the files and folders from one folder to another using globstars and -u 1:

copyfiles -u 1 ./dist/** ../Angular2Test/Content/myapp

It gives this error:

K:\dev\Angular2Test\Angular2Source\node_modules\copyfiles\index.js:30
throw new Error('cant go up that far');
^

Error: cant go up that far
at dealWith (K:\dev\Angular2Test\Angular2Source\node_modules\copyfiles\index
.js:30:11)
at K:\dev\Angular2Test\Angular2Source\node_modules\copyfiles\index.js:64:39
at FSReqWrap.oncomplete (fs.js:82:15)

Does not work in Windows

When running this locally installed into a project using npm run, it never copies anything with no error.

$ copyfiles src out
[ 'src', 'out' ]
Done in 0.85s.

[BUG]: Copyfiles Incorrectly Assigns Up

Steps to Reproduce:

$ mkdir ~/folder-with-a-up-in-path && cd $_
$ npm init -y
$ npm install copyfiles
$ # open package.json and add the following line to "scripts"
    "copyfiles": "copyfiles package.json dist/lib"
$ npm run copyfiles
Error: cant go up that far
    at dealWith (/home/user/folder-with-a-up-in-path/node_modules/copyfiles/index.js:30:11)
    at /home/user/folder-with-a-up-in-path/node_modules/copyfiles/index.js:80:39
    at FSReqWrap.oncomplete (fs.js:153:5)

The issue is that the script is being run in a folder with a literal -up in the path

The root of the issue the following block of code:

if (args.argv.$0.indexOf('up') > -1) {
  args.default('u', '1');
}

This looks like it is trying to assign / detect a default value if -u is ever specified without a value, the problem is it isn't. First of all it is incomplete code, it only works with -up and not -u. Second the args.argv.$0 will never contain accurate runtime args, it will only contain the folder.

This code creates a really nasty bug. I know yargs doesn't make it easy to support this functionality, the code above should be removed.

Negate exclude glob

Currently, the negation pattern for globs is dysfunctional. This is necessary for cases such as file inclusion differences between production and development modes.

Example negation pattern use:

args.indexOf('production') >= 0 ? '!*.min.js' : '*.min.js'

Doesn't work on Windows

We have to use Windows for builds at work, and this fails silently there while working perfectly the same files/structure on OSX. Using globbing to get a whole directory with a certain file extension and -u 2.

Redo the out dir arg

copyfiles assets/src/img/**/* assets/dist/img should copy all the files in assets/src/img to assets/dist/img.

I've tried a dozen ways to copy files to the correct location and can't figure it out.

Gonna make my own copyfiles package. No need for a reply.

dot folders not being copied even with escaped quotes

I tried doing the fix shown in #18, and that is not working to solve my issue. I am running

copyfiles -u 4 \\\"../../gradleBase/java/**/*\\\" resources/src/java/gradlebase

I've also tried copyfiles -u 4 \"../../gradleBase/java/**/*\" resources/src/java/gradlebase

and neither one works. My from folder has 2 dot folders with files in them, and neither one is being copied.

Upgrade yargs version to prevent mem vulnerability warning

On the most current version of copyfiles, yargs is limited to ^11, which uses a vulnerable version of mem. Reported by WhiteSource as WS-2018-0236.

Here's the 1.x version of mem on a fresh install of copyfiles:

> npm ls
<trimmed>
  └─┬ [email protected]
    ├─┬ [email protected]
    │ └─┬ [email protected]
<trimmed>

If I install the newest yargs they've upgraded to a >4 version of mem:

> npm ls
<trimmed>
└─┬ [email protected]
  ├─┬ [email protected]
  │ └─┬ [email protected]
<trimmed>

I noticed this because I'm getting a GitHub automated security vulnerability warning on my repo where I use copyfiles.

-u returns an error

C:\...\project>copyfiles -u 1 "./src/assets/images/*" build
{ [Error: EISDIR, open 'C:\...\project\build']
  errno: 28,
  code: 'EISDIR',
  path: 'C:\\...\\project\build' }

Am I using the option wrong?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.