@putout/operator-filesystem 3.1.0 → 3.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/lib/filesystem.js +14 -2
- package/package.json +1 -1
package/lib/filesystem.js
CHANGED
|
@@ -76,10 +76,12 @@ function getFilename(filePath) {
|
|
|
76
76
|
return value;
|
|
77
77
|
}
|
|
78
78
|
|
|
79
|
-
module.exports.getFileType =
|
|
79
|
+
module.exports.getFileType = getFileType;
|
|
80
|
+
|
|
81
|
+
function getFileType(filePath) {
|
|
80
82
|
const typePath = getProperty(filePath, 'type');
|
|
81
83
|
return typePath.node.value.value;
|
|
82
|
-
}
|
|
84
|
+
}
|
|
83
85
|
|
|
84
86
|
function getFileContent(filePath) {
|
|
85
87
|
const content = getProperty(filePath, 'content');
|
|
@@ -235,6 +237,11 @@ const createContentProperty = (content) => {
|
|
|
235
237
|
};
|
|
236
238
|
|
|
237
239
|
module.exports.readFileContent = (filePath) => {
|
|
240
|
+
const fileType = getFileType(filePath);
|
|
241
|
+
|
|
242
|
+
if (fileType === 'directory')
|
|
243
|
+
return '';
|
|
244
|
+
|
|
238
245
|
const [hasContent, content] = getFileContent(filePath);
|
|
239
246
|
|
|
240
247
|
if (hasContent) {
|
|
@@ -258,6 +265,11 @@ module.exports.readFileContent = (filePath) => {
|
|
|
258
265
|
module.exports.writeFileContent = writeFileContent;
|
|
259
266
|
|
|
260
267
|
function writeFileContent(filePath, content) {
|
|
268
|
+
const fileType = getFileType(filePath);
|
|
269
|
+
|
|
270
|
+
if (fileType === 'directory')
|
|
271
|
+
return;
|
|
272
|
+
|
|
261
273
|
const filename = getFilename(filePath);
|
|
262
274
|
|
|
263
275
|
maybeFS.writeFileContent(filename, content);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/operator-filesystem",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.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",
|