Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bcomnes/cpx2
Maintenance fork of cpx. A cli tool to watch and copy file globs. 🤞hoping to get this work merged one day.
https://github.com/bcomnes/cpx2
Last synced: 12 days ago
JSON representation
Maintenance fork of cpx. A cli tool to watch and copy file globs. 🤞hoping to get this work merged one day.
- Host: GitHub
- URL: https://github.com/bcomnes/cpx2
- Owner: bcomnes
- License: mit
- Created: 2019-08-26T09:32:03.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2024-10-24T17:38:56.000Z (17 days ago)
- Last Synced: 2024-10-26T01:49:20.175Z (16 days ago)
- Language: JavaScript
- Homepage:
- Size: 377 KB
- Stars: 46
- Watchers: 3
- Forks: 3
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# cpx2
[![npm version](https://img.shields.io/npm/v/cpx2.svg)](https://www.npmjs.com/package/cpx2)
[![Downloads/month](https://img.shields.io/npm/dm/cpx2.svg)](http://www.npmtrends.com/cpx2)
[![tests](https://github.com/bcomnes/cpx2/actions/workflows/test.yml/badge.svg)](https://github.com/bcomnes/cpx2/actions/workflows/test.yml)Copy file globs, watching for changes.
This module provides a CLI tool like `cp`, but with watching.
This is a maintained fork of [mysticatea/cpx](https://github.com/mysticatea/cpx). It retains the `cpx` bin name, so it can act as a drop-in replacement.
## Installation
```
npm install cpx2
```## Usage
```
Usage: cpx [options]Copy files, watching for changes.
The glob of target files.
The path of a destination directory.Options:
-c, --command A command text to transform each file.
-C, --clean Clean files that matches like pattern in
directory before the first copying.
-f, --force Force the file to be copied, even if the
destination is readonly.
-i, --ignore A comma separated list of gitignore style ignore
patterns.
-L, --dereference Follow symbolic links when copying from them.
-h, --help Print usage information.
--include-empty-dirs The flag to copy empty directories which is
matched with the glob.
--no-initial The flag to not copy at the initial time of watch.
Use together '--watch' option.
-p, --preserve The flag to copy attributes of files.
This attributes are uid, gid, atime, and mtime.
-t, --transform A module name to transform each file. cpx lookups
the specified name via "require()".
-u, --update The flag to not overwrite files on destination if
the source file is older.
-v, --verbose Print copied/removed files.
-V, --version Print the version number.
-w, --watch Watch for files that matches , and copy
the file to every changing.
```## Example
```
$ cpx "src/**/*.{html,png,jpg}" app --watch
```This example will copy html/png/jpg files from `src` directory to `app`
directory, keeping file tree structure.
Whenever the files are changed, copy them.> Since Bash expands globs, requires to enclose it with double quotes.
You can use together [Browserify](http://browserify.org).
```
$ cpx "src/**/*.{html,png,jpg}" app -w & watchify src/index.js -o app/index.js
```You can use shell commands to convert each file.
```
$ cpx "src/**/*.js" app -w -c "babel --source-maps inline"
```You can use the transform packages for Browserify.
```
$ cpx "src/**/*.js" app -w -t babelify -t uglifyify
```It maybe can use to add header comment, to optimize images, or etc...
## Node.js API
You can use this module as a node module.
```js
var cpx = require("cpx2");
```### cpx.copy
```ts
cpx.copy(source, dest, options, callback)
cpx.copy(source, dest, callback)
```- **source** `{string}` -- A file glob of copy targets.
- **dest** `{string}` -- A file path of a destination directory.
- **options** `{object}`
- **options.clean** `{boolean}` -- The flag to remove files that copied on past before copy. Default: `false`.
- **options.dereference** `{boolean}` -- The flag to follow symbolic links when copying from them. Default: `false`.
- **options.includeEmptyDirs** `{boolean}` -- The flag to copy empty directories which is matched with the glob. Default: `false`.
- **options.initialCopy** `{boolean}` -- The flag to not copy at the initial time of watch. This is for `cpx.watch()`. Default: `true`.
- **options.force** `{boolean}` -- The flag to copy file to the destination, even if it is readonly.
- **options.preserve** `{boolean}` -- The flag to copy uid, gid, atime, and mtime of files. Default: `false`.
- **options.transform** `{((filepath: string) => stream.Transform)[]}` -- Functions that creates a `stream.Transform` object to transform each copying file.
- **options.update** `{boolean}` -- The flag to not overwrite files on destination if the source file is older. Default: `false`.
- **options.ignore** `{string|Array}` -- A gitignore style string or array of strings that make ignoring directory patterns easier. Default: []
- **callback** `{(err: Error|null) => void}` -- A function that is called at done.Copy files that matches with `source` glob to `dest` directory.
### cpx.copySync
```ts
cpx.copySync(source, dest, options)
cpx.copySync(source, dest)
```A synchronous function of `cpx.copy`.
Arguments is almost same as `cpx.copy`.
But `options.transform` is not supported.### cpx.watch
```ts
cpx.watch(source, dest, options)
cpx.watch(source, dest)
```Copy files that matches with `source` glob string to `dest` directory.
After the first copy, starts observing. And copy the files when every changes.Arguments is same as `cpx.copy`.
`cpx.watch` returns an `EventEmitter`.
- `.on("copy", (e) => { ... })` : Be fired after file is copied. `e.srcPath` is a path of original file. `e.dstPath` is a path of new file.
- `.on("remove", (e) => { ... })` : Be fired after file is removed. `e.path` is a path of removed file.
- `.on("watch-ready", () => { ... })` : Be fired when started watching files, after the first copying.
- `.on("watch-error", (err) => { ... })` : Be fired when occured errors during watching.## Changelog
[GitHub Releases](https://github.com/bcomnes/cpx2/releases)
## Contributing
Thank you for contributions!
### Bug Reports or Feature Requests
Please use GitHub Issues.
### Document Corrections
Please use GitHub Pull Requests.
I would especially thank for document corrections since I'm not familiar with English.### Feature Implementing
Please use GitHub Pull Requests.
There are some npm-scripts to help developments.
- `npm test` - Run tests and collect coverage.
- `npm run build` - Make lib directory from src directory.
- `npm run clean` - Delete directories (folders) which are created by other commands.
- `npm run lint` - Run ESLint.
- `npm run watch` - Run tests (not collect coverage) when each file was modified.
- `npm run open-coverage` - Open the coverage report of the last `npm test` command with web browser.