make-dir.js 545 B

123456789101112131415161718192021222324252627
  1. 'use strict'
  2. const fs = require('../fs')
  3. const { checkPath } = require('./utils')
  4. const getMode = options => {
  5. const defaults = { mode: 0o777 }
  6. if (typeof options === 'number') return options
  7. return ({ ...defaults, ...options }).mode
  8. }
  9. module.exports.makeDir = async (dir, options) => {
  10. checkPath(dir)
  11. return fs.mkdir(dir, {
  12. mode: getMode(options),
  13. recursive: true
  14. })
  15. }
  16. module.exports.makeDirSync = (dir, options) => {
  17. checkPath(dir)
  18. return fs.mkdirSync(dir, {
  19. mode: getMode(options),
  20. recursive: true
  21. })
  22. }