0.0.1 • Published 7 years ago

handmade-fs v0.0.1

Weekly downloads
2
License
MIT
Repository
github
Last release
7 years ago

handmade-fs

handmade-fs on NPM handmade-fs on Travis Standard JavaScript Style handmade-fs Stability Index

File system tasks for handmade.

Install

# via npm
$ npm i handmade-fs --save

# via yarn
$ yarn add handmade-fs

Use

handmade-fs exports read and write tasks.

const {
  read,
  write
} = require('handmade-fs')

.read(path)

Accepts a path to an existing folder, relative to the root of the build.

Reads contents of all files within, populating the build object with the file data.

const handmade = require('handmade')
const { read } = require('handmade-fs')

// read path is relative to this context
handmade(__dirname)
  // relative path to source files
  .task(read('./src'))

  // in subsequent tasks, access the read path and file data from the core
  .task(contents => new Promise((resolve, reject) => {    
    const {
      files,
      read
    } = contents.core

    resolve(contents)
  }))

  // start the build
  .build()

.write(path)

Accepts a path to a new or existing folder, relative to the root of the build.

Creates necessary folders and writes files, using the file data from the build object.

const handmade = require('handmade')

const {
  read,
  write
} = require('handmade-fs')

// write path is relative to this context
handmade(__dirname)
  // relative path to src files
  .task(read('./src'))

  // relative path to dist files
  .task(write('./dist'))

  // start the build
  .build()

Because the file data isn't modified in a different task between the read and write tasks, the above code essentially copies the src folder contents to the dist folder.

Roadmap

  • Add merge option (read multiple folders into same object)

License

MIT. © 2017 Michael Cavalea