function Cpx(source, outDir, options) { (0, _classCallCheck3.default)(this, Cpx); options = options || {}; // eslint-disable-line no-param-reassign var _this = (0, _possibleConstructorReturn3.default)(this, (0, _getPrototypeOf2.default)(Cpx).call(this)); _this[SOURCE] = normalizePath(source); _this[OUT_DIR] = normalizePath(outDir); _this[DEREFERENCE] = Boolean(options.dereference); _this[INCLUDE_EMPTY_DIRS] = Boolean(options.includeEmptyDirs); _this[INITIAL_COPY] = options.initialCopy === undefined || Boolean(options.initialCopy); _this[PRESERVE] = Boolean(options.preserve); _this[TRANSFORM] = [].concat(options.transform).filter(Boolean); _this[UPDATE] = Boolean(options.update); _this[QUEUE] = new Queue(); _this[BASE_DIR] = null; _this[WATCHER] = null; return _this; }
n/a
function copy(source, outDir) {
var options = arguments.length <= 2 || arguments[2] === undefined ? null : arguments[2];
var cb = arguments.length <= 3 || arguments[3] === undefined ? null : arguments[3];
if (typeof options === "function") {
/* eslint-disable no-param-reassign */
cb = options;
options = null;
/* eslint-enable no-param-reassign */
}
var cpx = new Cpx(source, outDir, options);
if (options && options.clean) {
cpx.clean(function (err) {
if (err == null) {
cpx.copy(cb);
} else if (cb != null) {
cb(err);
}
});
} else {
cpx.copy(cb);
}
return cpx;
}
...
```js
var cpx = require("cpx");
```
### 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`.
...
function copySync(source, outDir) { var options = arguments.length <= 2 || arguments[2] === undefined ? null : arguments[2]; var cpx = new Cpx(source, outDir, options); if (options && options.clean) { cpx.cleanSync(); } cpx.copySync(); }
...
- **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.
...
function watch(source, outDir) { var options = arguments.length <= 2 || arguments[2] === undefined ? null : arguments[2]; var cpx = new Cpx(source, outDir, options); if (options && options.clean) { cpx.clean(function (err) { if (err == null) { cpx.watch(); } else { cpx.emit("watch-error", err); } }); } else { cpx.watch(); } return cpx; }
...
- **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.
...