index.js 845 B

1234567891011121314151617181920212223242526272829303132333435
  1. "use strict"
  2. const fsExtra = require("fs-extra")
  3. const Promise = require('bluebird-lst')
  4. function makeFs(Promise) {
  5. const fs = Object.create(null)
  6. for (const methodName of Object.keys(fsExtra)) {
  7. const method = fsExtra[methodName]
  8. if (methodName === "createFile" || methodName === "mkdirp") {
  9. continue
  10. }
  11. if (typeof method !== "function" ||
  12. methodName.endsWith("Sync") ||
  13. methodName.endsWith("Stream") ||
  14. methodName.match(/^[A-Z]/) ||
  15. methodName === "exists" ||
  16. methodName === "watch" ||
  17. methodName === "watchFile" ||
  18. methodName === "unwatchFile") {
  19. fs[methodName] = method
  20. }
  21. else {
  22. fs[methodName] = Promise.promisify(method)
  23. }
  24. }
  25. fs.createFile = fs.ensureFile
  26. fs.mkdirp = fs.mkdirs
  27. return fs
  28. }
  29. module.exports = makeFs(Promise)