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

Install

npm i @putout/plugin-filesystem -D

Rules

Config

{
    "rules": {
        "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/convert-filesystem-to-simple-filesystem": "off",
        "filesystem/replace-cwd": ["off", {
            "from": "/home/coderaiser/putout",
            "to": "/"
        }],
        "filesystem/convert-json-to-yaml": ["off", {
            "filename": "actions.json"
        }],
        "filesystem/convert-yaml-to-toml": ["off", {
            "filename": "bunfig.yaml"
        }],
        "filesystem/convert-json-to-toml": ["off", {
            "filename": "bunfig.json"
        }],
        "filesystem/convert-toml-to-json": ["off", {
            "filename": "bunfig.toml"
        }],
        "filesystem/convert-toml-to-yaml": ["off", {
            "filename": "bunfig.toml"
        }],
        "filesystem/convert-json-to-js": ["off", {
            "filename": "package.json"
        }],
        "filesystem/convert-yaml-to-json": ["off", {
            "filename": "actions.yaml"
        }],
        "filesystem/convert-js-to-json": ["off", {
            "filename": "package.js"
        }]
    }
}

bundle

Bundle and minify css files.

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

Checkout in 🐊Putout Editor.

Before:

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

After:

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

Just minify styles:

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

Before:

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

After:

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

Create subdirectory:

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

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/rename-referenced-file": ["on", {
            "from": "hello.js",
            "to": "world.js"
        }]
    }
}

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:

// hello.spec.js
import hello from './hello.js';

Concut files:

Before:

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

After:

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

convert-simple-filesystem-to-filesystem

Checkout in 🐊Putout Editor.

convert-filesystem-to-simple-filesystem

Checkout in 🐊Putout Editor.

convert-json-to-js

Checkout in 🐊Putout Editor.

Filesystem:

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

convert-json-to-toml

Filesystem:

-["/", "/bunfig.json"]
+["/", "/bunfig.toml"]

convert-toml-to-json

Filesystem:

-["/", "/bunfig.toml"]
+["/", "/bunfig.json"]

convert-toml-to-yaml

Filesystem:

-["/", "/bunfig.toml"]
+["/", "/bunfig.yaml"]

❌ Example of incorrect code

// hello.spec.js
import hello from './world.js';

βœ… Example of correct code

// world.js
export const hello = 'world';

convert-json-to-yaml

Filesystem:

-["/", "/actions.json"]
+["/", "/actions.yaml"]

❌ Example of incorrect code

__putout_processor_json({
    rules: {
        'filesystem/move-referenced-file': ['on', {
            name: 'hello.js',
            directory: 'lib',
        }],
    },
});

βœ… Example of correct code

// test/hello.spec.js
import hello from '../src/hello.js';

convert-yaml-to-toml

Filesystem:

-["/", "/bunfig.yaml"]
+["/", "/bunfig.toml"]

convert-yaml-to-json

Filesystem:

-["/", "/actions.yaml"]
+["/", "/actions.json"]

❌ Example of incorrect code

// src/hello.js
export const hello = 'world';

βœ… Example of correct code

// test/hello.spec.js
import hello from '../lib/hello.js';

convert-js-to-json

Checkout in 🐊Putout Editor:

Filesystem:

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

❌ Example of incorrect code

βœ… Example of correct code

move-referenced-file

Update .putout.json to enable rule:

Checkout in 🐊Putout Editor.

Before:

/
|-- test/
|  `-- hello.spec.js
|-- src/
|   `-- hello.js
`-- lib/
__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: [],
    }],
});
__putout_processor_filesystem([
    '/',
    '/hello.txt',
    ['/world.txt', 'hello world'],
    '/abc/',
]);

After:

/
|-- test/
|   `-- hello.spec.js
|-- src/
`-- lib/
    `-- hello.js
-src/hello.js
+lib/hello.js
__putout_processor_json({
    rules: {
        'filesystem/bundle': ['on', {
            groups: [
                ['__:columns/__', [
                    'name-size-date.css',
                    'name-size.css',
                ]],
                [
                    'main.css',
                    ['hello.css', 'world.css'],
                ],
                '1:1',
            ],
        }],
    },
});
__putout_processor_json({
    rules: {
        'filesystem/bundle': ['on', {
            groups: ['1:1'],
        }],
    },
});

rename-file

Checkout in 🐊Putout Editor.

Update .putout.json to enable rule:

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

It will make next modifications to filesystem:

-README.md
+readme.md

For more sophisticated example, use mask:

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

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

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

❌ Example of incorrect code

remove-files

Remove next files:

  • *.swp;
  • *.swo;
  • *.lock;
  • .DS_Store;
  • .travis.yml;

Apply overrides:

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

It will make next modifications to filesystem:

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

❌ Example of incorrect code

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

βœ… Example of correct code

[install]
lockfile = false
linker = "hoisted"

rename-spec-to-test

Checkout in 🐊Putout Editor.

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

❌ Example of incorrect code

[install]
lockfile = false
linker = "hoisted"

βœ… Example of correct code

rename-test-to-spec

Checkout in 🐊Putout Editor.

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

❌ Example of incorrect code

[install]
lockfile = false
linker = "hoisted"

βœ… Example of correct code

install:
  lockfile: false
  linker: hoisted

rename-referenced-file

Update .putout.json to enable rule:

Checkout in 🐊Putout Editor.

Before:

__putout_processor_json(['/', '/hello.xyz']);
__putout_processor_json([
    '/',
    ['/hello.xyz', 'hello world'],
]);

After:

