Skip to content

Commit

Permalink
feat(file-system): add ability to create directories
Browse files Browse the repository at this point in the history
  • Loading branch information
Raphaël Benitte authored and Raphaël Benitte committed Jul 19, 2017
1 parent 0e965fc commit 0b176bb
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 7 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,6 @@ jspm_packages
.DS_Store
.idea
bin
_doc
_doc
/examples/features/file_system/files/generated
/examples/features/file_system/files/deeply
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -713,7 +713,7 @@ fileSystem.install(defineSupportCode)

```yaml
Given:
# No definitions
- /^(?:I )?create directory (.+)$/

When:
# No definitions
Expand Down
12 changes: 11 additions & 1 deletion examples/features/file_system/file_system.feature
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,14 @@ Feature: File system extension

Scenario: Checking directory does not exist
Given I set cwd to examples/features/file_system/files
Then directory crap_dir should not exist
Then directory crap_dir should not exist

Scenario: Creating a directory
Given I set cwd to examples/features/file_system/files
And I create directory generated
Then directory generated should exist

Scenario: Creating nested directory
Given I set cwd to examples/features/file_system/files
And I create directory deeply/nested/directory
Then directory deeply/nested/directory should exist
19 changes: 17 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"engineStrict": true,
"dependencies": {
"chai": "^4.0.2",
"fs-extra": "^4.0.0",
"glob": "^7.1.2",
"js-yaml": "^3.8.4",
"lodash": "^4.17.4",
Expand Down Expand Up @@ -90,10 +91,24 @@
},
"config": {
"validate-commit-msg": {
"types": ["feat", "fix", "docs", "style", "refactor", "perf", "test", "build", "ci", "chore", "revert"],
"types": [
"feat",
"fix",
"docs",
"style",
"refactor",
"perf",
"test",
"build",
"ci",
"chore",
"revert"
],
"scope": {
"required": false,
"allowed": ["*"],
"allowed": [
"*"
],
"validate": false,
"multiple": false
},
Expand Down
9 changes: 8 additions & 1 deletion src/extensions/file_system/definitions.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@

const { expect } = require('chai')

module.exports = ({ Then }) => {
module.exports = ({ Given, Then }) => {
/**
* Creating a directory.
*/
Given(/^(?:I )?create directory (.+)$/, function(directory) {
return this.fileSystem.createDirectory(this.cli.getCwd(), directory)
})

/**
* Checking file/directory presence.
*/
Expand Down
23 changes: 22 additions & 1 deletion src/extensions/file_system/file_system.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
'use strict'

/**
* The FileSystem helper used by the FileSystem extension.
*
* @module extensions/FileSystem/FileSystem
*/

const path = require('path')
const fs = require('fs')
const fs = require('fs-extra')

/**
* Loads file content.
Expand Down Expand Up @@ -37,3 +43,18 @@ exports.getFileInfo = (cwd, file) =>
resolve(stat)
})
})

/**
* Creates a directory.
*
* @param {string} cwd - Current Working Directory
* @param {string} directory - Directory name
* @return {Promise.<boolean>}
*/
exports.createDirectory = (cwd, directory) =>
new Promise((resolve, reject) => {
fs.mkdirs(path.join(cwd, directory), err => {
if (err) return reject(err)
resolve(true)
})
})
8 changes: 8 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1142,6 +1142,14 @@ fs-extra@^3.0.1:
jsonfile "^3.0.0"
universalify "^0.1.0"

fs-extra@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-4.0.0.tgz#414fb4ca2d2170ba0014159d3a8aec3303418d9e"
dependencies:
graceful-fs "^4.1.2"
jsonfile "^3.0.0"
universalify "^0.1.0"

fs.realpath@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/fs.realpath/-/fs.realpath-1.0.0.tgz#1504ad2523158caa40db4a2787cb01411994ea4f"
Expand Down

0 comments on commit 0b176bb

Please sign in to comment.