• Stars
    star
    524
  • Rank 84,541 (Top 2 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created almost 10 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A cli tool to watch and copy file globs.

cpx

npm version Downloads/month Build Status codecov Dependency Status

Copy file globs, watching for changes.

This module provides a CLI tool like cp, but with watching.

Installation

npm install cpx
  • Requires Node.js >=6.5.

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.
    -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("cpx");

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

More Repositories

1

npm-run-all

A CLI tool to run multiple npm-scripts in parallel or sequential.
JavaScript
5,679
star
2

eslint-plugin-node

Additional ESLint's rules for Node.js
JavaScript
958
star
3

eslint-plugin-eslint-comments

Additional ESLint rules for directive comments of ESLint.
JavaScript
359
star
4

abort-controller

An implementation of WHATWG AbortController interface.
TypeScript
301
star
5

regexpp

The regular expression parser for ECMAScript.
TypeScript
150
star
6

event-target-shim

An implementation of WHATWG EventTarget interface, plus few extensions.
TypeScript
123
star
7

eslint-plugin-es

ESLint plugin about ECMAScript syntactic features.
JavaScript
106
star
8

eslint-plugin-vue-trial

Experimental ESLint plugin for Vue.js.
JavaScript
90
star
9

eslint-utils

Utilities for ESLint plugins and custom rules.
JavaScript
74
star
10

eslint-gitignore

A utility for ESLint respecting `.gitignore` files.
TypeScript
39
star
11

eslint4b

ESLint which works in browsers.
JavaScript
37
star
12

vue-eslint-editor

A code editor component to play ESLint.
Vue
35
star
13

vue-eslint-demo

The online demo to check `eslint-plugin-vue`.
JavaScript
31
star
14

react-helix

A small library for immutable design and React.
JavaScript
26
star
15

appcache-manifest

A CLI tool to generate HTML5 Application Cache Manifest.
JavaScript
26
star
16

eslint-plugin

ESLint configurations and additional rules for me
JavaScript
25
star
17

eslint-plugin-dprint

An ESLint plugin that fixes code with dprint
TypeScript
24
star
18

template-eslint-plugin

A repository template for ESLint plugins.
JavaScript
17
star
19

if-node-version

Run a shell command if it's on the node of specified versions.
JavaScript
14
star
20

eslint-plugin-ja

ESLint ใฎใ‚จใƒฉใƒผใƒกใƒƒใ‚ปใƒผใ‚ธใ‚’ๆ—ฅๆœฌ่ชžๅŒ–ใ™ใ‚‹้žๅ…ฌๅผใฎๅฎŸ้จ“็š„ใชใƒ—ใƒฉใ‚ฐใ‚คใƒณใงใ™ใ€‚
JavaScript
12
star
21

bre

A Binary-Object Mapper for JavaScript
TypeScript
10
star
22

eaw

The Node.js module to calculate the width of east Asian characters.
JavaScript
10
star
23

eslint-config

Shareable configurations of ESLint for me.
JavaScript
8
star
24

eslint-evaluating-issues

ESLint evaluating feature issues
JavaScript
8
star
25

spy

Just a spy library.
TypeScript
8
star
26

uptodate

A CLI tool to update dependencies in your package.json.
JavaScript
7
star
27

validia

An object validator library that is TypeScript friendly
TypeScript
7
star
28

eslint-ast

The Extensible Type Definition of ESLint AST
TypeScript
6
star
29

Yammer-for-Developers

[Chrome Extension] The code formater and highlighter in Yammer's messages.
JavaScript
5
star
30

typescript-eslint-demo

A playground for @typescript-eslint.
JavaScript
4
star
31

mocha-assert-snapshot

Snapshot test utilities for Mocha.
TypeScript
4
star
32

warun

CLI tool which does Watch and Run.
JavaScript
4
star
33

type-tester

A tester to check expected type errors
TypeScript
4
star
34

eslint-custom-rule-tutorial

JavaScript
3
star
35

event-source-shim

An implementation for `EventSource` of Server-sent events standard.
TypeScript
2
star
36

run-all

CLI tool to execute multiple commands parallelly.
JavaScript
2
star
37

eslint-plugin-utils

Tools to maintain ESLint plugins
2
star
38

react-helix-examples

Examples for react-helix library.
JavaScript
2
star
39

github-actions-sandbox

JavaScript
2
star
40

hetemel

A HTML parser to make AST which fits for linting.
1
star
41

tools

My tools
TypeScript
1
star
42

fs-watcher

Lightweight file system watchers.
TypeScript
1
star
43

webkit-test

HTML
1
star
44

simple-vue-app

A CLI command to build a simple Vue.js SPA with almost no configuration.
JavaScript
1
star
45

.github

1
star
46

ajx

Simple fetch library for me.
JavaScript
1
star
47

string-replace-unexpected-behavior

Is this a bug?
JavaScript
1
star