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

@putout/plugin-filesystem

v5.3.0

Published

๐ŸŠPutout plugin operates with filesystem

Downloads

8,039

Readme

@putout/plugin-filesystem NPM version

๐ŸŠPutout plugin helps to lint filesystem.

Install

npm i @putout/plugin-filesystem -D

Rules

Config

{
    "rules": {
        "filesystem/remove-vim-swap-file": "on",
        "filesystem/bundle": "off",
        "filesystem/read-all-files": ["off", {
            "mask": "*"
        }],
        "filesystem/write-all-files": "off",
        "filesystem/rename-file": "off",
        "filesystem/remove-files": "off",
        "filesystem/rename-spec-to-test": "off",
        "filesystem/rename-test-to-spec": "off",
        "filesystem/rename-referenced-file": "off",
        "filesystem/move-referenced-file": "off",
        "filesystem/convert-simple-filesystem-to-filesystem": "off",
        "filesystem/replace-cwd": ["off", {
            "from": "/home/coderaiser/putout",
            "to": "/"
        }],
        "filesystem/convert-json-to-js": ["off", {
            "filename": "package.json"
        }],
        "filesystem/convert-js-to-json": ["off", {
            "filename": "package.js"
        }]
    }
}

rename-file

Checkout in ๐ŸŠPutout Editor.

Update .putout.json to enable rule:

{
    "rules": {
        "filesystem/rename-file": ["on", {
            "from": "README.md",
            "to": "readme.md"
        }]
    }
}

It will make next modifications to filesystem:

-README.md
+readme.md

For more sophisticated example, use mask:

{
    "rules": {
        "filesystem/rename-file": ["on", {
            "mask": "*.test.*",
            "from": "test",
            "to": "spec"
        }]
    }
}

It will rename 'test' to 'spec' in *.test.* files:

-index.test.js
+index.spec.js

remove-vim-swap-file

Checkout in ๐ŸŠPutout Editor.

-readme.md.swap

remove-files

Update .putout.json to enable rule:

{
    "rules": {
        "filesystem/remove-files": ["on", {
            "names": ["coverage"]
        }]
    }
}

It will make next modifications to filesystem:

 /
 |-- test/
 |   `-- hello.spec.js
-|-- coverage/
 `-- lib/
     `-- hello.js

rename-spec-to-test

Checkout in ๐ŸŠPutout Editor.

-index.spec.js
+index.test.js

rename-test-to-spec

Checkout in ๐ŸŠPutout Editor.

-index.test.js
+index.spec.js

rename-referenced-file

Update .putout.json to enable rule:

{
    "rules": {
        "filesystem/rename-referenced-file": ["on", {
            "from": "hello.js",
            "to": "world.js"
        }]
    }
}

Checkout in ๐ŸŠPutout Editor.

Before:

// hello.spec.js
import hello from './hello.js';
// hello.js
export const hello = 'world';

After:

-hello.js
+world.js
// hello.spec.js
import hello from './world.js';
// world.js
export const hello = 'world';

move-referenced-file

Update .putout.json to enable rule:

{
    "rules": {
        "filesystem/move-referenced-file": ["on", {
            "name": "hello.js",
            "directory": "lib"
        }]
    }
}

Checkout in ๐ŸŠPutout Editor.

Before:

/
|-- test/
|  `-- hello.spec.js
|-- src/
|   `-- hello.js
`-- lib/
// test/hello.spec.js
import hello from '../src/hello.js';
// src/hello.js
export const hello = 'world';

After:

