Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds separator and eol to filesystem + documentation. #50

Merged
merged 1 commit into from
Dec 9, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 93 additions & 1 deletion docs/context-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -255,9 +255,101 @@ Call `context.prompt.separator()` to return a separator you can use in some of y
A pre-built prompt which asks the user if they would like to overwrite a file. The first parameter
to this function is `message` which can be customized to what you need. The function returns `boolean`.



# context.filesystem

Honestly, the `fs-jetpack` API is so well done, let's just drop that here. Provide examples.
A set of functions & values to work with files and directories. The majority of these functions come
straight from [fs-jetpack](https://github.com/szwacz/fs-jetpack), a fantastic API for working with the
file system. All jetpack-based functions have an equivalent `*Async` version if you need it.

### context.filesystem.separator

This value is the path separator `\` or `/` depending on the OS.

```js
context.filesystem.seperator // '/' on posix but '\' on windows
```

### context.filesystem.eol

This value is the end of line byte sequence.

```js
context.filesystem.eol // '\n' on posix but '\r\n' on windows
```

### context.filesystem.append

[Appends](https://github.com/szwacz/fs-jetpack#appendpath-data-options) data to the end of a file.

### context.filesystem.copy

[Copies](https://github.com/szwacz/fs-jetpack#copyfrom-to-options) a file or a directory.

### context.filesystem.cwd

Gets the [current working directory](https://github.com/szwacz/fs-jetpack#createreadstreampath-options).

### context.filesystem.dir

[Ensures a directory exists](https://github.com/szwacz/fs-jetpack#dirpath-criteria) and creates a new jetpack
instance with it's `cwd` pointing there.

### context.filesystem.exists

Checks to see if file or directory [exists](https://github.com/szwacz/fs-jetpack#existspath).

### context.filesystem.file

[Ensures a file exists](https://github.com/szwacz/fs-jetpack#filepath-criteria).

### context.filesystem.find

[Finds](https://github.com/szwacz/fs-jetpack#findpath-searchoptions) files or directories.

### context.filesystem.inspect

[Grabs information](https://github.com/szwacz/fs-jetpack#inspectpath-options) about a file or directory.

### context.filesystem.inspectTree

[Grabs nested information](https://github.com/szwacz/fs-jetpack#inspecttreepath-options) about a set of files or directories.

### context.filesystem.list

[Gets a directory listing](https://github.com/szwacz/fs-jetpack#listpath), like `ls`.

### context.filesystem.move

[Moves](https://github.com/szwacz/fs-jetpack#movefrom-to) files and directories.

### context.filesystem.path

[Grabs path parts](https://github.com/szwacz/fs-jetpack#pathparts) as a string.

### context.filesystem.read

[Reads](https://github.com/szwacz/fs-jetpack#readpath-returnas) the contents of a file as a string or JSON.

### context.filesystem.remove

[Deletes](https://github.com/szwacz/fs-jetpack#removepath) a file or directory.

### context.filesystem.rename

[Renames](https://github.com/szwacz/fs-jetpack#renamepath-newname) a file or directory.

### context.filesystem.symlink

[Makes a symbolic link](https://github.com/szwacz/fs-jetpack#symlinksymlinkvalue-path) to a file or directory.

### context.filesystem.write

[Writes](https://github.com/szwacz/fs-jetpack#writepath-data-options) data to a file.




# context.system

Expand Down
15 changes: 9 additions & 6 deletions packages/gluegun/src/extensions/filesystem-extension.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
const jetpack = require('fs-jetpack')
const os = require('os')
const path = require('path')

/**
* Extensions to filesystem. Brought to you by fs-jetpack.
*
* @param {Plugin} plugin The plugin that triggered.
* @param {Command} command The current command that is running.
* @param {RunContext} context The running context.
* @return {Function} A function to attach to the context.
* @return {Function} A function to attach to the context.
*/
function attach (plugin, command, context) {
return jetpack
function attach () {
const extension = jetpack // jetpack
extension.eol = os.EOL // end of line marker
extension.separator = path.sep // path separator

return extension
}

module.exports = attach
17 changes: 17 additions & 0 deletions packages/gluegun/test/extensions/filesystem-extension.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const test = require('ava')
const createExtension = require('../../src/extensions/filesystem-extension')
const os = require('os')
const path = require('path')
const { split } = require('ramda')

test('has the proper interface', t => {
const ext = createExtension()
t.truthy(ext)
// a few dumb checks to ensure we're talking to jetpack
t.is(typeof ext.copy, 'function')
t.is(typeof ext.path, 'function')
t.is(split('\n', ext.read(__filename))[0], 'const test = require(\'ava\')')
// the extra values we've added
t.is(ext.eol, os.EOL)
t.is(ext.separator, path.sep)
})