From 4da17fed5f32f971862bdb21c6a8ec068bfa809b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Peer=20St=C3=B6cklmair?= Date: Thu, 9 Aug 2018 20:07:01 +0200 Subject: [PATCH 1/2] Chore: github issue template (#617) * Chore: github issue template * Docs: typoe --- .github/issue_template.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/issue_template.md b/.github/issue_template.md index e3d10ebd..80d6921a 100644 --- a/.github/issue_template.md +++ b/.github/issue_template.md @@ -1,4 +1,5 @@ - + + - **Operating System:** - **Node.js version:** - **`fs-extra` version:** From 402c1d05727f2f9414a4905ffa75f4fa1d99461c Mon Sep 17 00:00:00 2001 From: robertjacobson Date: Sat, 11 Aug 2018 15:08:20 -0500 Subject: [PATCH 2/2] Show support for mode (#587) Node fs's mkdir supports mode specification. After reviewing the source fs-extra does as well, but is not documented. Update the documentation to include the `options` parameter and provide a few examples of using `mode`. --- docs/ensureDir-sync.md | 18 +++++++++++++++--- docs/ensureDir.md | 34 ++++++++++++++++++++++++++++++++-- 2 files changed, 47 insertions(+), 5 deletions(-) diff --git a/docs/ensureDir-sync.md b/docs/ensureDir-sync.md index 8f083d27..e03d37bc 100644 --- a/docs/ensureDir-sync.md +++ b/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` `` - +- `options` `|` ## 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 ``` diff --git a/docs/ensureDir.md b/docs/ensureDir.md index 0d43a145..85e9392d 100644 --- a/docs/ensureDir.md +++ b/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` `` +- `options` `|` - `callback` `` ## Example: @@ -13,6 +14,10 @@ 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 => { @@ -20,6 +25,12 @@ fs.ensureDir(dir, err => { // 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(() => { @@ -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 { @@ -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) ```