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.

127 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 a ordinary file `from` to destination `to`. Uses
  38. `fs-write-stream-atomic` to ensure that the file is entirely copied or not
  39. 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 on Windows then if
  51. symlinking fails, a junction will be used instead.
  52. Options are:
  53. * top - The top level the copy is being run from. This is used to determine
  54. if the symlink destination is within the set of files we're copying or
  55. outside it.
  56. * fs - (Default: `require('fs')`) The filesystem module to use. Can be used
  57. to use `graceful-fs` or to inject a mock.
  58. * Promise - (Default: `global.Promise`) The promise implementation to use, defaults to Node's.
  59. * isWindows - (Default: `process.platform === 'win32'`) If true enables Windows symlink semantics. This requires
  60. an extra `stat` to determine if the destination of a symlink is a file or directory. If symlinking a directory
  61. fails then we'll try making a junction instead.
  62. ### copy.recurse(from, to, options) → Promise
  63. Reads all of the files in directory `from` and adds them to the `queue`
  64. using `recurseWith` (by default `copy.item`).
  65. Options are:
  66. * queue - A [`run-queue`](https://npmjs.com/package/run-queue) object to add files found inside `from` to.
  67. * recurseWith - (Default: `copy.item`) The function to call on each file after recursing into a directory.
  68. * uid, gid - (Optional) If `getuid()` is `0` then this and gid will be used to
  69. set the user and group of `to`. If uid is present then gid must be too.
  70. * mode - (Optional) If set then `to` will have its perms set to `mode`.
  71. * fs - (Default: `require('fs')`) The filesystem module to use. Can be used
  72. to use `graceful-fs` or to inject a mock.
  73. * getuid - (Default: `process.getuid`) A function that returns the current UID. Used to inject a mock.
  74. ### copy.item(from, to, options) → Promise
  75. Copies some kind of `from` to destination `to`. This looks at the filetype
  76. and calls `copy.file`, `copy.symlink` or `copy.recurse` as appropriate.
  77. Symlink copies are queued with a priority such that they happen after all
  78. file and directory copies as you can't create a junction on windows to a
  79. file that doesn't exist yet.
  80. Options are:
  81. * top - The top level the copy is being run from. This is used to determine
  82. if the symlink destination is within the set of files we're copying or
  83. outside it.
  84. * queue - The [`run-queue`](https://npmjs.com/package/run-queue) object to
  85. pass to `copy.recurse` if `from` is a directory.
  86. * recurseWith - (Default: `copy.item`) The function to call on each file after recursing into a directory.
  87. * uid, gid - (Optional) If `getuid()` is `0` then this and gid will be used to
  88. set the user and group of `to`. If uid is present then gid must be too.
  89. * mode - (Optional) If set then `to` will have its perms set to `mode`.
  90. * fs - (Default: `require('fs')`) The filesystem module to use. Can be used
  91. to use `graceful-fs` or to inject a mock.
  92. * getuid - (Default: `process.getuid`) A function that returns the current UID. Used to inject a mock.
  93. * isWindows - (Default: `process.platform === 'win32'`) If true enables Windows symlink semantics. This requires
  94. an extra `stat` to determine if the destination of a symlink is a file or directory. If symlinking a directory
  95. fails then we'll try making a junction instead.
  96. * Promise - (Default: `global.Promise`) The promise implementation to use, defaults to Node's.
  97. * writeStreamAtomic - (Default `require('fs-write-stream-atomic')`) The
  98. implementation of `writeStreamAtomic` to use. Used to inject a mock.