Giter VIP home page Giter VIP logo

cpx's Introduction

cpx

npm version Downloads/month Build Status Dependency Status

Copy file globs, watching for changes.

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

Installation

npm install cpx

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
    -t, --transform <name>    A module name to transform each file. cpx lookups
                                the specified name via "require()".
    -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} -- A flag to remove files that copied on past before copy.
    • options.dereference {boolean} -- A flag to follow symbolic links when copying from them.
    • options.transform {((filepath: string) => stream.Transform)[]} -- Functions that creates a stream.Transform object to transform each copying file.
  • 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-raedy", () => { ... }) : Be fired when started watching files, after the first copying.
  • .on("watch-error", (err) => { ... }) : Be fired when occured errors during watching.

cpx's People

Contributors

mysticatea avatar k88hudson avatar

Watchers

Sam Jeffress avatar

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.