create-deep-dir

1.0.0 • Public • Published

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 the await statement. It does not return a Promise, but it is an asynchronous function.

Don't forget `import.meta.url` or `__dirname` !


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.


License

MIT

Package Sidebar

Install

npm i create-deep-dir

Weekly Downloads

17

Version

1.0.0

License

MIT

Unpacked Size

5.02 kB

Total Files

5

Last publish

Collaborators

  • hold_mine