Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 1,000,000+ packages pre-installed, including go-plugin-fs with all npm packages installed. Try it out:

var goPluginFs = require("go-plugin-fs")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

go-plugin-fs v1.0.2

Go plugin to work with file system

go-plugin-fs

npm Travis Coveralls Vulnerabilities js-standard-style

Go plugin to work with file system.

Table of Contents

Usage

$ npm install --save-dev go go-plugin-fs
import go from 'go'
import { FsPlugin } from 'go-plugin-fs'

go.use(FsPlugin)

go.copy('./path/to/source/file', './destination/path')

API

Methods

copy

go.copy( source, target [ , options, callback ]): Promise<void>
go.copySync( source, target [ , options ]): void

Copies file or directory to the target destination (it creates missing directories automatically). Read more about fs-extra copy and copySync.

move

go.move( source, target [ , options, callback ]): Promive<void>
go.moveSync( source, target [ , options ]): void

Moves file or directory to the target destination (it creates missing directories automatically). Read more about fs-extra move and moveSync.

remove

go.remove( path [ , callback ]): Promise<void>
go.removeSync( path ): void

Removes file or directory. Read more about fs-extra remove and removeSync.

writeFile

go.writeFile( path, data [ , options, callback ]): Promise<void>
go.writeFileSync( path, data [ , options ]): void

Creates or rewrites the file with given content. Read more about fs-extra outputFile and outputFileSync.

readFile

go.readFile( path [ , options, callback ]): Promise<void>
go.readFileSync( path [ , options ]): void

Reads the content from the given file. Read more about NodeJS readFile and readFileSync.

createDir

go.createDir( path, data [ , options, callback ]): Promise<void>
go.createDirSync( path, data [ , options ]): void

Creates the directory if it doesn't exist (it also creates missing directories in the path automatically). Read more about fs-extra ensureDir and ensureDirSync.

Examples

Basic usage

const newComponentName = 'new-component'
go.copy('./templates/component.js', `./src/components/${newComponentName}.js`)

Read and write file

const contributorsPath = './CONTRIBUTORS.md'
const newContributor = 'Chuck Norris'

go.readFile(contributorsPath)
  .then((content) => `${content}\n - ${newContributor}`)
  .then((content) => go.writeFile(contributorsPath, content))

License

MIT © Stanislav Termosa

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free