@putout/operator-filesystem 10.6.0 → 11.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +49 -1
- package/lib/filesystem.js +7 -11
- package/lib/maybe-fs.js +5 -5
- package/package.json +6 -2
package/README.md
CHANGED
|
@@ -125,7 +125,7 @@ Anyways inside one plugin while you applying changes related to one plugin you c
|
|
|
125
125
|
|
|
126
126
|
☝️ *`findFile` expensive, when you need to call it often use `crawlDirectory()`*
|
|
127
127
|
|
|
128
|
-
### `crawlDirectory(directoryPath: directoryPath):
|
|
128
|
+
### `crawlDirectory(directoryPath: directoryPath): Crawled`
|
|
129
129
|
|
|
130
130
|
```js
|
|
131
131
|
import {operator} from 'putout';
|
|
@@ -295,6 +295,54 @@ Since `basename` is used.
|
|
|
295
295
|
|
|
296
296
|
To move file use [`moveFile()`](#movefilefilepath-filepath-dirpath-filepath).
|
|
297
297
|
|
|
298
|
+
### `inject`
|
|
299
|
+
|
|
300
|
+
Inject filesystem API with methods:
|
|
301
|
+
|
|
302
|
+
- ✅ `renameFile`;
|
|
303
|
+
- ✅ `copyFile`;
|
|
304
|
+
- ✅ `removeFile;
|
|
305
|
+
- ✅ `createDirectory;
|
|
306
|
+
- ✅ `readFileContent;
|
|
307
|
+
- ✅ `writeFileContent;
|
|
308
|
+
|
|
309
|
+
To have ability to interact with any kind of filesystem representation.
|
|
310
|
+
|
|
311
|
+
```js
|
|
312
|
+
import {inject} from '@putout/operator-filesystem/maybe';
|
|
313
|
+
import * as filesystemCLI from '@putout/cli-filesystem';
|
|
314
|
+
|
|
315
|
+
inject(filesystemCLI);
|
|
316
|
+
```
|
|
317
|
+
|
|
318
|
+
### `eject`
|
|
319
|
+
|
|
320
|
+
```js
|
|
321
|
+
import {eject} from '@putout/operator-filesystem/maybe';
|
|
322
|
+
|
|
323
|
+
eject();
|
|
324
|
+
```
|
|
325
|
+
|
|
326
|
+
### `pause`
|
|
327
|
+
|
|
328
|
+
Pause currently injected filesystem API
|
|
329
|
+
|
|
330
|
+
```js
|
|
331
|
+
import {pause} from '@putout/operator-filesystem/maybe';
|
|
332
|
+
|
|
333
|
+
pause();
|
|
334
|
+
```
|
|
335
|
+
|
|
336
|
+
### `start`
|
|
337
|
+
|
|
338
|
+
Start currently paused injected filesystem API.
|
|
339
|
+
|
|
340
|
+
```js
|
|
341
|
+
import {start} from '@putout/operator-filesystem/maybe';
|
|
342
|
+
|
|
343
|
+
start();
|
|
344
|
+
```
|
|
345
|
+
|
|
298
346
|
## Example
|
|
299
347
|
|
|
300
348
|
```js
|
package/lib/filesystem.js
CHANGED
|
@@ -103,11 +103,14 @@ function parseFindFileOptions(options) {
|
|
|
103
103
|
}
|
|
104
104
|
|
|
105
105
|
export function findFile(node, name, options) {
|
|
106
|
-
const {
|
|
106
|
+
const {
|
|
107
|
+
exclude = [],
|
|
108
|
+
crawled = crawlDirectory(node),
|
|
109
|
+
} = parseFindFileOptions(options);
|
|
107
110
|
|
|
108
111
|
checkName(name);
|
|
109
112
|
|
|
110
|
-
const filePaths =
|
|
113
|
+
const filePaths = new Set();
|
|
111
114
|
const names = maybeArray(name);
|
|
112
115
|
|
|
113
116
|
for (const filenamePath of crawled) {
|
|
@@ -126,12 +129,12 @@ export function findFile(node, name, options) {
|
|
|
126
129
|
if (excluded)
|
|
127
130
|
continue;
|
|
128
131
|
|
|
129
|
-
filePaths.
|
|
132
|
+
filePaths.add(path);
|
|
130
133
|
}
|
|
131
134
|
}
|
|
132
135
|
}
|
|
133
136
|
|
|
134
|
-
return filePaths;
|
|
137
|
+
return Array.from(filePaths);
|
|
135
138
|
}
|
|
136
139
|
|
|
137
140
|
function checkName(name) {
|
|
@@ -490,10 +493,3 @@ export function getFile(directoryPath, name, {type} = {}) {
|
|
|
490
493
|
|
|
491
494
|
return files.values();
|
|
492
495
|
}
|
|
493
|
-
|
|
494
|
-
export const {
|
|
495
|
-
init,
|
|
496
|
-
deinit,
|
|
497
|
-
pause,
|
|
498
|
-
start,
|
|
499
|
-
} = maybeFS;
|
package/lib/maybe-fs.js
CHANGED
|
@@ -41,19 +41,19 @@ export const writeFileContent = (name, content) => {
|
|
|
41
41
|
maybeFS.writeFileContent(name, content);
|
|
42
42
|
};
|
|
43
43
|
|
|
44
|
-
export
|
|
44
|
+
export const inject = (fsDriver) => {
|
|
45
45
|
assign(maybeFS, fsDriver);
|
|
46
|
-
}
|
|
46
|
+
};
|
|
47
47
|
|
|
48
48
|
export const pause = () => {
|
|
49
49
|
driverStore(maybeFS);
|
|
50
|
-
|
|
50
|
+
eject();
|
|
51
51
|
};
|
|
52
52
|
|
|
53
53
|
export const start = () => {
|
|
54
|
-
|
|
54
|
+
inject(driverStore());
|
|
55
55
|
};
|
|
56
56
|
|
|
57
|
-
export function
|
|
57
|
+
export function eject() {
|
|
58
58
|
assign(maybeFS, defaultFS);
|
|
59
59
|
}
|
package/package.json
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/operator-filesystem",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "11.0.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
|
|
6
6
|
"description": "🐊Putout operator adds ability to filesystem referenced variables that was not defined",
|
|
7
7
|
"homepage": "https://github.com/coderaiser/putout/tree/master/packages/operator-filesystem#readme",
|
|
8
8
|
"main": "lib/filesystem.js",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": "./lib/filesystem.js",
|
|
11
|
+
"./maybe": "./lib/maybe-fs.js"
|
|
12
|
+
},
|
|
9
13
|
"release": false,
|
|
10
14
|
"tag": false,
|
|
11
15
|
"changelog": false,
|
|
@@ -42,7 +46,7 @@
|
|
|
42
46
|
"@putout/eslint-flat": "^4.0.0",
|
|
43
47
|
"@putout/test": "^15.0.0",
|
|
44
48
|
"c8": "^10.0.0",
|
|
45
|
-
"eslint": "^10.0.0
|
|
49
|
+
"eslint": "^10.0.0",
|
|
46
50
|
"eslint-plugin-n": "^17.0.0",
|
|
47
51
|
"eslint-plugin-putout": "^30.0.0",
|
|
48
52
|
"madrun": "^12.0.0",
|