json-file-structure
v1.0.11
Published
Clean and simple JavaScript project for turning JSON objects into directory and file structures.
Downloads
6
Maintainers
Readme
Getting started
"json-file-structure" was created to create file & directory structures from a JSON definition
Example
const JSONtoFiles = require('json-file-structure);
let destination = 'dist';
let data = [
{
name: "index.html", // required
content: "<h1 id=\"header\">Home Page</h1>"
},{
name: "about.html", // required
content: "<h1 id=\"header\">About Page</h1>"
},{
name: "assets", // required
children: [ // required for directories
{
name: "projects.json", // required
content: "{\"projects\":[]}"
},
{
name: "images", // required
children: [] // required for directories
}
]
}
]
JSONtoFiles(destination,data);
Output
- dist/
- index.html
- about.html
- assets/
- projects.json
- images/
Types
json-file-structure
can create both directories and files. Below are the required fields for each.
Directories (folders)
Directories are created when an object has a children
key with a value type of array. This array can be empty but it MUST exist for a directory to be created. You can nest directories
empty directory
{
name: "images", // required
children: [] // required
}
Files
Files are created if the object has a name
. However content
is optional.
empty file
{
name: "test.txt", // required
}