/
|-- test/
|   `-- hello.spec.js
|-- src/
`-- lib/
    `-- hello.js
-src/hello.js
+lib/hello.js
// test/hello.spec.js
import hello from '../lib/hello.js';
// lib/hello.js
export const hello = 'world';

convert-simple-filesystem-to-filesystem

Checkout in ๐ŸŠPutout Editor.

โŒ Example of incorrect code

__putout_processor_filesystem([
    '/',
    '/hello.txt',
    [
        '/world.txt',
        'hello world',
    ],
    '/abc/',
]);

โœ… Example of correct code

__putout_processor_filesystem({
    type: 'directory',
    filename: '/',
    files: [{
        type: 'file',
        filename: '/hello.txt',
    }, {
        type: 'file',
        filename: '/world.txt',
        content: 'hello world',
    }, {
        type: 'directory',
        filename: '/abc',
        files: [],
    }],
});

convert-filesystem-to-simple-filesystem

Checkout in ๐ŸŠPutout Editor.

โŒ Example of incorrect code

__putout_processor_filesystem({
    type: 'directory',
    filename: '/',
    files: [{
        type: 'file',
        filename: '/hello.txt',
    }, {
        type: 'file',
        filename: '/world.txt',
        content: 'hello world',
    }, {
        type: 'directory',
        filename: '/abc',
        files: [],
    }],
});

โœ… Example of correct code

__putout_processor_filesystem([
    '/',
    '/hello.txt',
    [
        '/world.txt',
        'hello world',
    ],
    '/abc/',
]);

bundle

Bundle and minify css files.

{
    "rules": {
        "filesystem/bundle": ["on", {
            "groups": [
                ["__:columns/__", [
                    "name-size-date.css",
                    "name-size.css"
                ]],
                ["main.css", [
                    "hello.css",
                    "world.css"
                ]],
                "1:1"
            ]
        }]
    }
}

Checkout in ๐ŸŠPutout Editor.

Before:

/
|-- css/
|  `-- hello.css
|  `-- world.css

After:

/
|-- css/
|  `-- hello.css
|  `-- world.css
|-- dist/
|   `-- main.css

Just minify styles:

{
    "rules": {
        "filesystem/bundle": ["on", {
            "groups": ["1:1"]
        }]
    }
}

Before:

/
|-- css/
|  `-- hello.css
|  `-- world.css

After:

/
|-- css/
|  `-- hello.css
|  `-- world.css
|-- dist/
|   `-- hello.css
|   `-- world.css

Create subdirectory:

{
    "rules": {
        "filesystem/bundle": ["on", {
            "groups": [
                ["__:columns/__", [
                    "name-size-date.css",
                    "name-size.css"
                ]]
            ]
        }]
    }
}

Before:

/
|-- css/
|  `-- hello.css
|  `-- world.css

After:

/
|-- css/
|  `-- hello.css
|  `-- world.css
|-- dist/
|   `-- columns
|       `-- hello.css
|       `-- world.css

Filter css files by mask:

{
    "rules": {
        "filesystem/bundle": ["on", {
            "mask": "*.good.css",
            "groups": ["1:1"]
        }]
    }
}

Before:

/
|-- css/
|  `-- hello.css
|  `-- world.good.css

After:

/
|-- css/
|  `-- hello.css
|  `-- world.css
|-- dist/
|   `-- world.good.css

You can even override transform with your own config:

putout(filesystem, {
    rules: {
        'filesystem/bundle': ['on', {
            transform: (source: string | string[], config) => string,
        }],
    },
});

Concreate files:

{
    "rules": {
        "filesystem/bundle": ["on", {
            "groups": ["hello.css"]
        }]
    }
}

Before:

/
|-- css/
|  `-- hello.css
|  `-- world.css

After:

/
|-- css/
|  `-- hello.css
|  `-- world.css
|-- dist/
|   `-- hello.css

replace-cwd

Checkout in ๐ŸŠPutout Editor.

When from=/home/coderaiser/putout and to=/:

{
    "rules": {
        "filesystem/replace-cwd": ["on", {
            "from": "/home/coderaiser/putout",
            "to": "/"
        }]
    }
}

โŒ Example of incorrect code

__putout_processor_filesystem(['/home/coderaiser/putout/', '/home/coderaiser/putout/README.md']);

โœ… Example of correct code

__putout_processor_filesystem(['/', '/README.md']);

read-all-files

Checkout in ๐ŸŠPutout Editor.

โŒ Example of incorrect code

["/", "/hello.xyz"]

โœ… Example of correct code

["/", [
    "/hello.xyz",
    "hello world"
]]

write-all-files

Write all files that was read before to Filesystem.

Checkout in ๐ŸŠPutout Editor.

["/", [
    "/hello.xyz",
    "hello world"
]]

convert-json-to-js

Checkout in ๐ŸŠPutout Editor.

Filesystem:

-["/", "/package.json"]
+["/", "/package.js"]

โŒ Example of incorrect code

{
    "plugins": []
}

โœ… Example of correct code

export default {
    plugins: [],
};

convert-js-to-json

Checkout in ๐ŸŠPutout Editor:

Filesystem:

-["/", "/package.js"]
+["/", "/package.json"]

โŒ Example of incorrect code

{
    "plugins": []
}

โœ… Example of correct code

export default {
    plugins: [],
};

License

MIT