-hello.js
+world.js
__putout_processor_json([
    '/',
    ['/hello.xyz', 'hello world'],
]);
__putout_processor_json({
    plugins: [],
});

❌ Example of incorrect code

{
    "install": {
        "lockfile": false,
        "linker": "hoisted"
    }
}

βœ… Example of correct code

name: Node CI
on:
    push:
        branches: master

replace-cwd

Checkout in 🐊Putout Editor.

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

{
    "install": {
        "lockfile": false,
        "linker": "hoisted"
    }
}

❌ Example of incorrect code

install:
  lockfile: false
  linker: hoisted

βœ… Example of correct code

[install]
lockfile = false
linker = "hoisted"

read-all-files

Checkout in 🐊Putout Editor.

❌ Example of incorrect code

name: Node CI
on:
    push:
    branches: master

βœ… Example of correct code

{
    "name": "Node CI",
    "on": {
        "push": {
            "branches": "master"
        }
    }
}

write-all-files

Write all files that was read before to Filesystem.

Checkout in 🐊Putout Editor.

{
    "name": "Node CI",
    "on": {
        "push": {
            "branches": "master"
        }
    }
}

❌ Example of incorrect code

{
    "plugins": []
}

βœ… Example of correct code

export default {
    plugins: [],
};

License

MIT

Current Tags

  • 13.6.0                                ...           latest (3 months ago)

86 Versions

  • 13.6.0                                ...           3 months ago
  • 13.5.2                                ...           3 months ago
  • 13.5.1                                ...           3 months ago
  • 13.5.0                                ...           3 months ago
  • 13.4.0                                ...           6 months ago
  • 13.3.0                                ...           6 months ago
  • 13.2.0                                ...           6 months ago
  • 13.1.0                                ...           9 months ago
  • 13.0.2                                ...           9 months ago
  • 13.0.1                                ...           9 months ago
  • 13.0.0                                ...           9 months ago
  • 12.4.1                                ...           10 months ago
  • 12.4.0                                ...           10 months ago
  • 12.3.0                                ...           10 months ago
  • 12.2.0                                ...           10 months ago
  • 12.1.1                                ...           a year ago
  • 12.1.0                                ...           a year ago
  • 12.0.0                                ...           a year ago
  • 11.0.1                                ...           a year ago
  • 11.0.0                                ...           a year ago
  • 10.1.0                                ...           2 years ago
  • 10.0.0                                ...           2 years ago
  • 9.0.1                                ...           2 years ago
  • 9.0.0                                ...           2 years ago
  • 8.3.0                                ...           2 years ago
  • 8.2.0                                ...           2 years ago
  • 8.1.0                                ...           2 years ago
  • 8.0.1                                ...           2 years ago
  • 8.0.0                                ...           2 years ago
  • 7.0.0                                ...           2 years ago
  • 6.0.0                                ...           2 years ago
  • 5.3.0                                ...           3 years ago
  • 5.2.0                                ...           3 years ago
  • 5.1.0                                ...           3 years ago
  • 5.0.0                                ...           3 years ago
  • 4.2.0                                ...           3 years ago
  • 4.1.0                                ...           3 years ago
  • 4.0.1                                ...           3 years ago
  • 4.0.0                                ...           3 years ago
  • 3.18.2                                ...           3 years ago
  • 3.18.1                                ...           3 years ago
  • 3.18.0                                ...           3 years ago
  • 3.17.0                                ...           3 years ago
  • 3.16.0                                ...           3 years ago
  • 3.15.0                                ...           3 years ago
  • 3.14.0                                ...           3 years ago
  • 3.13.0                                ...           3 years ago
  • 3.12.0                                ...           3 years ago
  • 3.11.0                                ...           3 years ago
  • 3.10.0                                ...           3 years ago
  • 3.9.0                                ...           3 years ago
  • 3.8.0                                ...           3 years ago
  • 3.7.0                                ...           3 years ago
  • 3.6.0                                ...           3 years ago
  • 3.5.0                                ...           3 years ago
  • 3.4.0                                ...           3 years ago
  • 3.3.0                                ...           3 years ago
  • 3.2.0                                ...           3 years ago
  • 3.1.1                                ...           3 years ago
  • 3.1.0                                ...           3 years ago
  • 3.0.0                                ...           3 years ago
  • 2.5.0                                ...           3 years ago
  • 2.4.2                                ...           3 years ago
  • 2.4.1                                ...           3 years ago
  • 2.4.0                                ...           3 years ago
  • 2.3.1                                ...           3 years ago
  • 2.3.0                                ...           3 years ago
  • 2.2.0                                ...           3 years ago
  • 2.1.0                                ...           3 years ago
  • 2.0.0                                ...           3 years ago
  • 1.10.0                                ...           3 years ago
  • 1.9.0                                ...           3 years ago
  • 1.8.1                                ...           3 years ago
  • 1.8.0                                ...           3 years ago
  • 1.7.0                                ...           3 years ago
  • 1.6.1                                ...           3 years ago
  • 1.6.0                                ...           3 years ago
  • 1.5.0                                ...           3 years ago
  • 1.4.0                                ...           3 years ago
  • 1.3.1                                ...           3 years ago
  • 1.3.0                                ...           3 years ago
  • 1.2.0                                ...           3 years ago
  • 1.1.0                                ...           3 years ago
  • 1.0.2                                ...           3 years ago
  • 1.0.1                                ...           3 years ago
  • 1.0.0                                ...           3 years ago
Maintainers (1)
Downloads
Total 73
Today 0
This Week 0
This Month 68
Last Day 0
Last Week 3
Last Month 2
Dependencies (4)
Dev Dependencies (12)

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