Skip to content

Commit

Permalink
Merge branch 'master' into v8-dev
Browse files Browse the repository at this point in the history
  • Loading branch information
manidlou committed Aug 12, 2018
2 parents e5cbdc4 + 402c1d0 commit 1657c61
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 6 deletions.
3 changes: 2 additions & 1 deletion .github/issue_template.md
@@ -1,4 +1,5 @@
<!-- Please fill out the following information if it applies to your issue: -->
<!-- First ensure you installed the latest version of fs-extra -->
<!-- If your bug still exists please fill out the following information if it applies to your issue: -->
- **Operating System:**
- **Node.js version:**
- **`fs-extra` version:**
18 changes: 15 additions & 3 deletions docs/ensureDir-sync.md
@@ -1,17 +1,29 @@
# ensureDirSync(dir)
# ensureDirSync(dir[,options])

Ensures that the directory exists. If the directory structure does not exist, it is created. Like `mkdir -p`.
Ensures that the directory exists. If the directory structure does not exist, it is created. Like `mkdir -p`. If provided, options may specify the desired mode for the directory.

**Aliases:** `mkdirsSync()`, `mkdirpSync()`

- `dir` `<String>`

- `options` `<Integer>|<Object>`
## Example:

```js
const fs = require('fs-extra')

const dir = '/tmp/this/path/does/not/exist'

const desiredMode = 0o2775
const options = {
mode: 0o2775
}

fs.ensureDirSync(dir)
// dir has now been created, including the directory it is to be placed in

fs.ensureDirSync(dir, desiredMod)
// dir has now been created, including the directory it is to be placed in with permission 0o2775

fs.ensureDirSync(dir, options)
// dir has now been created, including the directory it is to be placed in with permission 0o2775
```
34 changes: 32 additions & 2 deletions docs/ensureDir.md
@@ -1,10 +1,11 @@
# ensureDir(dir[, callback])
# ensureDir(dir[,options][,callback])

Ensures that the directory exists. If the directory structure does not exist, it is created. Like `mkdir -p`.

**Aliases:** `mkdirs()`, `mkdirp()`

- `dir` `<String>`
- `options` `<Integer>|<Object>`
- `callback` `<Function>`

## Example:
Expand All @@ -13,13 +14,23 @@ Ensures that the directory exists. If the directory structure does not exist, it
const fs = require('fs-extra')

const dir = '/tmp/this/path/does/not/exist'
const desiredMode = 0o2775
const options = {
mode: 0o2775
}

// With a callback:
fs.ensureDir(dir, err => {
console.log(err) // => null
// dir has now been created, including the directory it is to be placed in
})

// With a callback and a mode integer
fs.ensureDir(dir, desiredMode, err => {
console.log(err) // => null
// dir has now been created with mode 0o2775, including the directory it is to be placed in
})

// With Promises:
fs.ensureDir(dir)
.then(() => {
Expand All @@ -29,6 +40,15 @@ fs.ensureDir(dir)
console.error(err)
})

// With Promises and a mode integer:
fs.ensureDir(dir, desiredMode)
.then(() => {
console.log('success!')
})
.catch(err => {
console.error(err)
})

// With async/await:
async function example (directory) {
try {
Expand All @@ -38,6 +58,16 @@ async function example (directory) {
console.error(err)
}
}

example(dir)

// With async/await and an options object, containing mode:
async function exampleMode (directory) {
try {
await fs.ensureDir(directory, options)
console.log('success!')
} catch (err) {
console.error(err)
}
}
exampleMode(dir)
```

0 comments on commit 1657c61

Please sign in to comment.