struc

v1.0.0
Build file/dir structures from plain js objects
file directory fs build create nikerino json

struc Travis build AppVeyor build

Create file/dir structures from plain js objects on disk

Most useful in testing while combined with tempy.

Install

$ npm install struc

Usage

The following input:

const struc = require('struc');

struc('path/', {
    'file': 'file contents',
    'directory': {
        'another-file': 'with stuff inside!',
        'empty-dir': {}
    }
});

...would place the following files/directories on disk:

path/file: "file contents"
path/directory/another-file: "with stuff inside"
path/directory/empty-dir/

API

struc([path], structure)

Returns the absolute resolved path.

path

Type: String
Default: tempy.directory()

Path to the target directory the structure will be placed inside of. Will be created if doesn't exist, otherwise must be an empty directory.

structure

Type: Object

A file/directory representation, keys represent paths and all values of the object must be of type object or string (array isn't allowed). An object represents a directory its keys being other files/directories, while string represents a file with contents being the string itself.

License

MIT © nikersify

Metadata

  • MIT
  • >=4
  • nikersify
  • released 2/4/2018

Downloads

Maintainers