@putout/operator-filesystem 4.1.0 → 5.1.0
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 +16 -7
- package/lib/filesystem.js +15 -2
- package/package.json +7 -7
package/README.md
CHANGED
|
@@ -23,7 +23,7 @@ const [dirPath] = findFile(ast, 'hello');
|
|
|
23
23
|
const filePath = createFile(dirPath, 'world.txt', 'hello world');
|
|
24
24
|
```
|
|
25
25
|
|
|
26
|
-
### `createDirectory(directoryPath:
|
|
26
|
+
### `createDirectory(directoryPath: DirectoryPath, name: string): DirectoryPath`
|
|
27
27
|
|
|
28
28
|
```js
|
|
29
29
|
const {operator} = require('putout');
|
|
@@ -37,7 +37,7 @@ const [dirPath] = findFile(ast, 'hello');
|
|
|
37
37
|
const newDirectoryPath = createDirectory(dirPath, 'world');
|
|
38
38
|
```
|
|
39
39
|
|
|
40
|
-
### `findFile(
|
|
40
|
+
### `findFile(directoryPath: DirectoryPath, name: string | string[], exclude?: string[]): (FilePath | DirectoryPath)[]`
|
|
41
41
|
|
|
42
42
|
```js
|
|
43
43
|
const {operator} = require('putout');
|
|
@@ -55,6 +55,15 @@ const {findFile} = operator;
|
|
|
55
55
|
const coupleFiles = findFile(ast, ['*.js', '*.ts']);
|
|
56
56
|
```
|
|
57
57
|
|
|
58
|
+
Or `exclude` some files:
|
|
59
|
+
|
|
60
|
+
```js
|
|
61
|
+
import {operator} from 'putout';
|
|
62
|
+
|
|
63
|
+
const {findFile} = operator;
|
|
64
|
+
const coupleFiles = findFile(ast, '*.ts', ['*.d.ts']);
|
|
65
|
+
```
|
|
66
|
+
|
|
58
67
|
And even search for a directory:
|
|
59
68
|
|
|
60
69
|
```js
|
|
@@ -64,7 +73,7 @@ const {findFile} = operator;
|
|
|
64
73
|
const coupleFiles = findFile(ast, ['/home/coderaiser', '/home/coderaiser/putout']);
|
|
65
74
|
```
|
|
66
75
|
|
|
67
|
-
### `getParentDirectory(
|
|
76
|
+
### `getParentDirectory(path: FilePath | DirectoryPath): FilePath | null`
|
|
68
77
|
|
|
69
78
|
```js
|
|
70
79
|
const {operator} = require('putout');
|
|
@@ -83,7 +92,7 @@ dirPath === getParentDirectory(newDirectoryPath);
|
|
|
83
92
|
true;
|
|
84
93
|
```
|
|
85
94
|
|
|
86
|
-
### `getFilename(path: FilePath): string`
|
|
95
|
+
### `getFilename(path: FilePath | DirectoryPath): string`
|
|
87
96
|
|
|
88
97
|
```js
|
|
89
98
|
const {operator} = require('putout');
|
|
@@ -125,7 +134,7 @@ const {removeFile} = operator;
|
|
|
125
134
|
removeFile(filePath);
|
|
126
135
|
```
|
|
127
136
|
|
|
128
|
-
### `copyFile(
|
|
137
|
+
### `copyFile(path: FilePath | DirectoryPath, directoryPath: DirectoryPath)`
|
|
129
138
|
|
|
130
139
|
```js
|
|
131
140
|
const {operator} = require('putout');
|
|
@@ -134,7 +143,7 @@ const {moveFile, copyFile} = operator;
|
|
|
134
143
|
copyFile(filePath, dirPath);
|
|
135
144
|
```
|
|
136
145
|
|
|
137
|
-
### `moveFile(
|
|
146
|
+
### `moveFile(path: FilePath | DirectoryPath, directoryPath: DirectoryPath)`
|
|
138
147
|
|
|
139
148
|
```js
|
|
140
149
|
const {operator} = require('putout');
|
|
@@ -169,7 +178,7 @@ readFileContent(filePath);
|
|
|
169
178
|
'hello';
|
|
170
179
|
```
|
|
171
180
|
|
|
172
|
-
### `renameFile(
|
|
181
|
+
### `renameFile(path: FilePath | DirectoryPath, name: string)`
|
|
173
182
|
|
|
174
183
|
```js
|
|
175
184
|
const {operator} = require('putout');
|
package/lib/filesystem.js
CHANGED
|
@@ -61,7 +61,16 @@ module.exports.getParentDirectory = (filePath) => {
|
|
|
61
61
|
|
|
62
62
|
module.exports.findFile = findFile;
|
|
63
63
|
|
|
64
|
-
function
|
|
64
|
+
function isExcluded(name, base, exclude) {
|
|
65
|
+
for (const currentExclude of exclude) {
|
|
66
|
+
if (name === currentExclude || getRegExp(currentExclude).test(base))
|
|
67
|
+
return true;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function findFile(node, name, exclude = []) {
|
|
65
74
|
checkName(name);
|
|
66
75
|
|
|
67
76
|
const filePaths = [];
|
|
@@ -72,8 +81,12 @@ function findFile(node, name) {
|
|
|
72
81
|
const base = basename(value);
|
|
73
82
|
|
|
74
83
|
for (const name of names) {
|
|
75
|
-
if (value === name || getRegExp(name).test(base))
|
|
84
|
+
if (value === name || getRegExp(name).test(base)) {
|
|
85
|
+
if (isExcluded(name, base, exclude))
|
|
86
|
+
continue;
|
|
87
|
+
|
|
76
88
|
filePaths.push(filenamePath.parentPath);
|
|
89
|
+
}
|
|
77
90
|
}
|
|
78
91
|
}
|
|
79
92
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/operator-filesystem",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.1.0",
|
|
4
4
|
"type": "commonjs",
|
|
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",
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"changelog": false,
|
|
12
12
|
"repository": {
|
|
13
13
|
"type": "git",
|
|
14
|
-
"url": "git://github.com/coderaiser/putout.git"
|
|
14
|
+
"url": "git+https://github.com/coderaiser/putout.git"
|
|
15
15
|
},
|
|
16
16
|
"scripts": {
|
|
17
17
|
"test": "madrun test",
|
|
@@ -36,13 +36,13 @@
|
|
|
36
36
|
"filesystem"
|
|
37
37
|
],
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@putout/engine-parser": "^
|
|
39
|
+
"@putout/engine-parser": "^11.0.1",
|
|
40
40
|
"@putout/operator-json": "^2.0.0",
|
|
41
|
-
"@putout/test": "^
|
|
42
|
-
"c8": "^
|
|
41
|
+
"@putout/test": "^11.0.0",
|
|
42
|
+
"c8": "^10.0.0",
|
|
43
43
|
"eslint": "^9.0.0",
|
|
44
44
|
"eslint-plugin-n": "^17.0.0",
|
|
45
|
-
"eslint-plugin-putout": "^
|
|
45
|
+
"eslint-plugin-putout": "^23.0.0",
|
|
46
46
|
"lerna": "^6.0.1",
|
|
47
47
|
"madrun": "^10.0.0",
|
|
48
48
|
"montag": "^1.2.1",
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
"supertape": "^10.0.0"
|
|
51
51
|
},
|
|
52
52
|
"peerDependencies": {
|
|
53
|
-
"putout": ">=
|
|
53
|
+
"putout": ">=36"
|
|
54
54
|
},
|
|
55
55
|
"license": "MIT",
|
|
56
56
|
"engines": {
|