You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

128 lines
6.0 KiB

4 years ago
  1. # copy-concurrently
  2. Copy files, directories and symlinks
  3. ```
  4. const copy = require('copy-concurrently')
  5. copy('/path/to/thing', '/new/path/thing').then(() => {
  6. // this is now copied
  7. }).catch(err => {
  8. // oh noooo
  9. })
  10. ```
  11. Copies files, directories and symlinks. Ownership is maintained when
  12. running as root, permissions are always maintained. On Windows, if symlinks
  13. are unavailable then junctions will be used.
  14. ## PUBLIC INTERFACE
  15. ### copy(from, to, [options]) → Promise
  16. Recursively copies `from` to `to` and resolves its promise when finished.
  17. If `to` already exists then the promise will be rejected with an `EEXIST`
  18. error.
  19. Options are:
  20. * maxConcurrency – (Default: `1`) The maximum number of concurrent copies to do at once.
  21. * recurseWith - (Default: `copy.item`) The function to call on each file after recursing into a directory.
  22. * isWindows - (Default: `process.platform === 'win32'`) If true enables Windows symlink semantics. This requires
  23. an extra `stat` to determine if the destination of a symlink is a file or directory. If symlinking a directory
  24. fails then we'll try making a junction instead.
  25. Options can also include dependency injection:
  26. * Promise - (Default: `global.Promise`) The promise implementation to use, defaults to Node's.
  27. * fs - (Default: `require('fs')`) The filesystem module to use. Can be used
  28. to use `graceful-fs` or to inject a mock.
  29. * writeStreamAtomic - (Default: `require('fs-write-stream-atomic')`) The
  30. implementation of `writeStreamAtomic` to use. Used to inject a mock.
  31. * getuid - (Default: `process.getuid`) A function that returns the current UID. Used to inject a mock.
  32. ## EXTENSION INTERFACE
  33. Ordinarily you'd only call `copy` above. But it's possible to use it's
  34. component functions directly. This is useful if, say, you're writing
  35. [move-concurently](https://npmjs.com/package/move-concurrently).
  36. ### copy.file(from, to, options) → Promise
  37. Copies an ordinary file `from` to destination `to`. Uses
  38. `fs-write-stream-atomic` to ensure that the file is either entirely copied
  39. or not at all.
  40. Options are:
  41. * uid, gid - (Optional) If `getuid()` is `0` then this and gid will be used to
  42. set the user and group of `to`. If uid is present then gid must be too.
  43. * mode - (Optional) If set then `to` will have its perms set to `mode`.
  44. * fs - (Default: `require('fs')`) The filesystem module to use. Can be used
  45. to use `graceful-fs` or to inject a mock.
  46. * Promise - (Default: `global.Promise`) The promise implementation to use, defaults to Node's.
  47. * writeStreamAtomic - (Default `require('fs-write-stream-atomic')`) The
  48. implementation of `writeStreamAtomic` to use. Used to inject a mock.
  49. ### copy.symlink(from, to, options) → Promise
  50. Copies a symlink `from` to destination `to`. If you're using Windows and
  51. symlinking fails and what you're linking is a directory then junctions will
  52. be tried instead.
  53. Options are:
  54. * top - The top level the copy is being run from. This is used to determine
  55. if the symlink destination is within the set of files we're copying or
  56. outside it.
  57. * fs - (Default: `require('fs')`) The filesystem module to use. Can be used
  58. to use `graceful-fs` or to inject a mock.
  59. * Promise - (Default: `global.Promise`) The promise implementation to use, defaults to Node's.
  60. * isWindows - (Default: `process.platform === 'win32'`) If true enables Windows symlink semantics. This requires
  61. an extra `stat` to determine if the destination of a symlink is a file or directory. If symlinking a directory
  62. fails then we'll try making a junction instead.
  63. ### copy.recurse(from, to, options) → Promise
  64. Reads all of the files in directory `from` and adds them to the `queue`
  65. using `recurseWith` (by default `copy.item`).
  66. Options are:
  67. * queue - A [`run-queue`](https://npmjs.com/package/run-queue) object to add files found inside `from` to.
  68. * recurseWith - (Default: `copy.item`) The function to call on each file after recursing into a directory.
  69. * uid, gid - (Optional) If `getuid()` is `0` then this and gid will be used to
  70. set the user and group of `to`. If uid is present then gid must be too.
  71. * mode - (Optional) If set then `to` will have its perms set to `mode`.
  72. * fs - (Default: `require('fs')`) The filesystem module to use. Can be used
  73. to use `graceful-fs` or to inject a mock.
  74. * getuid - (Default: `process.getuid`) A function that returns the current UID. Used to inject a mock.
  75. ### copy.item(from, to, options) → Promise
  76. Copies some kind of `from` to destination `to`. This looks at the filetype
  77. and calls `copy.file`, `copy.symlink` or `copy.recurse` as appropriate.
  78. Symlink copies are queued with a priority such that they happen after all
  79. file and directory copies as you can't create a junction on windows to a
  80. file that doesn't exist yet.
  81. Options are:
  82. * top - The top level the copy is being run from. This is used to determine
  83. if the symlink destination is within the set of files we're copying or
  84. outside it.
  85. * queue - The [`run-queue`](https://npmjs.com/package/run-queue) object to
  86. pass to `copy.recurse` if `from` is a directory.
  87. * recurseWith - (Default: `copy.item`) The function to call on each file after recursing into a directory.
  88. * uid, gid - (Optional) If `getuid()` is `0` then this and gid will be used to
  89. set the user and group of `to`. If uid is present then gid must be too.
  90. * mode - (Optional) If set then `to` will have its perms set to `mode`.
  91. * fs - (Default: `require('fs')`) The filesystem module to use. Can be used
  92. to use `graceful-fs` or to inject a mock.
  93. * getuid - (Default: `process.getuid`) A function that returns the current UID. Used to inject a mock.
  94. * isWindows - (Default: `process.platform === 'win32'`) If true enables Windows symlink semantics. This requires
  95. an extra `stat` to determine if the destination of a symlink is a file or directory. If symlinking a directory
  96. fails then we'll try making a junction instead.
  97. * Promise - (Default: `global.Promise`) The promise implementation to use, defaults to Node's.
  98. * writeStreamAtomic - (Default `require('fs-write-stream-atomic')`) The
  99. implementation of `writeStreamAtomic` to use. Used to inject a mock.