@putout/operator-filesystem 3.5.0 → 3.7.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 +20 -17
- package/lib/filesystem.js +9 -1
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -17,28 +17,12 @@ npm i putout @putout/operator-filesystem
|
|
|
17
17
|
|
|
18
18
|
```js
|
|
19
19
|
const {operator} = require('putout');
|
|
20
|
-
const {
|
|
21
|
-
createDirectory,
|
|
22
|
-
findFile,
|
|
23
|
-
createFile,
|
|
24
|
-
} = operator;
|
|
20
|
+
const {findFile, createFile} = operator;
|
|
25
21
|
|
|
26
22
|
const [dirPath] = findFile(ast, 'hello');
|
|
27
23
|
const filePath = createFile(dirPath, 'world.txt', 'hello world');
|
|
28
24
|
```
|
|
29
25
|
|
|
30
|
-
```js
|
|
31
|
-
const {operator} = require('putout');
|
|
32
|
-
const {
|
|
33
|
-
createDirectory,
|
|
34
|
-
findFile,
|
|
35
|
-
} = operator;
|
|
36
|
-
|
|
37
|
-
const [dirPath] = findFile(ast, 'hello');
|
|
38
|
-
|
|
39
|
-
const newDirectoryPath = createDirectory(dirPath, 'world');
|
|
40
|
-
```
|
|
41
|
-
|
|
42
26
|
### `createDirectory(directoryPath: FilePath, name: string): FilePath`
|
|
43
27
|
|
|
44
28
|
```js
|
|
@@ -80,6 +64,25 @@ const {findFile} = operator;
|
|
|
80
64
|
const coupleFiles = findFile(ast, ['/home/coderaiser', '/home/coderaiser/putout']);
|
|
81
65
|
```
|
|
82
66
|
|
|
67
|
+
### `getParentDirectory(filePath: FilePath): FilePath|null`
|
|
68
|
+
|
|
69
|
+
```js
|
|
70
|
+
const {operator} = require('putout');
|
|
71
|
+
const {
|
|
72
|
+
createDirectory,
|
|
73
|
+
findFile,
|
|
74
|
+
getParentDirectory,
|
|
75
|
+
} = operator;
|
|
76
|
+
|
|
77
|
+
const [dirPath] = findFile(ast, 'hello');
|
|
78
|
+
|
|
79
|
+
const newDirectoryPath = createDirectory(dirPath, 'world');
|
|
80
|
+
|
|
81
|
+
dirPath === getParentDirectory(newDirectoryPath);
|
|
82
|
+
// returns
|
|
83
|
+
true;
|
|
84
|
+
```
|
|
85
|
+
|
|
83
86
|
### `getFilename(path: FilePath): string`
|
|
84
87
|
|
|
85
88
|
```js
|
package/lib/filesystem.js
CHANGED
|
@@ -188,6 +188,13 @@ module.exports.copyFile = (filePath, dirPath) => {
|
|
|
188
188
|
};
|
|
189
189
|
|
|
190
190
|
function maybeRemoveFile(dirPath, filename) {
|
|
191
|
+
const type = getFileType(dirPath);
|
|
192
|
+
|
|
193
|
+
if (type !== 'directory') {
|
|
194
|
+
const filename = getFilename(dirPath);
|
|
195
|
+
throw Error(`☝️ Looks like '${filename}' is not a directory, but: '${type}'. Rename to '${filename}/'`);
|
|
196
|
+
}
|
|
197
|
+
|
|
191
198
|
const dirPathFiles = getProperty(dirPath, 'files');
|
|
192
199
|
const [fileToOverwrite] = findFile(dirPathFiles, filename);
|
|
193
200
|
|
|
@@ -280,7 +287,8 @@ module.exports.readFileContent = (filePath) => {
|
|
|
280
287
|
|
|
281
288
|
const filename = getFilename(filePath);
|
|
282
289
|
const fileContent = maybeFS.readFileContent(filename);
|
|
283
|
-
|
|
290
|
+
|
|
291
|
+
const property = createContentProperty(toBase64(fileContent));
|
|
284
292
|
|
|
285
293
|
filePath.node.properties.push(property);
|
|
286
294
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/operator-filesystem",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.7.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",
|
|
@@ -39,9 +39,9 @@
|
|
|
39
39
|
"@putout/engine-parser": "^10.0.2",
|
|
40
40
|
"@putout/operator-json": "^1.3.0",
|
|
41
41
|
"@putout/test": "^8.0.0",
|
|
42
|
-
"c8": "^
|
|
43
|
-
"eslint": "^
|
|
44
|
-
"eslint-plugin-n": "^
|
|
42
|
+
"c8": "^9.0.0",
|
|
43
|
+
"eslint": "^9.0.0-alpha.0",
|
|
44
|
+
"eslint-plugin-n": "^17.0.0-0",
|
|
45
45
|
"eslint-plugin-putout": "^22.0.0",
|
|
46
46
|
"lerna": "^6.0.1",
|
|
47
47
|
"madrun": "^10.0.0",
|