mysticatea / cpx Goto Github PK
View Code? Open in Web Editor NEWA cli tool to watch and copy file globs.
License: MIT License
A cli tool to watch and copy file globs.
License: MIT License
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.
Line 33 in 79671ba
i have the following directory stucture:
--dist
--------- **.ebextension** [folder]
--------- index.html [file]
--------- other files [files]
All my other files except .ebextension gets copied.
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!
When running npm audit we get a issue on:
cpx > chokidar > anymatch > micromatch > braces
Would it be possible to update the version ?
Cheers,
Ringo.
I have installed cpx using npm i cpx -D
but when I try to run it I got message 'cpx' is not recognized as an internal or external command
I would really like to see this tool being able to load up config file. What are your thoughts on this? I would happily make a PR.
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?
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.
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.
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
Specify a shell command after every copy operations.
cpx src/**/*.{html,css,png} app --after-command "generate-appcache app"
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 |
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`)
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)
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.
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?..
cpx
is ignoring symlink directories.
If this --follow
option is specified, cpx
will copy files inside of symlink directories.
cpx defines a lot of vulnerabile dependencies, such as:
Can you please update these deps? @mysticatea
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.
Internally dest path is converted to relative one by normalizePath()
but it make fs.open()
failed when dest is in tmpdir.
1.5.0
v10.15.3
macOS Catalina 10.15.2
const os = require('os')
const cpx = require('cpx')
cpx.copySync('*.js', os.tmpdir())
$ 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)
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.
$ 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
How can I flatten the folder structure and just copy the files? Similar to what copyfiles
library does with -f
option (https://www.npmjs.com/package/copyfiles).
I'm using cpx './dist/**/*.umd.js' './dest/assets'
, but this maintains the tree structure and creates all the subfolders in the destination directory. I need to copy just the files under the root of the destination folder.
The spec will be as same as Browserify.
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 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)
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.
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
.
First of all, awesome tool!
I am trying to create a transform module that convert all '.tpl' files into '.js'.
Could you please provide to me some guidelines or point me out with some documentation/examples?
Thanks in advance.
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.
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 -\"",
}
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
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.
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)
sometimes chokidar should be tuned to a concrete OS to work reliable, be able to pass chokidar options will be nice
I tried the following
cpx {a,b}/* c/
expecting all the files from inside a/
and b/
to be copied into c/
. Instead I ended up with c/a/
and c/b/
.
I'm not sure if this is a bug or my expectations are wrong.
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)?
Generally, -v
is --version
It would be nice if --clean
were a bit more smart and only deleted output files with no matching input.
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
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 |
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.
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?
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.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.