Giter Site home page Giter Site logo

cpy-cli's Introduction

cpy-cli

Copy files

Why

  • Fast by using streams.
  • Resilient by using graceful-fs.
  • User-friendly by accepting globs and creating non-existent 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
    --cwd=<dir>          Working directory for files
    --rename=<filename>  Rename all <source> filenames to <filename>. Supports string templates.
    --dot                Allow patterns to match entries that begin with a period (.)
    --flat               Flatten directory structure. All copied files will be put in the same directory.
    --concurrency        Number of files being copied concurrently

  <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 files inside src folder into dist and preserve path structure
    $ cpy . '../dist/' --cwd=src

    Copy all .png files in the src folder to dist and prefix the image filenames
    $ cpy 'src/*.png' dist --cwd=src --rename=hi-{{basename}}

Related

  • cpy - API for this module

cpy-cli's People

Contributors

andy2mrqz avatar antongolub avatar deining avatar drewml avatar jaywcjlove avatar jopemachine avatar kevva avatar mfal avatar richienb avatar samverschueren avatar sindresorhus avatar xtqqczze 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  avatar

cpy-cli's Issues

`--cwd` flag does not work

Previously I was executing the following command with 3.1.x

cpy **/*.scss !**/*.stories.scss ../lib --parents --cwd=src

with a result similar to:

% ls lib/**/*.scss 
lib/Button/Button.scss
lib/ButtonLink/ButtonLink.scss
lib/Checkbox/Checkbox.scss

However, the 4.0 release doesn't find any files to copy. This seems like a globbing problem.

macOS problemam with subfolders

Platform

macOS monterey M1 Max processor Node 18.17.0 npm 9.6.7

If I define a script in package.json with

cpy 'prisma/parts/schema.prisma' 'prisma/'

and I run nom run script from the project root folder a prisma folder is created under the prisma folder in the project root

instead of copying schema.prisma from prisma/parts in prisma

Tested both 4.2.0 and 5.0.0, with version 3.1.1 the behaviour is correct

Help converting syntax for package.json script

I am using this for a build process that is simple enough to live strictly in NPM via scripts in package.json.

I have no problems using the tool when the syntax uses wildcards in directory; for example:

cpy ../../../shared/picker/*.min.js dist/js/vendor/

But it doesn't do anything (nor throw an actual error, mind you) when I try to single out just a specific file like this:

cpy ../../../shared/picker/picker.min.js dist/js/vendor/

I tried understanding how to translate the original API from "cpy", but the samples were Javascript function calls rather than passing arguments in the command line.

Is the single-file method not supported, or am I missing something in my syntax?

npx cpy-cli --nooverwrite produces an error when file exists. Expected skip

Platform

windows 11 22H2
[email protected]

When I execute

npx cpy-cli .\test.json foo\ --no-overwrite

it returns the error

Cannot copy from `test.json` to `d:\temp\foo\test.json`: 
Cannot write to `d:\temp\foo\test.json`: EEXIST: file already exists, open 'd:\temp\foo\test.json'

Issuing the command without --no-overwrite works fine (but the file is overwritten)

Expected

when setting the --no-overwrite parameter it should continue without error even if the file exists.

My Misunderstanding of purpose?

I found the test for cpy, it appears it is expected that overwrite:false will throw an exception? If so is there any way to 'skip/ignore' existing files similar to how the non async approach appears to work?

test('do not overwrite', async t => {
	fs.mkdirSync(t.context.tmp);
	fs.writeFileSync(path.join(t.context.tmp, 'license'), '');

	await t.throwsAsync(cpy(['license'], t.context.tmp, {overwrite: false}));

	t.is(read(t.context.tmp, 'license'), '');
});

EDIT: reading cp-file code, if I understand async copy overwrite false will throw an exception, but sync copy overwrite will not. If that is correct, then this was just a misunderstanding, please close the issue.

--dot flag appears broken

Not entirely sure if this is related to #22, but the --dot flag appears to be non-functional on the latest version. The command:

cpy --dot *.{yml,yaml} dist

does not copy a .meshrc.yml file in the directory, but does copy both .yml and .yaml files without a leading . in the filename.

.sh file permission changed?

I have a .sh file with +x permissions on it. When I copy it:

cpy \"**/*.sh\" \"../dist/\" --cwd=src --parents

it's execute permissions are stripped / not maintained.

Is it expected?

Thanks! Chad

option for ignore error if not found files

I run.

cpy 'public/**/*.*' '../build/' --cwd=src --parents

Output:

Cannot glob `public/**/*.*,!**/*-src.*`: Cannot copy from `/path/to/src/public/**/*.*` to `/path/to/build/public/**/*.*`: cannot read from `/path/to/public/**/*.*`: ENOENT: no such file or directory, open '/path/to/src/public/**/*.*'

Initial folder structure not restored in destination folder

Hey πŸ‘‹ First thanks for the effort put in this project πŸ‘

I have a project structure that looks like this:

project
β”‚
└───node_modules
β”‚   └───module
β”‚       └───public
β”‚           └───dist
β”‚               β”‚ styles.css
β”‚           β”‚ index.html
β”‚   
└───src

And I want to copy the public folder from node_modules/module/public into the src/public folder. So I run this command:

$ yarn cpy ./node_modules/module/public ./src/public

It works but the final src/public folder contains all the files but not the initial folder structure:

# just the files
β”‚   
└───src
    └───public
        β”‚ styles.css
        β”‚ index.html
# expected folder structure
β”‚   
└───src
    └───public
        └───dist
            β”‚ styles.css
        β”‚ index.html

And if I run it with the --parents I got this structure:

