sindresorhus / cpy-cli

Copy files
MIT License
344 stars 33 forks source link

[Windows] not working in npm script if use ' #30

Open rendomnet opened 3 years ago

rendomnet commented 3 years ago

If I use npm script "copy": "cpy './package.json' dist"

npm run copy it will give me error Cannot copy'./package.json': the file doesn't exist

But if I remove ' like this cpy ./package.json dist it will run correctly

Windows 10 Node 10.24.1

whizkidwwe1217 commented 3 years ago

@rendomnet You can escape a double quote "copy": "cpy \"./package.json\" dist"

jhildenbiddle commented 3 years ago

FYI --

Removing the single quotes surrounding the paths resolved the issue for me.

Using the example from the OP:

"copy": "cpy ./package.json dist"
BePo65 commented 2 years ago

I had the same problem. I think this is a documentation thing, as the README e.g. in npmjs says

: 
Examples
    Copy all .png files in src folder into dist except src/goat.png
    $ cpy 'src/*.png' '!src/goat.png' dist     <-- here we have single quotes that cause the problems

    Copy all .html files inside src folder into dist and preserve path structure
    $ cpy '**/*.html' '../dist/' --cwd=src --parents     <-- here we have single quotes that cause the problems
: 

but as @jhildenbiddle wrote, the single quotes are unnecessary (if the paths don't contain spaces - in that case escaping double quotes around the paths will solve the problem as @whizkidwwe1217 wrote)

So: wouldn't it be a good idea to update the README?

ediblecode commented 2 years ago

FWIW, I had a process running locally on Windows and on a TeamCity build agent on linux. Removing single quotes made it work OK on Windows but not on linux, Whereas using escaped double quotes as per @whizkidwwe1217's answer worked on both platforms.

seanohue commented 1 year ago

I ran into a similar problem on Mac as well when using cpy-cli 5.0.0 -- after upgrading from an earlier version I found my copy command broke -- files were no longer being copied in a recursive manner. After removing single quotes that I had wrapping all of the "source" parameters, it worked as expected.