Skip to content

Commit

Permalink
New: --include-empty-dirs option
Browse files Browse the repository at this point in the history
  • Loading branch information
mysticatea committed Sep 4, 2016
1 parent 77b1627 commit 6324e50
Show file tree
Hide file tree
Showing 10 changed files with 341 additions and 65 deletions.
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,17 @@ Options:
-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
-h, --help Print usage information.
--include-empty-dirs The flag to copy empty directories which is
matched with the glob.
-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
-V, --version Print the version number.
-w, --watch Watch for files that matches <source>, and copy
the file to <dest> every changing.
```
Expand Down Expand Up @@ -101,6 +103,7 @@ cpx.copy(source, dest, callback)
- **options** `{object}`
- **options.clean** `{boolean}` -- The flag to remove files that copied on past before copy.
- **options.dereference** `{boolean}` -- The flag to follow symbolic links when copying from them.
- **options.includeEmptyDirs** `{boolean}` -- The flag to copy empty directories which is matched with the glob.
- **options.preserve** `{boolean}` -- The flag to copy uid, gid, atime, and mtime of files.
- **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.
Expand Down
2 changes: 2 additions & 0 deletions src/bin/help.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ Options:
<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.
-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
Expand Down
2 changes: 2 additions & 0 deletions src/bin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const OPTIONS = {
c: "command",
C: "clean",
h: "help",
includeEmptyDirs: "include-empty-dirs",
L: "dereference",
p: "preserve",
t: "transform",
Expand All @@ -30,6 +31,7 @@ const args = subarg(process.argv.slice(2), {
"clean",
"dereference",
"help",
"include-empty-dirs",
"preserve",
"update",
"verbose",
Expand Down
1 change: 1 addition & 0 deletions src/bin/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ module.exports = function main(source, outDir, args) {
{
transform: mergedTransformFactories,
dereference: args.dereference,
includeEmptyDirs: args.includeEmptyDirs,
preserve: args.preserve,
update: args.update,
}
Expand Down
8 changes: 7 additions & 1 deletion src/lib/copy-sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

const {Buffer} = require("safe-buffer")
const fs = require("fs")
const mkdirSync = require("mkdirp").sync
const MAX_BUFFER = 2048

/**
Expand Down Expand Up @@ -66,7 +67,12 @@ module.exports = function copySync(src, dst, {preserve, update}) {
}
}

copyBodySync(src, dst)
if (stat.isDirectory()) {
mkdirSync(dst)
}
else {
copyBodySync(src, dst)
}
fs.chmodSync(dst, stat.mode)

if (preserve) {
Expand Down
25 changes: 20 additions & 5 deletions src/lib/copy.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"use strict"

const fs = require("fs")
const mkdir = require("mkdirp")
const Queue = require("./queue")

/**
Expand Down Expand Up @@ -117,14 +118,28 @@ module.exports = function copy(
}))
}

q.push(next => copyBody(src, dst, transformFactories, (err) => {
if (err) {
cb(err)
q.push(next => {
if (stat.isDirectory()) {
mkdir(dst, (err) => {
if (err) {
cb(err)
}
else {
next()
}
})
}
else {
next()
copyBody(src, dst, transformFactories, (err) => {
if (err) {
cb(err)
}
else {
next()
}
})
}
}))
})
q.push(next => fs.chmod(dst, stat.mode, (err) => {
if (err) {
cb(err)
Expand Down
Loading

0 comments on commit 6324e50

Please sign in to comment.