@putout/operator-filesystem 3.2.0 → 3.4.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 +19 -10
- package/package.json +1 -1
package/lib/filesystem.js
CHANGED
|
@@ -15,6 +15,16 @@ const isString = (a) => typeof a === 'string';
|
|
|
15
15
|
const {isArray} = Array;
|
|
16
16
|
const maybeArray = (a) => isArray(a) ? a : [a];
|
|
17
17
|
|
|
18
|
+
const toBase64 = (a) => btoa(encodeURI(a));
|
|
19
|
+
const fromBase64 = (content) => {
|
|
20
|
+
const [e, decoded] = tryCatch(atob, content);
|
|
21
|
+
|
|
22
|
+
if (!e)
|
|
23
|
+
return decodeURI(decoded);
|
|
24
|
+
|
|
25
|
+
return content;
|
|
26
|
+
};
|
|
27
|
+
|
|
18
28
|
const {
|
|
19
29
|
ObjectExpression,
|
|
20
30
|
ArrayExpression,
|
|
@@ -231,7 +241,7 @@ module.exports.createDirectory = (dirPath, name) => {
|
|
|
231
241
|
|
|
232
242
|
const createContentProperty = (content) => {
|
|
233
243
|
const contentKey = StringLiteral('content');
|
|
234
|
-
const contentValue = StringLiteral(
|
|
244
|
+
const contentValue = StringLiteral(toBase64(content));
|
|
235
245
|
|
|
236
246
|
return ObjectProperty(contentKey, contentValue);
|
|
237
247
|
};
|
|
@@ -244,14 +254,8 @@ module.exports.readFileContent = (filePath) => {
|
|
|
244
254
|
|
|
245
255
|
const [hasContent, content] = getFileContent(filePath);
|
|
246
256
|
|
|
247
|
-
if (hasContent)
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
if (!e)
|
|
251
|
-
return decodeURI(decoded);
|
|
252
|
-
|
|
253
|
-
return content;
|
|
254
|
-
}
|
|
257
|
+
if (hasContent)
|
|
258
|
+
return fromBase64(content);
|
|
255
259
|
|
|
256
260
|
const filename = getFilename(filePath);
|
|
257
261
|
const fileContent = maybeFS.readFileContent(filename);
|
|
@@ -265,6 +269,11 @@ module.exports.readFileContent = (filePath) => {
|
|
|
265
269
|
module.exports.writeFileContent = writeFileContent;
|
|
266
270
|
|
|
267
271
|
function writeFileContent(filePath, content) {
|
|
272
|
+
const fileType = getFileType(filePath);
|
|
273
|
+
|
|
274
|
+
if (fileType === 'directory')
|
|
275
|
+
return;
|
|
276
|
+
|
|
268
277
|
const filename = getFilename(filePath);
|
|
269
278
|
|
|
270
279
|
maybeFS.writeFileContent(filename, content);
|
|
@@ -272,7 +281,7 @@ function writeFileContent(filePath, content) {
|
|
|
272
281
|
const contentPath = getProperty(filePath, 'content');
|
|
273
282
|
|
|
274
283
|
if (contentPath) {
|
|
275
|
-
setLiteralValue(contentPath.node.value,
|
|
284
|
+
setLiteralValue(contentPath.node.value, toBase64(content));
|
|
276
285
|
return;
|
|
277
286
|
}
|
|
278
287
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/operator-filesystem",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.4.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",
|