Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

cpx2

bcomnes333.2kMIT8.0.0

Copy file globs, watching for changes.

cp, cli, tool, commandline, sync, rsync, watch, observe, copy, dir, directory, directories, file, files

readme

cpx2

npm version Downloads/month tests

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. It retains the cpx bin name, so it can act as a drop-in replacement.

Installation

npm install cpx2

Usage

Usage: cpx <source> <dest> [options]

    Copy files, watching for changes.

        <source>  The glob of target files.
        <dest>    The path of a destination directory.

Options:

    -c, --command <command>   A command text to transform each file.
    -C, --clean               Clean files that matches <source> like pattern in
                              <dest> 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 <name>    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 <source>, and copy
                              the file to <dest> 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.

$ 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.

var cpx = require("cpx2");

cpx.copy

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<string>} -- 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

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

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

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.

changelog

Changelog

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog and this project adheres to Semantic Versioning.

Generated by auto-changelog.

v8.0.0

Commits

  • Breaking change: Update engines field to node 20 f17186a
  • Merge pull request #125 from bcomnes/deps edb319e
  • Update p-map and double check installed-check af2efce

v7.0.2 - 2024-10-04

Merged

  • Upgrade: Bump glob from 10.4.4 to 11.0.0 #119
  • Upgrade: Bump minimatch from 9.0.5 to 10.0.1 #118
  • Upgrade: Bump nyc from 15.1.0 to 17.0.0 #117

Fixed

  • Set allowRelativePaths for apply acitons #113

Commits

  • Merge pull request #124 from bcomnes/fix-relative-copy-errors e35a68a
  • Merge pull request #123 from bcomnes/neostandard ab10190
  • Autofix 1396a28

v7.0.1 - 2023-12-29

Commits

  • fix: minimum node version down to 18 05a55cc

v7.0.0 - 2023-12-25

Commits

  • Remove files filter e9ef541
  • Bump minimum node version to lts 20 56bbc19
  • Upgrade: Bump debounce from 1.2.1 to 2.0.0 390cd9d

v6.0.1 - 2023-10-25

Merged

  • Upgrade: Bump actions/setup-node from 3 to 4 #111

Commits

  • Fix windows bugs with new glob eb7ab6a
  • Add more OSs to tests 35128d8

v6.0.0 - 2023-10-22

Merged

  • Update to the latest glob #110
  • Upgrade: Bump actions/checkout from 3 to 4 #109

Commits

v5.0.0 - 2023-07-05

Merged

  • Upgrade: Bump minimatch from 8.0.4 to 9.0.0 #107

Commits

v4.2.3 - 2023-04-03

Merged

  • Upgrade: Bump minimatch from 7.4.4 to 8.0.2 #106

v4.2.2 - 2023-03-07

Merged

  • Upgrade: Bump mocha from 9.2.2 to 10.2.0 #79

v4.2.1 - 2023-03-07

Merged

Commits

v4.2.0 - 2022-02-08

Merged

  • Fix #53: Overwrite readonly #57
  • Upgrade: Bump actions/setup-node from 2.5.0 to 2.5.1 #52

Fixed

  • Merge pull request #57 from schutm/overwrite-readonly #53

Commits

  • Add force flag to overwrite readonly files e622923
  • Eat exception if target doesn't exist f7c1fb3
  • Pin to major actions version 94a5f34

v4.1.2 - 2021-12-23

Merged

  • Allow watching from a relative directory again #51

Fixed

  • Allow watching from a relative directory again #44

v4.1.1 - 2021-12-22

Merged

  • Remove co #50

Commits

v4.1.0 - 2021-12-22

Merged

  • Upgrade: Bump actions/checkout from 2.3.4 to 2.4.0 #39
  • Upgrade: Bump actions/setup-node from 2.4.0 to 2.5.0 #45
  • Return a report object containing details about the copy operation #49

v4.0.0 - 2021-09-15

Merged

  • Add gitignore style ignore support #32

