Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
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.

readme.markdown 8.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. # mkdirp
  2. Like `mkdir -p`, but in Node.js!
  3. Now with a modern API and no\* bugs!
  4. <small>\* may contain some bugs</small>
  5. # example
  6. ## pow.js
  7. ```js
  8. const mkdirp = require('mkdirp')
  9. // return value is a Promise resolving to the first directory created
  10. mkdirp('/tmp/foo/bar/baz').then(made =>
  11. console.log(`made directories, starting with ${made}`))
  12. ```
  13. Output (where `/tmp/foo` already exists)
  14. ```
  15. made directories, starting with /tmp/foo/bar
  16. ```
  17. Or, if you don't have time to wait around for promises:
  18. ```js
  19. const mkdirp = require('mkdirp')
  20. // return value is the first directory created
  21. const made = mkdirp.sync('/tmp/foo/bar/baz')
  22. console.log(`made directories, starting with ${made}`)
  23. ```
  24. And now /tmp/foo/bar/baz exists, huzzah!
  25. # methods
  26. ```js
  27. const mkdirp = require('mkdirp')
  28. ```
  29. ## mkdirp(dir, [opts]) -> Promise<String | undefined>
  30. Create a new directory and any necessary subdirectories at `dir` with octal
  31. permission string `opts.mode`. If `opts` is a string or number, it will be
  32. treated as the `opts.mode`.
  33. If `opts.mode` isn't specified, it defaults to `0o777 &
  34. (~process.umask())`.
  35. Promise resolves to first directory `made` that had to be created, or
  36. `undefined` if everything already exists. Promise rejects if any errors
  37. are encountered. Note that, in the case of promise rejection, some
  38. directories _may_ have been created, as recursive directory creation is not
  39. an atomic operation.
  40. You can optionally pass in an alternate `fs` implementation by passing in
  41. `opts.fs`. Your implementation should have `opts.fs.mkdir(path, opts, cb)`
  42. and `opts.fs.stat(path, cb)`.
  43. You can also override just one or the other of `mkdir` and `stat` by
  44. passing in `opts.stat` or `opts.mkdir`, or providing an `fs` option that
  45. only overrides one of these.
  46. ## mkdirp.sync(dir, opts) -> String|null
  47. Synchronously create a new directory and any necessary subdirectories at
  48. `dir` with octal permission string `opts.mode`. If `opts` is a string or
  49. number, it will be treated as the `opts.mode`.
  50. If `opts.mode` isn't specified, it defaults to `0o777 &
  51. (~process.umask())`.
  52. Returns the first directory that had to be created, or undefined if
  53. everything already exists.
  54. You can optionally pass in an alternate `fs` implementation by passing in
  55. `opts.fs`. Your implementation should have `opts.fs.mkdirSync(path, mode)`
  56. and `opts.fs.statSync(path)`.
  57. You can also override just one or the other of `mkdirSync` and `statSync`
  58. by passing in `opts.statSync` or `opts.mkdirSync`, or providing an `fs`
  59. option that only overrides one of these.
  60. ## mkdirp.manual, mkdirp.manualSync
  61. Use the manual implementation (not the native one). This is the default
  62. when the native implementation is not available or the stat/mkdir
  63. implementation is overridden.
  64. ## mkdirp.native, mkdirp.nativeSync
  65. Use the native implementation (not the manual one). This is the default
  66. when the native implementation is available and stat/mkdir are not
  67. overridden.
  68. # implementation
  69. On Node.js v10.12.0 and above, use the native `fs.mkdir(p,
  70. {recursive:true})` option, unless `fs.mkdir`/`fs.mkdirSync` has been
  71. overridden by an option.
  72. ## native implementation
  73. - If the path is a root directory, then pass it to the underlying
  74. implementation and return the result/error. (In this case, it'll either
  75. succeed or fail, but we aren't actually creating any dirs.)
  76. - Walk up the path statting each directory, to find the first path that
  77. will be created, `made`.
  78. - Call `fs.mkdir(path, { recursive: true })` (or `fs.mkdirSync`)
  79. - If error, raise it to the caller.
  80. - Return `made`.
  81. ## manual implementation
  82. - Call underlying `fs.mkdir` implementation, with `recursive: false`
  83. - If error:
  84. - If path is a root directory, raise to the caller and do not handle it
  85. - If ENOENT, mkdirp parent dir, store result as `made`
  86. - stat(path)
  87. - If error, raise original `mkdir` error
  88. - If directory, return `made`
  89. - Else, raise original `mkdir` error
  90. - else
  91. - return `undefined` if a root dir, or `made` if set, or `path`
  92. ## windows vs unix caveat
  93. On Windows file systems, attempts to create a root directory (ie, a drive
  94. letter or root UNC path) will fail. If the root directory exists, then it
  95. will fail with `EPERM`. If the root directory does not exist, then it will
  96. fail with `ENOENT`.
  97. On posix file systems, attempts to create a root directory (in recursive
  98. mode) will succeed silently, as it is treated like just another directory
  99. that already exists. (In non-recursive mode, of course, it fails with
  100. `EEXIST`.)
  101. In order to preserve this system-specific behavior (and because it's not as
  102. if we can create the parent of a root directory anyway), attempts to create
  103. a root directory are passed directly to the `fs` implementation, and any
  104. errors encountered are not handled.
  105. ## native error caveat
  106. The native implementation (as of at least Node.js v13.4.0) does not provide
  107. appropriate errors in some cases (see
  108. [nodejs/node#31481](https://github.com/nodejs/node/issues/31481) and
  109. [nodejs/node#28015](https://github.com/nodejs/node/issues/28015)).
  110. In order to work around this issue, the native implementation will fall
  111. back to the manual implementation if an `ENOENT` error is encountered.
  112. # choosing a recursive mkdir implementation
  113. There are a few to choose from! Use the one that suits your needs best :D
  114. ## use `fs.mkdir(path, {recursive: true}, cb)` if:
  115. - You wish to optimize performance even at the expense of other factors.
  116. - You don't need to know the first dir created.
  117. - You are ok with getting `ENOENT` as the error when some other problem is
  118. the actual cause.
  119. - You can limit your platforms to Node.js v10.12 and above.
  120. - You're ok with using callbacks instead of promises.
  121. - You don't need/want a CLI.
  122. - You don't need to override the `fs` methods in use.
  123. ## use this module (mkdirp 1.x) if:
  124. - You need to know the first directory that was created.
  125. - You wish to use the native implementation if available, but fall back
  126. when it's not.
  127. - You prefer promise-returning APIs to callback-taking APIs.
  128. - You want more useful error messages than the native recursive mkdir
  129. provides (at least as of Node.js v13.4), and are ok with re-trying on
  130. `ENOENT` to achieve this.
  131. - You need (or at least, are ok with) a CLI.
  132. - You need to override the `fs` methods in use.
  133. ## use [`make-dir`](http://npm.im/make-dir) if:
  134. - You do not need to know the first dir created (and wish to save a few
  135. `stat` calls when using the native implementation for this reason).
  136. - You wish to use the native implementation if available, but fall back
  137. when it's not.
  138. - You prefer promise-returning APIs to callback-taking APIs.
  139. - You are ok with occasionally getting `ENOENT` errors for failures that
  140. are actually related to something other than a missing file system entry.
  141. - You don't need/want a CLI.
  142. - You need to override the `fs` methods in use.
  143. ## use mkdirp 0.x if:
  144. - You need to know the first directory that was created.
  145. - You need (or at least, are ok with) a CLI.
  146. - You need to override the `fs` methods in use.
  147. - You're ok with using callbacks instead of promises.
  148. - You are not running on Windows, where the root-level ENOENT errors can
  149. lead to infinite regress.
  150. - You think vinyl just sounds warmer and richer for some weird reason.
  151. - You are supporting truly ancient Node.js versions, before even the advent
  152. of a `Promise` language primitive. (Please don't. You deserve better.)
  153. # cli
  154. This package also ships with a `mkdirp` command.
  155. ```
  156. $ mkdirp -h
  157. usage: mkdirp [DIR1,DIR2..] {OPTIONS}
  158. Create each supplied directory including any necessary parent directories
  159. that don't yet exist.
  160. If the directory already exists, do nothing.
  161. OPTIONS are:
  162. -m<mode> If a directory needs to be created, set the mode as an octal
  163. --mode=<mode> permission string.
  164. -v --version Print the mkdirp version number
  165. -h --help Print this helpful banner
  166. -p --print Print the first directories created for each path provided
  167. --manual Use manual implementation, even if native is available
  168. ```
  169. # install
  170. With [npm](http://npmjs.org) do:
  171. ```
  172. npm install mkdirp
  173. ```
  174. to get the library locally, or
  175. ```
  176. npm install -g mkdirp
  177. ```
  178. to get the command everywhere, or
  179. ```
  180. npx mkdirp ...
  181. ```
  182. to run the command without installing it globally.
  183. # platform support
  184. This module works on node v8, but only v10 and above are officially
  185. supported, as Node v8 reached its LTS end of life 2020-01-01, which is in
  186. the past, as of this writing.
  187. # license
  188. MIT