Giter Site home page Giter Site logo

cpx's People

Contributors

forivall avatar igor-toporet avatar k88hudson avatar mysticatea avatar pdehaan avatar quilicicf avatar yassh 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

cpx's Issues

How to exclude d.ts files?

I'm trying to copy over all files except those ending with .ts and .d.ts.
I've tried npx cpx src/**/*.!(ts) dest but it still copies over all .d.ts files.

d doesn't work nor d.ts does.

How to copy hidden folders?

i have the following directory stucture:

--dist
--------- **.ebextension** [folder]
--------- index.html [file]
--------- other files [files]

All my other files except .ebextension gets copied.

Add Support for TypeScript

Hi,

Are you willing to accept TypeScript typings within the repo itself?

This will make it more convenient for typescript users (and suggested by typescript) to provide typings with the repository itself, rather than another repo (such as DefinitelyTyped).

Are you willing to have a pull request for this?

I will be happy to create typing for this library myself if you agree.

Thanks!

npm audit issue

When running npm audit we get a issue on:
cpx > chokidar > anymatch > micromatch > braces

Would it be possible to update the version ?

Cheers,
Ringo.

cpx fails with ENOENT: no such file or directory, chmod...

Failed to copy: ENOENT: no such file or directory, chmod 'External/shared/node_modules/browser-resolve/node_modules/resolve/test/resolver/other_path/root.js'.

The file exists at source;
0 -rw-r--r-- 1 amp staff 0 Aug 26 17:12 root.js

And once the cpx fails, I check the destination the file is there too;
0 -rw-r--r-- 1 amp staff 0 Sep 7 2015 root.js

Is there a workaround for this?

cpx watches irrelevant files, while I want it to watch only one file

I use cpx like this:
cpx "./bundle.js" ../../resources/public/js --watch
and I expect it to watch only one file: bundle.js
but it watches many other irrelevant files. I have node_modules directory in the same directory I run cpx (where bundle.js is located), and it watches all files in the node_modules directory.

Fix security warning

Hi,

When installing cpx as a dependency of a project, npm gave me a warning about a vulnerability.
The problem comes from dependency chokidar, I've created an issue there.

┌───────────────┬──────────────────────────────────────────────────────────────┐
│ Low           │ Prototype Pollution                                          │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package       │ deep-extend                                                  │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ cpx [dev]                                                    │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path          │ cpx > chokidar > fsevents > node-pre-gyp > rc > deep-extend  │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info     │ https://nodesecurity.io/advisories/612                       │
└───────────────┴──────────────────────────────────────────────────────────────┘

I also noticed that the badge on the README points to another vulnerability, on debug this time (cf David report).

Thanks for developing cpx.
I can commit a fix if that helps.

No release in two years?

I was wondering why this package hasn't had a new release in a long time? There have been a lot of commits since then, including some dependency cleanup that my current project really needs

Add --after-command

Specify a shell command after every copy operations.

cpx src/**/*.{html,css,png} app --after-command "generate-appcache app"

npm audit issue [set-value] High

npm audit