public
β”‚
└───node_modules
β”‚   └───module
β”‚       └───public
β”‚           └───dist
β”‚               β”‚ styles.css
β”‚           β”‚ index.html

Has someone an idea how I could get the expected folder structure?

Thanks in advance πŸ˜„

Add `--watch` option

I found this previous issue #11 that was withdrawn by the requester, but i still need it. None of the related tools work for me, since i specifically need to not preserve the directory structure, and cpy is the only node tool i've found that doesn't.

Cannot simply copy an entire folder

Issuehunt badges

I am getting errors for all folder with this command

cpy test/dist somewhere
Cannot glob `test/dist/folder, test/dist/folder-2`:  EISDIR: illegal operation on a directory, read

I tried

cpy test/dist/**/* somewhere

but same result.

I understand why there is an error, but it's pretty weird to not be able to ignore folder, I would have make this the default behavior.


IssueHunt Summary

Backers (Total: $80.00)

Submitted pull Requests


Become a backer now!

Or submit a pull request to get the deposits!

Tips

Please bump cpy package version.

Here is a vulnerability related to make-dir package which is used in version 9.1.0 of cp-file package.

At the moment the cpy-cli package depends on vulnerable version of cpy, since uses not the last version of that package.

The npm audit report gives the following output:
image

Thanks in advance.

[Minor] Windows Argument Escaping

For Windows users the --help examples are misleading, e.g.:

C:\test>dir src
…
07.10.2016  19:07                 0 goat.png
07.10.2016  19:07                 0 unicorn.png
C:\test>cpy --help
…
  Examples
    Copy all .png files in src folder into dist except src/goat.png
    $ cpy 'src/*.png' '!src/goat.png' dist
C:\test>cpy 'src/*.png' '!src/goat.png' dist
Cannot glob `'src/*.png','!src/goat.png'`: …

NB: Double quotes work as expected:

C:\test>cpy "src/*.png" "!src/goat.png" dist
C:\test>dir dist
…
07.10.2016  19:07                 0 unicorn.png

No errors on missing source

As the title implies, if the source folder doesn't exist, the cpy-cli doesn't complain/raise errors and does an exit(0) too.

Example:

npx cpy "./resources/fonts/*.*" "./public/fonts" --concurrency=20

Getting error `Only file and data URLs are supported by the default ESM loader` on Node v14.0.0-14.13.0 with [email protected]

It works fine in Node v12 and later versions of Node v14, but not Node v14.0.0 - 14.13.0.

$ npx [email protected] docs tests
npx: installed 100 in 1.747s
internal/modules/run_main.js:54
    internalBinding('errors').triggerUncaughtException(
                              ^

Error [ERR_UNSUPPORTED_ESM_URL_SCHEME]: Only file and data URLs are supported by the default ESM loader
    at Loader.defaultResolve [as _resolve] (internal/modules/esm/resolve.js:666:11)
    at Loader.resolve (internal/modules/esm/loader.js:97:40)
    at Loader.getModuleJob (internal/modules/esm/loader.js:243:28)
    at ModuleWrap.<anonymous> (internal/modules/esm/module_job.js:42:40)
    at link (internal/modules/esm/module_job.js:41:36) {
  code: 'ERR_UNSUPPORTED_ESM_URL_SCHEME'

[email protected] does work on all of those versions.

Not working with .env files

I am using version "cpy-cli": "^4.2.0",

I am trying to copy ".env.qa" contents to ".env" file in the same directory structure but its not working as intended. Instead of writing the contents, it creates a "/.env/.env.qa" directory & file.

I have tried the --dot and --flat flags but that doesn't solve the problem.

cpy .env.qa .env --dot --flat

I wanted to copy my environment variables from .env.qa or .env.production to .env file so it can be used with .dotenv package.

Windows CI

With all the path handling stuff, I think, the CLI would profit from testing on Windows too.

@sindresorhus Would you mind to add support for Appveyor? At least for me, it's a bit cumbersome to run tests on Windows.

Btw, this may also be convenient for cpy and cp-file.

[Windows] not working in npm script if use '

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

Inconsistent file tree depending on OS

Consider the following file tree:

dist-tmp
└── index.html

On Windows, the command npx cpy-cli dist-tmp/** dist/ results in:

dist
└── index.html

On Linux, the same command npx cpy-cli dist-tmp/** dist/ results in:

dist
└── dist-tmp
    └── index.html

It happened using node 18.18.0 on both systems

file already exists

We have .env and .env.development files in the C:\projects\xxx\.
Running cpy gives:

$ npx cpy './.env.development' './.env'
Cannot copy from `C:\projects\xxx\.env.development` to `C:\projects\xxx\.env\.env.development`: Cannot create directory `C:\projects\xxx\.env`: EEXIST: file already exists, mkdir 'C:\projects\xxx\.env'

Is that the expected result? Is there a workaround?
@sindresorhus

Usage in `package.json` script throws "const in script mode" error

When used in a package.json script, the script fails. For example:

  "scripts": {
    "bork": "cpy ./node_modules/font-awesome/fonts/* build/fonts/"
  },
C:\dev\test>npm run bork

> [email protected] bork C:\dev\test
> cpy ./node_modules/font-awesome/fonts/* build/fonts/

C:\dev\test\node_modules\cpy-cli\cli.js:3
const meow = require('meow');
^^^^^
SyntaxError: Use of const in strict mode.
    at exports.runInThisContext (vm.js:73:16)
    at Module._compile (module.js:443:25)
    at Object.Module._extensions..js (module.js:478:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Function.Module.runMain (module.js:501:10)
    at startup (node.js:129:16)
    at node.js:814:3

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.