@putout/operator-filesystem 2.0.0 → 2.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/lib/filesystem.js +24 -4
- package/package.json +4 -4
package/lib/filesystem.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
const tryCatch = require('try-catch');
|
|
3
4
|
const {types} = require('putout');
|
|
5
|
+
|
|
4
6
|
const {
|
|
5
7
|
setLiteralValue,
|
|
6
8
|
getProperty,
|
|
@@ -134,16 +136,26 @@ module.exports.createDirectory = (dirPath, name) => {
|
|
|
134
136
|
.at(-1);
|
|
135
137
|
};
|
|
136
138
|
|
|
139
|
+
const createContentProperty = (content) => {
|
|
140
|
+
const contentKey = StringLiteral('content');
|
|
141
|
+
const contentValue = StringLiteral(btoa(content));
|
|
142
|
+
|
|
143
|
+
return ObjectProperty(contentKey, contentValue);
|
|
144
|
+
};
|
|
145
|
+
|
|
137
146
|
module.exports.readFileContent = (filePath) => {
|
|
138
147
|
const [hasContent, content] = getFileContent(filePath);
|
|
139
148
|
|
|
140
|
-
if (hasContent)
|
|
141
|
-
|
|
149
|
+
if (hasContent) {
|
|
150
|
+
const [, decoded] = tryCatch(atob, content);
|
|
151
|
+
return decoded || content;
|
|
152
|
+
}
|
|
142
153
|
|
|
143
154
|
const filename = getFilename(filePath);
|
|
144
155
|
const fileContent = maybeFS.readFileContent(filename);
|
|
156
|
+
const property = createContentProperty(fileContent);
|
|
145
157
|
|
|
146
|
-
filePath.node.properties.push(
|
|
158
|
+
filePath.node.properties.push(property);
|
|
147
159
|
|
|
148
160
|
return fileContent;
|
|
149
161
|
};
|
|
@@ -153,7 +165,15 @@ module.exports.writeFileContent = (filePath, content) => {
|
|
|
153
165
|
|
|
154
166
|
maybeFS.writeFileContent(filename, content);
|
|
155
167
|
|
|
156
|
-
filePath
|
|
168
|
+
const contentPath = getProperty(filePath, 'content');
|
|
169
|
+
|
|
170
|
+
if (contentPath) {
|
|
171
|
+
contentPath.node.value.value = content;
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
const property = createContentProperty(content);
|
|
176
|
+
filePath.node.properties.push(property);
|
|
157
177
|
};
|
|
158
178
|
|
|
159
179
|
module.exports.init = maybeFS.init;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/operator-filesystem",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.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",
|
|
@@ -24,7 +24,8 @@
|
|
|
24
24
|
"report": "madrun report"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@putout/operate": "^11.0.0"
|
|
27
|
+
"@putout/operate": "^11.0.0",
|
|
28
|
+
"try-catch": "^3.0.1"
|
|
28
29
|
},
|
|
29
30
|
"keywords": [
|
|
30
31
|
"putout",
|
|
@@ -42,8 +43,7 @@
|
|
|
42
43
|
"madrun": "^9.0.0",
|
|
43
44
|
"montag": "^1.2.1",
|
|
44
45
|
"nodemon": "^3.0.1",
|
|
45
|
-
"supertape": "^8.0.0"
|
|
46
|
-
"try-catch": "^3.0.0"
|
|
46
|
+
"supertape": "^8.0.0"
|
|
47
47
|
},
|
|
48
48
|
"peerDependencies": {
|
|
49
49
|
"putout": ">=33"
|