High Prototype Pollution
Package set-value
Dependency of cpx
Path  cpx > chokidar > readdirp > micromatch > braces > snapdragon > base > cache-base > set-value 
More info https://npmjs.com/advisories/1012
High Prototype Pollution
Package set-value
Dependency of cpx
Path  cpx > chokidar > readdirp > micromatch > extglob > expand-brackets > snapdragon > base > cache-base > set-value
More info https://npmjs.com/advisories/1012
High Prototype Pollution
Package set-value
Dependency of cpx   
Path  cpx > chokidar > readdirp > micromatch > extglob > snapdragon > base > cache-base > set-value
More info https://npmjs.com/advisories/1012                           
High Prototype Pollution
Package set-value
Dependency of cpx
Path  cpx > chokidar > readdirp > micromatch > nanomatch > snapdragon > base > cache-base > set-value
More info https://npmjs.com/advisories/1012
High Prototype Pollution
Package set-value
Dependency of cpx
Path cpx > chokidar > readdirp > micromatch > snapdragon > base > cache-base > set-value
More info https://npmjs.com/advisories/1012
High Prototype Pollution
Package set-value
Dependency of cpx                                                  
Path cpx > chokidar > readdirp > micromatch > braces > snapdragon > base > cache-base > union-value > set-value               
More info https://npmjs.com/advisories/1012
High Prototype Pollution
Package set-value
Dependency of cpx
Path cpx > chokidar > readdirp > micromatch > extglob > expand-brackets > snapdragon > base > cache-base > union-value > set-value
More info https://npmjs.com/advisories/1012
High Prototype Pollution
Package set-value
Dependency of cpx
Path cpx > chokidar > readdirp > micromatch > extglob > snapdragon > base > cache-base > union-value > set-value
More info https://npmjs.com/advisories/1012
High Prototype Pollution
Package set-value
Dependency of cpx
Path cpx > chokidar > readdirp > micromatch > nanomatch > snapdragon > base > cache-base > union-value > set-value
More info https://npmjs.com/advisories/1012
High Prototype Pollution
Package set-value
Dependency of cpx
Path  cpx > chokidar > readdirp > micromatch > snapdragon > base > cache-base > union-value > set-value
More info https://npmjs.com/advisories/1012

How to rename file?

I want to copy a icon file to a new place and rename it to favicon.ico.

cpx.copy('./resources/icon.ico', `${destRoot}/favicon.ico`)

include none-ts files, and templates/**/*.* and exclude node_modules

I want to match all none-ts files, and all files inside templates folder including ts files
and totally exclude node_modules

please don't suggest extended patterns
i.e: {!(node_modules/), !(*.ts), templates/}
because it will run the glob multiple times, causing to include node_modules in the other extended patterns

also !(node_modules/) not works
and !(node_modules)/
cannot be used with files, i.e: !(node_modules | .ts)/*

examples:
node_modules/some-module/file.js (not matches: inside node_modules)
dir/subdir/file.ts (not matches: .ts)
dir/subdir/files/file.ts (matches: .ts file, but inside files/ dir)

./ paths don't work

Not sure if this is intended but the following doesn't work:

cpx \"./src/static/**/*\" ./www

If you remove the dot slashes it works fine. I will get a better STR for this later.

Include "dotfiles" together with normal files

Currently I need to do 2 separate commands to copy a folder with subfolder AND include dotfiles (e.g .gitignore, .editorconfig)

Commands I'm doing:

# Copy over WPWebStatic-files
yarn cpx './export/WPWebStatic-files/**/*' ./export/WPWebStatic
# Separate command for 'dotfiles' (would be nice to combine it with previous)
yarn cpx './export/WPWebStatic-files/.*' ./export/WPWebStatic

I'd like to figure a way to copy both in one command. Any tips?..

`--follow` option

cpx is ignoring symlink directories.
If this --follow option is specified, cpx will copy files inside of symlink directories.

Empty directories are not copied

Empty directories are not copied from source destination to target location

Example: cpx 'static/**/*' 'dest' --verbose

This at the moment causing me no issues as I don't need to copy empty directories but I believe it may cause issues to someone. I believe it's a good candidate for a command line option, something like:

cpx 'static/**/*' 'dest' --verbose --include-empty-dirs

Or the other way around, by copying all directories by default and allow user to specify if he wants to avoid empty directories by an command line option.

Throws ENOENT when dest is in tmpdir

Internally dest path is converted to relative one by normalizePath() but it make fs.open() failed when dest is in tmpdir.

Sample

Environment

  • cpx: 1.5.0
  • NodeJS: v10.15.3
  • OS: macOS Catalina 10.15.2

Code

const os = require('os')
const cpx = require('cpx')

cpx.copySync('*.js', os.tmpdir())

Result

$ node tester.js
fs.js:114
    throw err;
    ^

