@putout/plugin-filesystem
🐊Putout plugin operates with filesystem
Last updated a year ago by coderaiser .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install @putout/plugin-filesystem 
SYNC missed versions from official npm registry.

@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

Current Tags

  • 6.0.0                                ...           latest (a month ago)

56 Versions

  • 6.0.0                                ...           a month ago
  • 5.3.0                                ...           7 months ago
  • 5.2.0                                ...           7 months ago
  • 5.1.0                                ...           8 months ago
  • 5.0.0                                ...           9 months ago
  • 4.2.0                                ...           10 months ago
  • 4.1.0                                ...           10 months ago
  • 4.0.1                                ...           a year ago
  • 4.0.0                                ...           a year ago
  • 3.18.2                                ...           a year ago
  • 3.18.1                                ...           a year ago
  • 3.18.0                                ...           a year ago
  • 3.17.0                                ...           a year ago
  • 3.16.0                                ...           a year ago
  • 3.15.0                                ...           a year ago
  • 3.14.0                                ...           a year ago
  • 3.13.0                                ...           a year ago
  • 3.12.0                                ...           a year ago
  • 3.11.0                                ...           a year ago
  • 3.10.0                                ...           a year ago
  • 3.9.0                                ...           a year ago
  • 3.8.0                                ...           a year ago
  • 3.7.0                                ...           a year ago
  • 3.6.0                                ...           a year ago
  • 3.5.0                                ...           a year ago
  • 3.4.0                                ...           a year ago
  • 3.3.0                                ...           a year ago
  • 3.2.0                                ...           a year ago
  • 3.1.1                                ...           a year ago
  • 3.1.0                                ...           a year ago
  • 3.0.0                                ...           a year ago
  • 2.5.0                                ...           a year ago
  • 2.4.2                                ...           a year ago
  • 2.4.1                                ...           a year ago
  • 2.4.0                                ...           a year ago
  • 2.3.1                                ...           a year ago
  • 2.3.0                                ...           a year ago
  • 2.2.0                                ...           a year ago
  • 2.1.0                                ...           a year ago
  • 2.0.0                                ...           a year ago
  • 1.10.0                                ...           a year ago
  • 1.9.0                                ...           a year ago
  • 1.8.1                                ...           a year ago
  • 1.8.0                                ...           a year ago
  • 1.7.0                                ...           a year ago
  • 1.6.1                                ...           a year ago
  • 1.6.0                                ...           a year ago
  • 1.5.0                                ...           a year ago
  • 1.4.0                                ...           a year ago
  • 1.3.1                                ...           a year ago
  • 1.3.0                                ...           a year ago
  • 1.2.0                                ...           a year ago
  • 1.1.0                                ...           a year ago
  • 1.0.2                                ...           a year ago
  • 1.0.1                                ...           a year ago
  • 1.0.0                                ...           a year ago
Maintainers (1)
Downloads
Total 0
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (5)
Dev Dependencies (10)

© 2010 - cnpmjs.org x YWFE | Home | YWFE