npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

create-fs-tree

v1.0.0

Published

Create a fs tree from a json definition

Downloads

775

Readme

npm version Build Status Coverage Status Dependency Status devDependency Status

create-fs-tree

Create a filesystem tree from a definition. This module is intended to use in unit/e2e tests to create a pre-determined fs trees.

Use

You probably want to install this as an npm dev dependency:

npm install --save-dev create-fs-tree

Use it in your tests:

import {expect} from "chai";
import {createTree, destroyTree} from "create-fs-tree";
import {readFileSync} from "fs";
import {tmpdir} from "os";
import {join} from "path";

describe("my test subject", () => {

    const dir = join(os.tmpdir(), "root");

    before(() => {
        createTree(dir, {
            "file": "file content",
            "other-file": Buffer.from("other-file content"),
            "sub-dir": {
                "sub-file": "sub-file content"
            }
        });
    });
    after(() => {
        destroyTree(dir);
    });

    it("my test", () => {
        expect(
            readFileSync(join(dir, "file"))
        ).to.equal("file content");
    });

});

API

createTree(root, definition)

Creates under the root directory a fs tree as specified in the definition.

WARNING: createTree removes the root directory before creating the specified fs tree.

Arguments
  • root string: root directory under which the fs tree is created. The directory is created if it doesn't exist, it's emptied if it already exists
  • definition object: an object describing the fs tree to create. Its properties' values can either be:
    • strings or buffers: in which case a file with the property key as name and the property value as content will be created
    • definition objects: in which case a directory with the property key as name will be created, and under it a fs tree as described by the property value (which of course is a definition object)
Returns

Nothing.

Example
createTree("mydir", {
    "level-0-file": Buffer.from("level-0-file content\n"),
    "level-0-dir": {
        "level-1-file": "level-1-file content\n",
        "level-1-dir": {}
    }
});

Creates a fs tree so that:

$ tree mydir
mydir
├── level-0-file
└── level-0-dir
    ├── level-1-file
    └── level-1-dir
$ cat mydir/level-0-file
level-0-file content
$ cat mydir/level-0-dir/level-1-file
level-1-file content

destroyTree(root)

Removes the root path. Equivalent to rm -rf.

Arguments
  • root string: path to remove
Returns

Nothing.

Contribute

See CONTRIBUTING.