Error: ENOENT: no such file or directory, copyfile 'tester.js' -> '../../../../../var/folders/1h/chh659g57sg3v_wks3v7z43h0000gn/T/tester.js'
    at Object.copyFileSync (fs.js:1723:3)
    at copyFile (/Users/nandenjin/sample_package/node_modules/cpx/node_modules/fs-extra/lib/copy-sync/copy-sync.js:68:8)
    at onFile (/Users/nandenjin/sample_package/node_modules/cpx/node_modules/fs-extra/lib/copy-sync/copy-sync.js:52:41)
    at getStats (/Users/nandenjin/sample_package/node_modules/cpx/node_modules/fs-extra/lib/copy-sync/copy-sync.js:47:39)
    at startCopy (/Users/nandenjin/sample_package/node_modules/cpx/node_modules/fs-extra/lib/copy-sync/copy-sync.js:37:10)
    at Object.copySync (/Users/nandenjin/sample_package/node_modules/cpx/node_modules/fs-extra/lib/copy-sync/copy-sync.js:32:10)
    at copyFileSync (/Users/nandenjin/sample_package/node_modules/cpx/lib/utils/copy-file-sync.js:50:12)
    at sourcePath (/Users/nandenjin/sample_package/node_modules/cpx/lib/copy-sync.js:63:13)
    at applyActionSync (/Users/nandenjin/sample_package/node_modules/cpx/lib/utils/apply-action-sync.js:36:9)
    at Object.copySync (/Users/nandenjin/sample_package/node_modules/cpx/lib/copy-sync.js:60:5)

NPM install fails on 1.3.0

I think there is something wrong with the newest version of the package in NPM:

npm install
npm ERR! Windows_NT 6.3.9600
npm ERR! argv "C:\Program Files\nodejs\node.exe" "C:\Users\xxx\AppData\Roaming\npm\node_modules\npm\bin\npm-cli.js" "install"
npm ERR! node v5.4.1
npm ERR! npm v3.8.0
npm ERR! path C:\Code\xxx\node_modules\cpx\bin\index.js
npm ERR! code ENOENT
npm ERR! errno -4058
npm ERR! syscall chmod

npm ERR! enoent ENOENT: no such file or directory, chmod 'C:\Code\xxx\node_modules\cpx\bin\index.js'
npm ERR! enoent ENOENT: no such file or directory, chmod 'C:\Code\xxx\node_modules\cpx\bin\index.js'
npm ERR! enoent This is most likely not a problem with npm itself
npm ERR! enoent and is related to npm not being able to find a file.
npm ERR! enoent

When I change the version to 1.2.1 in package.json, everything seems to be ok.

CLI `cpx` copies a file to wrong place

CLI cpx copies a file to wrong place.

$ cpx a.txt dist

expected
./a.txt
./dist/a.txt

actual
./a.txt
./adisttxt

$ cpx ./a.txt dist

expected and actual
./a.txt
./dist/a.txt

This is my environment.

cpx v1.2.0
Mac OS X 10.9.5
node.js v0.12.7

Doesn't work with yarn and npm scripts

Running yarn build with the following npm script does absolutely nothing, with or without the escaped double quotes.

"scripts": {
    "build": "rm -rf dist && NODE_ENV=production webpack -p --config webpack.config.js && cpx \"/dist/*.js\" \"/static/\"",
}

Node 12.13.0
cpx 1.5.0
yarn 1.19.1
latest MacOS

Tests are failing on master due to eslint

Tests are failing with the following output as of eslint v0.21.1 (on Linux/travis, Mac OSX)

src/cpx.js
  71:6  error  Cpx is already declared in the upper scope  no-shadow

src/queue.js
  17:6  error  Queue is already declared in the upper scope  no-shadow

✖ 2 problems (2 errors, 0 warnings)

Issue is filed on eslint here eslint/eslint#2545, looks like a fix is incoming here eslint/eslint#2547

Would you maybe like to lock down the version of eslint to v0.21.0?

(Tested on Mac OSX 10.10.2, node v0.12.2, npm 2.7.4)

How to use --no-initial together with --clean ?

