@putout/operator-filesystem 2.2.0 → 2.3.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 CHANGED
@@ -24,10 +24,10 @@ const {
24
24
 
25
25
  const [dirPath] = findFile(ast, 'hello');
26
26
 
27
- const newDiretoryPath = createDirectory(dirPath, 'world');
27
+ const newDirectoryPath = createDirectory(dirPath, 'world');
28
28
  ```
29
29
 
30
- ## `findFile(path: Path, name: string): FilePath[]`
30
+ ## `findFile(path: Path, name: string | string[]): FilePath[]`
31
31
 
32
32
  ```js
33
33
  const {operator} = require('putout');
@@ -36,6 +36,15 @@ const {finedFiles, findFile} = operator;
36
36
  const [filePath] = findFile(ast, 'hello');
37
37
  ```
38
38
 
39
+ You can also pass array of file masks:
40
+
41
+ ```js
42
+ import {operator} from 'putout';
43
+
44
+ const {findFile} = operator;
45
+ const coupleFiles = findFile(ast, ['*.js', '*.ts']);
46
+ ```
47
+
39
48
  ### `getFilename(path: FilePath)`
40
49
 
41
50
  ```js
@@ -112,7 +121,7 @@ Since `basename` is used.
112
121
  >
113
122
  > (c) [nodejs.org](https://nodejs.org/api/path.html#pathbasenamepath-suffix)
114
123
 
115
- To move file use [`moveFile(file: FilePath, directory: FilePath)`](#movefilefilepath-filepath-dirpath-filepath);
124
+ To move file use [`moveFile()`](#movefilefilepath-filepath-dirpath-filepath).
116
125
 
117
126
  ## Example
118
127
 
package/lib/filesystem.js CHANGED
@@ -10,6 +10,8 @@ const {
10
10
  } = require('@putout/operate');
11
11
 
12
12
  const maybeFS = require('./maybe-fs');
13
+ const {isArray} = Array;
14
+ const maybeArray = (a) => isArray(a) ? a : [a];
13
15
 
14
16
  const {
15
17
  ObjectExpression,
@@ -39,12 +41,15 @@ module.exports.getParentDirectory = (filePath) => {
39
41
 
40
42
  module.exports.findFile = (node, name) => {
41
43
  const filePaths = [];
44
+ const names = maybeArray(name);
42
45
 
43
46
  for (const filenamePath of traverseProperties(node, 'filename')) {
44
47
  const {value} = filenamePath.node.value;
45
48
 
46
- if (value === name || getRegExp(name).test(value))
47
- filePaths.push(filenamePath.parentPath);
49
+ for (const name of names) {
50
+ if (value === name || getRegExp(name).test(value))
51
+ filePaths.push(filenamePath.parentPath);
52
+ }
48
53
  }
49
54
 
50
55
  return filePaths;
@@ -81,6 +86,7 @@ module.exports.renameFile = (filePath, name) => {
81
86
  const newName = name
82
87
  .split('/')
83
88
  .pop();
89
+
84
90
  const newFilename = oldName.replace(baseName, newName);
85
91
 
86
92
  setLiteralValue(valuePath, newFilename);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/operator-filesystem",
3
- "version": "2.2.0",
3
+ "version": "2.3.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",