create-deep-dir
v1.0.0
Published
Create lots of folders and files with a single object representing the structure!
Downloads
2
Maintainers
Readme
Create-Deep-Dir
Create lots of folders and files with a single object representing the structure! Works with commonjs and es6 modules.
- Dependencies: 0
Installation
# npm
npm i create-deep-dir
# pnpm
pnpm i create-deep-dir
# yarn
yarn add create-deep-dir
Usage
ES6 Modules
import { create } from "./index.js";
create(import.meta.url, {
src: { // create a folder
js: { // another folder
'index.js': 'console.log("Hello Index!")', // a file
'app.js': 'console.log("Hello App!")'
},
'css/index.css': 'body { background: red; }', // a folder css and a file index.css
'html/app': { // a folder html and a folder app
'index.html': '<h1>Hello World!</h1>', // a file
'top.html': '<h1>Top</h1>'
}
}
})
CommonJS
const { create } = require("./index.js");
create(__dirname, {
src: {
js: {
'index.js': 'console.log("Hello Index!")',
'app.js': 'console.log("Hello App!")'
},
'css/index.css': 'body { background: red; }',
'html/app': {
'index.html': '<h1>Hello World!</h1>',
'top.html': '<h1>Top</h1>'
}
}
})
- It creates the structure at the location of the file from which it is called.
- You can use
create()
with theawait
statement. It does not return a Promise, but it is an asynchronous function.
Result
src
├── js
│ ├── index.js
│ └── app.js
├── css
│ └── index.css
└── html
└── app
├── index.html
└── top.html
API
Create(path, structure)
params
path
- The path to the folder where the structure will be created.import.meta.url
or__dirname
structure
- Object representing the structure to be created.