Hi,

I'm trying to use cpx 'index.html' 'build' --no-initial --watch --clean. My desired behavior is:

Don't perform any copy after execution. Don't perform clean until the first copy (delayed by --no-initial, triggered by user saving the file).

However, it seems like --clean won't be blocked/delayed by --no-initial parameter. Instead, it will always do the clean right after executing the command.

My use case is that I need to override the destination file (read-only) when user first hit "Save" (override on every "Save" is better) , meaning that I want to perform copy index.html (edited) -> build/index.html (read-only) while watching.

I saw we have options for not overriding, but it seems during watching it won't override by default either.

Initial copy

Maybe I am doing something wrong, but I miss an option for having the program watch a directory and copy everything over initially. Currently I run the command twice; with and without --watch.

Watch does not work when path contains parentheses

While the following works:

cpx.watch("/tmp/dir1/file1.xml", "/tmp/dir2", {initialCopy:false}, function(err){});

This doesn't:

cpx.watch("/tmp/dir1(copy)/file1.xml", "/tmp/dir2", {initialCopy:false}, function(err){});

Tested on Windows10 / Ubuntu.
I even tried to escape like this: \( \) but it didn't work.

FYI: I've tested glob module separately (using default options) and it doesn't have any problems with parentheses in the above path.

Using this awesome tool with jsonnet CLI

I'm trying with no luck to transpile my "jsonnet" files with cpx and the jsonnet command line tool.

These work:

jsonnet.exe - < config.jsonnet
echo {a:'b', b:self.a} | jsonnet.exe -

How can I use the jsonnet CLI transpiler employing the --command option?

I tried this in an npm script:

"scripts": {
  "build:json": "cpx \"./**/*.jsonnet\" build -c \"jsonnet.exe -\"",
}

cpx

Hey,

I've tried everything but I'm on windows and can't figure out how to copy a file that doesn't have an extension. Is this something obvious i'm missing? cpx is either ignoring it or treating it as a directory

no overwrite option

i'd be interested (and possibly enough to develop and send a PR) in an option that prevented existing files in the dest directory from being written over. is this something the project maintainers would be interested in?

my use case is that i have a directory where i've outputted babel compiled javascript files from my entire source directory. within my source directory i have files that are not compiled by babel, and therefore not in the destination. i'd like to copy those wholesale by running something like cpx src build --no-overwrite so that the compiled files are left untouched and the remaining source files are copied to be alongside the compiled counterparts.

Tests fail on Max OS X

After #8 is fixed, two tests fail on Max OSX 10.10.2 with the following output:

  The copy method
    should copy specified file blobs:
      ✓ lib async version.
      ✓ lib sync version.
      ✓ command version. (194ms)
    should clean and copy specified file blobs when give clean option:
      ✓ lib async version.
      ✓ lib sync version.
      ✓ command version. (196ms)
    should copy with transform if specified command option.
      ✓ command version. (289ms)
    should copy with transform if specified transform option.
      ✓ lib async version.
      ✓ should throw an error on lib sync version (cannot use streaming api).
      ✓ command version. (206ms)
    should keep order even if -c and -t are mixed.
      ✓ command version. (303ms)

  The watch method
    should copy specified file blobs at first:
      ✓ lib version.
      ✓ command version. (215ms)
    should clean and copy specified file blobs at first when give clean option:
      ✓ lib version.
      ✓ command version. (226ms)
    should copy on file added:
      1) lib version.
      ✓ command version. (401ms)
    should do nothing on file added if unmatch file globs:
      ✓ lib version. (177ms)
      2) "after each" hook

  17 passing (3s)
  2 failing

  1) The watch method should copy on file added: lib version.:
     Uncaught AssertionError: expected null to equal 'added'
      at verifyFiles (test/watch.js:282:36)
      at test/watch.js:291:13
      at Cpx.listener (test/watch.js:57:9)
      at lib/cpx.js:222:19
      at WriteStream.done (lib/copy.js:43:5)
      at finishMaybe (_stream_writable.js:484:14)
      at endWritable (_stream_writable.js:493:3)
      at WriteStream.Writable.end (_stream_writable.js:459:5)
      at ReadStream.onend (_stream_readable.js:505:10)
      at _stream_readable.js:908:16

  2) The watch method "after each" hook:
     Uncaught Error: ENOENT, open 'test-ws/b/a.txt'
      at Error (native)

