@putout/operator-filesystem 10.0.3 → 10.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 +12 -1
- package/lib/filesystem.js +8 -0
- package/lib/maybe-fs.js +1 -1
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -102,7 +102,7 @@ readDirectory(dirPath);
|
|
|
102
102
|
|
|
103
103
|
```js
|
|
104
104
|
const {operator} = require('putout');
|
|
105
|
-
const {
|
|
105
|
+
const {findFile} = operator;
|
|
106
106
|
|
|
107
107
|
const [filePath] = findFile(ast, 'hello');
|
|
108
108
|
```
|
|
@@ -135,6 +135,17 @@ const {findFile} = operator;
|
|
|
135
135
|
const coupleFiles = findFile(ast, ['/home/coderaiser', '/home/coderaiser/putout']);
|
|
136
136
|
```
|
|
137
137
|
|
|
138
|
+
### `findFirstFileUp(directoryPath: DirectoryPath, name: string): [directory, FilePath]`
|
|
139
|
+
|
|
140
|
+
Find first file with `name` in all parent directories.
|
|
141
|
+
|
|
142
|
+
```js
|
|
143
|
+
const {operator} = require('putout');
|
|
144
|
+
const {findFileUp} = operator;
|
|
145
|
+
|
|
146
|
+
const [directory, filePath] = findFirstFileUp(ast, 'package.json');
|
|
147
|
+
```
|
|
148
|
+
|
|
138
149
|
### `getParentDirectory(path: FilePath | DirectoryPath): FilePath | null`
|
|
139
150
|
|
|
140
151
|
```js
|
package/lib/filesystem.js
CHANGED
|
@@ -137,9 +137,17 @@ export function getFileContent(filePath) {
|
|
|
137
137
|
];
|
|
138
138
|
}
|
|
139
139
|
|
|
140
|
+
function checkRenameFileName(name) {
|
|
141
|
+
if (!isString(name))
|
|
142
|
+
throw Error(`☝️ Looks like you forget to pass the 'name' of a file to 'renameFile(filePath: FilePath, name: string)'`);
|
|
143
|
+
}
|
|
144
|
+
|
|
140
145
|
export const renameFile = (filePath, name) => {
|
|
146
|
+
checkRenameFileName(name);
|
|
147
|
+
|
|
141
148
|
const oldName = getFilename(filePath);
|
|
142
149
|
const valuePath = getFilenamePath(filePath);
|
|
150
|
+
|
|
143
151
|
const baseName = oldName
|
|
144
152
|
.split('/')
|
|
145
153
|
.pop();
|
package/lib/maybe-fs.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/operator-filesystem",
|
|
3
|
-
"version": "10.0
|
|
3
|
+
"version": "10.1.0",
|
|
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",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"@putout/babel": "^5.0.0",
|
|
28
28
|
"@putout/operate": "^15.0.0",
|
|
29
|
-
"fullstore": "^
|
|
29
|
+
"fullstore": "^4.0.0",
|
|
30
30
|
"try-catch": "^4.0.0"
|
|
31
31
|
},
|
|
32
32
|
"keywords": [
|
|
@@ -37,13 +37,13 @@
|
|
|
37
37
|
],
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"@putout/engine-parser": "^15.0.1",
|
|
40
|
-
"@putout/eslint-flat": "^
|
|
40
|
+
"@putout/eslint-flat": "^4.0.0",
|
|
41
41
|
"@putout/operator-json": "^3.0.0",
|
|
42
42
|
"@putout/test": "^15.0.0",
|
|
43
43
|
"c8": "^10.0.0",
|
|
44
44
|
"eslint": "^10.0.0-alpha.0",
|
|
45
45
|
"eslint-plugin-n": "^17.0.0",
|
|
46
|
-
"eslint-plugin-putout": "^
|
|
46
|
+
"eslint-plugin-putout": "^30.0.0",
|
|
47
47
|
"madrun": "^12.0.0",
|
|
48
48
|
"montag": "^1.2.1",
|
|
49
49
|
"nodemon": "^3.0.1",
|