πPutout plugin operates with filesystem
npm install @putout/plugin-filesystem[NPMIMGURL]: https://img.shields.io/npm/v/@putout/plugin-filesystem.svg?style=flat&longCache=true
[NPMURL]: https://npmjs.org/package/@putout/plugin-filesystem "npm"
πPutout plugin helps to lint filesystem.
```
npm i @putout/plugin-filesystem -D
- β
bundle;
- β
convert-filesystem-to-simple-filesystem;
- β
convert-js-to-json;
- β
convert-json-to-js;
- β
convert-simple-filesystem-to-filesystem;
- β
move-referenced-file;
- β
read-all-files;
- β
rename-file;
- β
remove-empty-directory;
- β
remove-travis-yml-file;
- β
remove-vim-swap-file;
- β
remove-nyc-output-files;
- β
remove-ds-store-file;
- β
remove-files;
- β
rename-referenced-file;
- β
rename-spec-to-test;
- β
rename-test-to-spec;
- β
replace-cwd;
- β
write-all-files;
`json`
{
"rules": {
"filesystem/remove-empty-directory": "on",
"filesystem/remove-travis-yml-file": "on",
"filesystem/remove-ds-store-file": "on",
"filesystem/remove-vim-swap-file": "on",
"filesystem/remove-nyc-output-files": "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"
}]
}
}
Checkout in πPutout Editor.
Update .putout.json to enable rule:
`json`
{
"rules": {
"filesystem/rename-file": ["on", {
"from": "README.md",
"to": "readme.md"
}]
}
}
It will make next modifications to filesystem:
`diff`
-README.md
+readme.md
For more sophisticated example, use mask:
`json`
{
"rules": {
"filesystem/rename-file": ["on", {
"mask": ".test.",
"from": "test",
"to": "spec"
}]
}
}
It will rename 'test' to 'spec' in .test. files:
`diff`
-index.test.js
+index.spec.js
Checkout in πPutout Editor.
`diff-- abc/
/
-|-- hello/
-|
-| -- def/`
`diff`
-.DS_Store
Checkout in πPutout Editor.
`diff`
-.nyc_output
Checkout in πPutout Editor.
`diff`
-.travis.yml
Checkout in πPutout Editor.
`diff`
-readme.md.swap
Update .putout.json to enable rule:
`json`
{
"rules": {
"filesystem/remove-files": ["on", {
"names": ["coverage"]
}]
}
}
It will make next modifications to filesystem:
`diff-- hello.spec.js
/
|-- test/
|
-|-- coverage/
-- lib/-- hello.js
``
Checkout in πPutout Editor.
`diff`
-index.spec.js
+index.test.js
Checkout in πPutout Editor.
`diff`
-index.test.js
+index.spec.js
Update .putout.json to enable rule:
`json`
{
"rules": {
"filesystem/rename-referenced-file": ["on", {
"from": "hello.js",
"to": "world.js"
}]
}
}
Checkout in πPutout Editor.
Before:
`js`
// hello.spec.js
import hello from './hello.js';
`js`
// hello.js
export const hello = 'world';
After:
`diff`
-hello.js
+world.js
`js`
// hello.spec.js
import hello from './world.js';
`js`
// world.js
export const hello = 'world';
Update .putout.json to enable rule:
`json`
{
"rules": {
"filesystem/move-referenced-file": ["on", {
"name": "hello.js",
"directory": "lib"
}]
}
}
Checkout in πPutout Editor.
Before:
`-- hello.spec.js
/
|-- test/
|
|-- src/
| -- hello.js-- lib/
``
`js`
// test/hello.spec.js
import hello from '../src/hello.js';
`js`
// src/hello.js
export const hello = 'world';
After:
`-- hello.spec.js
/
|-- test/
|
|-- src/-- lib/-- hello.js
``
`diff`
-src/hello.js
+lib/hello.js
`js`
// test/hello.spec.js
import hello from '../lib/hello.js';
`js`
// lib/hello.js
export const hello = 'world';
Checkout in πPutout Editor.
`js`
__putout_processor_filesystem([
'/',
'/hello.txt',
[
'/world.txt',
'hello world',
],
'/abc/',
]);
`js`
__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: [],
}],
});
Checkout in πPutout Editor.
`js`
__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: [],
}],
});
`js`
__putout_processor_filesystem([
'/',
'/hello.txt',
[
'/world.txt',
'hello world',
],
'/abc/',
]);
Bundle and minify css files.
`json`
{
"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:
`-- hello.css
/
|-- css/
|
| -- world.css`
After:
`-- hello.css
/
|-- css/
|
| -- world.css-- main.css
|-- dist/
|
``
Just minify styles:
`json`
{
"rules": {
"filesystem/bundle": ["on", {
"groups": ["1:1"]
}]
}
}
Before:
`-- hello.css
/
|-- css/
|
| -- world.css`
After:
`-- hello.css
/
|-- css/
|
| -- world.css-- hello.css
|-- dist/
|
| -- world.css`
Create subdirectory:
`json`
{
"rules": {
"filesystem/bundle": ["on", {
"groups": [
["__:columns/__", [
"name-size-date.css",
"name-size.css"
]]
]
}]
}
}
Before:
`-- hello.css
/
|-- css/
|
| -- world.css`
After:
`-- hello.css
/
|-- css/
|
| -- world.css-- columns
|-- dist/
|
| -- hello.css-- world.css
|
``
Filter css files by mask:
`json`
{
"rules": {
"filesystem/bundle": ["on", {
"mask": "*.good.css",
"groups": ["1:1"]
}]
}
}
Before:
`-- hello.css
/
|-- css/
|
| -- world.good.css`
After:
`-- hello.css
/
|-- css/
|
| -- world.css-- world.good.css
|-- dist/
|
``
You can even override transform with your own config:
`ts`
putout(filesystem, {
rules: {
'filesystem/bundle': ['on', {
transform: (source: string | string[], config) => string,
}],
},
});
Concut files:
`json`
{
"rules": {
"filesystem/bundle": ["on", {
"groups": ["hello.css"]
}]
}
}
Before:
`-- hello.css
/
|-- css/
|
| -- world.css`
After:
`-- hello.css
/
|-- css/
|
| -- world.css-- hello.css
|-- dist/
|
``
Checkout in πPutout Editor.
When from=/home/coderaiser/putout and to=/:
`json`
{
"rules": {
"filesystem/replace-cwd": ["on", {
"from": "/home/coderaiser/putout",
"to": "/"
}]
}
}
`js`
__putout_processor_filesystem(['/home/coderaiser/putout/', '/home/coderaiser/putout/README.md']);
`js`
__putout_processor_filesystem(['/', '/README.md']);
Checkout in πPutout Editor.
`json`
["/", "/hello.xyz"]
`json`
["/", [
"/hello.xyz",
"hello world"
]]
Write all files that was read before to Filesystem.
Checkout in πPutout Editor.
`json`
["/", [
"/hello.xyz",
"hello world"
]]
Checkout in πPutout Editor.
Filesystem:
`diff`
-["/", "/package.json"]
+["/", "/package.js"]
`json`
{
"plugins": []
}
`js`
export default {
plugins: [],
};
Checkout in πPutout Editor:
Filesystem:
`diff`
-["/", "/package.js"]
+["/", "/package.json"]
`json`
{
"plugins": []
}
`js``
export default {
plugins: [],
};
MIT