More documents

  • The transform option of Node.js API
  • Details about --command, --transform

option to skip the first copy (only watch)

Hi, nice package.
For the cpx.watch, it would be nice to be able to skip the first copy (if files are already in sync.) Maybe add an option to the watch command (nocopy)?

"transform" option throw error for 'on' of undefined.

I have this:

...
var cpx = require("cpx");

async function copy() {
  return await cpx.copy(
    source,
    dest,
    { clean: true, transform: filepath => console.log(filepath) },
    err => {
      if (err) throw err;
      return console.log("OK");
    }
  );
}
...

and I receive this:

script/first.txt
script/second.txt

C:\scripts\script.js:113
      if (err) throw err;
               ^

TypeError: Cannot read property 'on' of undefined
    at C:\scripts\node_modules\cpx\lib\copy.js:56:15
    at Array.reduce (<anonymous>)
    at copyBody (C:\scripts\node_modules\cpx\lib\copy.js:54:28)
    at Object.action (C:\scripts\node_modules\cpx\lib\copy.js:119:13)
    at Immediate.dequeue [as _onImmediate] (C:\scripts\node_modules\cpx\lib\queue.js:37:10)
    at runCallback (timers.js:793:20)
    at tryOnImmediate (timers.js:751:5)
    at processImmediate [as _immediateCallback] (timers.js:722:5)
error Command failed with exit code 1.

As you can see it works good but at the end it throw error, why?

NodeJS 8.9.1, "cpx": "~1.5.0".

npm audit issue [mixin-deep] High

npm audit

High          Prototype Pollution
Package       mixin-deep
Dependency of cpx
Path          cpx > chokidar > readdirp > micromatch > braces > snapdragon > base > mixin-deep 
More info     https://npmjs.com/advisories/1013
High          Prototype Pollution 
Package       mixin-deep
Dependency of cpx
Path          cpx > chokidar > readdirp > micromatch > extglob > expand-brackets > snapdragon > base > mixin-deep
More info     https://npmjs.com/advisories/1013 
High          Prototype Pollution
Package       mixin-deep
Dependency of cpx
Path          cpx > chokidar > readdirp > micromatch > extglob > snapdragon > base > mixin-deep
More info     https://npmjs.com/advisories/1013
High          Prototype Pollution
Package       mixin-deep
Dependency of cpx
Path          cpx > chokidar > readdirp > micromatch > nanomatch > snapdragon > base > mixin-deep
More info     https://npmjs.com/advisories/1013
High        Prototype Pollution 
Package     mixin-deep                                                  
Dependency of cpx                                                 
Path        cpx > chokidar > readdirp > micromatch > snapdragon > base > mixin-deep
More info     https://npmjs.com/advisories/1013                           

Possibility of echoing a message

I was wondering if an option could be added such that a message is printed to the terminal every time that the cpx gets executed.

With the current implementation, when you modify an HTML file, it is not possible to know how much to wait to refresh the browser (if for instance you happen to be doing web development).

Edit: I have missed the --verbose option, which is enough for my particular purpose. I'm closing the issue.

[Feature] Promise-based API?

Right now, cpx can be used either synchronously, or asynchronously using callbacks. With the trend in the world of NodeJS to move to native Promises - what about providing a promise-based API?

Perhaps something like copyAsync? Or replacing the copy and introducing a breaking change?

Any way to ignore/exclude a file or folder?

I'm looking for a way to ignore a file or folder during the copy. For instance, if I want to copy all js files in a folder except a particular one. I haven't seen any examples or syntax that uses the ! option that minimatch and most other glob matchers use.

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.