Commits

  • Breaking change: Require node >=14 074e5b5
  • Add ignore option and flag be9680c

v3.0.2 - 2021-08-13

Commits

  • Revert "Merge pull request #23 from mhanberg/mh/exit-on-stdin-closing" d1275a0

v3.0.1 - 2021-08-09

Merged

  • Upgrade: Bump actions/setup-node from 2.3.2 to 2.4.0 #31
  • Exit when stdin closes #23
  • Upgrade: Bump fs-extra from 9.1.0 to 10.0.0 #17
  • Upgrade: Bump gh-release from 4.0.4 to 6.0.0 #20
  • Upgrade: Bump mocha from 8.4.0 to 9.0.3 #28
  • Upgrade: Bump actions/setup-node from 2.1.2 to 2.3.2 #30
  • Upgrade: Bump actions/checkout from v2.3.3 to v2.3.4 #11
  • Upgrade: Bump bcomnes/npm-bump from v2.0.1 to v2.0.2 #10
  • Upgrade: Bump actions/setup-node from v2.1.1 to v2.1.2 #9
  • Upgrade: Bump actions/checkout from v2.3.2 to v2.3.3 #8

Commits

v3.0.0 - 2020-09-18

Merged

  • Upgrade: Bump @mysticatea/eslint-plugin from 11.0.0 to 13.0.0 #4
  • Upgrade: Bump nyc from 14.1.1 to 15.1.0 #5
  • Upgrade: Bump eslint from 6.8.0 to 7.9.0 #6
  • Upgrade: Bump fs-extra from 8.1.0 to 9.0.1 #7
  • Upgrade: Bump mocha from 6.2.3 to 8.1.3 #3
  • try building windows #2

Commits

v2.0.0 - 2019-08-26

Merged

  • Maintenance tasks #1
  • Fix: fix vulnerability #43
  • Docs: fix typo w/ watch-ready #31
  • Add "text-summary" nyc reporter #26
  • Fix typo "untachable" => "untouchable" #25

Commits

  • Chore: remove package-lock.json db3e7f0
  • Breaking: stop transpiling e1d9b6e
  • Rewrite implementation 3098ae3

v1.5.0 - 2016-09-05

Commits

  • New: --include-empty-dirs option 6324e50
  • New: --no-initial option bae874a
  • Docs: fix wrong link of Changelog. 77b1627

v1.4.0 - 2016-09-03

Merged

  • Revise README.md #20

Fixed

  • New: --update option to disallow overwriting (fixes #12) #12

Commits

  • New: --preserve option to copy uid,gid,atime,mtime. 217004b
  • Chore: add some tests for misc. 82be9ae
  • Docs: add changelog/contributing sections 3de04d5

v1.3.2 - 2016-07-20

Fixed

  • Fix: check whether 'destroy' method exists or not to transform (fixes #18) #18

Commits

  • Chore: upgrade ESLint and my eslintrc 2a68c2f
  • Chore: upgrade dependencies. 07e3dc2
  • Chore: executes eslint only if node version >=4 11297e5

v1.3.1 - 2016-03-11

Commits

v1.3.0 - 2016-03-10

Fixed

  • New: --dereference option (fixes #14) #14
  • Fix: failed initial copies if target path starts with './' (fixes #13) #13

Commits

v1.2.1 - 2015-07-19

Commits

  • Fix: copying of a file in cwd (refs #11) b150cdd
  • Update dependencies. 861c36c

v1.2.0 - 2015-05-17

Commits

v1.1.6 - 2015-04-19

Commits

v1.1.5 - 2015-04-05

Commits

v1.1.4 - 2015-03-22

Commits

v1.1.3 - 2015-03-18

Commits

v1.1.2 - 2015-03-18

Commits

v1.1.1 - 2015-03-14

Commits

v1.1.0 - 2015-03-14

Fixed

  • Add --transform option #1

Commits

v1.0.0 - 2015-03-09

Commits