Skip to content

gocli/go-plugin-fs

Repository files navigation

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

About

Go plugin to work with file system

Resources

License

Stars

Watchers

Forks

Packages

No packages published