@putout/operator-filesystem 2.1.0 → 2.2.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
@@ -13,7 +13,7 @@ npm i putout @putout/operator-filesystem
13
13
 
14
14
  ## API
15
15
 
16
- ## `createDirectory(directoryPath: Path, name: string)`
16
+ ## `createDirectory(directoryPath: FilePath, name: string): FilePath`
17
17
 
18
18
  ```js
19
19
  const {operator} = require('putout');
@@ -24,10 +24,10 @@ const {
24
24
 
25
25
  const [dirPath] = findFile(ast, 'hello');
26
26
 
27
- createDirectory(dirPath, 'world'); // returns directoryPath
27
+ const newDiretoryPath = createDirectory(dirPath, 'world');
28
28
  ```
29
29
 
30
- ## `findFile(path: Path, name: string)`
30
+ ## `findFile(path: Path, name: string): FilePath[]`
31
31
 
32
32
  ```js
33
33
  const {operator} = require('putout');
@@ -36,7 +36,7 @@ const {finedFiles, findFile} = operator;
36
36
  const [filePath] = findFile(ast, 'hello');
37
37
  ```
38
38
 
39
- ### `getFilename(path: Path)`
39
+ ### `getFilename(path: FilePath)`
40
40
 
41
41
  ```js
42
42
  const {operator} = require('putout');
@@ -54,7 +54,7 @@ const {removeFile} = operator;
54
54
  removeFile(filePath);
55
55
  ```
56
56
 
57
- ### `moveFile(filePath: Path, dirPath: Path)`
57
+ ### `moveFile(filePath: FilePath, dirPath: FilePath)`
58
58
 
59
59
  ```js
60
60
  const {operator} = require('putout');
@@ -63,7 +63,7 @@ const {moveFile} = operator;
63
63
  moveFile(filePath, dirPath);
64
64
  ```
65
65
 
66
- ### `readFileContent(filePath: Path)`
66
+ ### `readFileContent(filePath: FilePath)`
67
67
 
68
68
  ```js
69
69
  const {operator} = require('putout');
@@ -74,7 +74,7 @@ readFileContent(filePath);
74
74
  'hello';
75
75
  ```
76
76
 
77
- ### `writeFileContent(filePath: Path, content: string)`
77
+ ### `writeFileContent(filePath: FilePath, content: string)`
78
78
 
79
79
  ```js
80
80
  const {operator} = require('putout');
@@ -89,7 +89,32 @@ readFileContent(filePath);
89
89
  'hello';
90
90
  ```
91
91
 
92
- ### `renameFile(filePath: Path, name: string)`
92
+ ### `renameFile(filePath: FilePath, name: string)`
93
+
94
+ ```js
95
+ const {operator} = require('putout');
96
+ const {renameFile, findFile} = operator;
97
+
98
+ const [filePath] = findFile(path, 'README.md');
99
+
100
+ renameFile(filePath, 'readme.md');
101
+ ```
102
+
103
+ this is the same as:
104
+
105
+ ```
106
+ renameFile(filePath, '/any/path/here/readme.md');
107
+ ```
108
+
109
+ Since `basename` is used.
110
+
111
+ > The `path.basename()` method returns the last portion of a path, similar to the Unix basename command. Trailing directory separators are ignored.
112
+ >
113
+ > (c) [nodejs.org](https://nodejs.org/api/path.html#pathbasenamepath-suffix)
114
+
115
+ To move file use [`moveFile(file: FilePath, directory: FilePath)`](#movefilefilepath-filepath-dirpath-filepath);
116
+
117
+ ## Example
93
118
 
94
119
  ```js
95
120
  const montag = require('montag');
package/lib/filesystem.js CHANGED
@@ -78,10 +78,13 @@ module.exports.renameFile = (filePath, name) => {
78
78
  .split('/')
79
79
  .pop();
80
80
 
81
- const newName = oldName.replace(baseName, name);
81
+ const newName = name
82
+ .split('/')
83
+ .pop();
84
+ const newFilename = oldName.replace(baseName, newName);
82
85
 
83
- setLiteralValue(valuePath, newName);
84
- maybeFS.renameFile(oldName, newName);
86
+ setLiteralValue(valuePath, newFilename);
87
+ maybeFS.renameFile(oldName, newFilename);
85
88
  };
86
89
 
87
90
  module.exports.removeFile = (filePath) => {
@@ -168,7 +171,7 @@ module.exports.writeFileContent = (filePath, content) => {
168
171
  const contentPath = getProperty(filePath, 'content');
169
172
 
170
173
  if (contentPath) {
171
- contentPath.node.value.value = content;
174
+ setLiteralValue(contentPath.node.value, btoa(content));
172
175
  return;
173
176
  }
174
177
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/operator-filesystem",
3
- "version": "2.1.0",
3
+ "version": "2.2.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",
@@ -34,6 +34,7 @@
34
34
  "filesystem"
35
35
  ],
36
36
  "devDependencies": {
37
+ "@putout/operator-json": "^1.3.0",
37
38
  "@putout/test": "^7.0.0",
38
39
  "c8": "^8.0.0",
39
40
  "eslint": "^8.0.1",