@putout/operator-filesystem 2.4.0 → 2.6.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 +1 -1
- package/lib/filesystem.js +24 -14
- package/package.json +1 -1
package/README.md
CHANGED
package/lib/filesystem.js
CHANGED
|
@@ -120,13 +120,14 @@ module.exports.moveFile = (filePath, dirPath) => {
|
|
|
120
120
|
.pop();
|
|
121
121
|
|
|
122
122
|
const newname = `${dirname}/${basename}`;
|
|
123
|
-
const [is] = getFile(dirPathFiles, newname);
|
|
123
|
+
const [is, fileToOverwrite] = getFile(dirPathFiles, newname);
|
|
124
124
|
|
|
125
|
-
if (
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
125
|
+
if (is)
|
|
126
|
+
fileToOverwrite.remove();
|
|
127
|
+
|
|
128
|
+
setLiteralValue(filenamePath.get('value'), newname);
|
|
129
|
+
dirPathFiles.node.value.elements.push(filePath.node);
|
|
130
|
+
filePath.remove();
|
|
130
131
|
|
|
131
132
|
maybeFS.renameFile(filename, newname);
|
|
132
133
|
};
|
|
@@ -141,16 +142,20 @@ module.exports.copyFile = (filePath, dirPath) => {
|
|
|
141
142
|
.pop();
|
|
142
143
|
|
|
143
144
|
const newFilename = `${dirname}/${basename}`;
|
|
145
|
+
const [hasContent, content] = getFileContent(filePath);
|
|
144
146
|
|
|
145
|
-
const
|
|
147
|
+
const copiedFile = ObjectExpression([
|
|
146
148
|
createType('file'),
|
|
147
149
|
createFilename(newFilename),
|
|
148
|
-
|
|
150
|
+
hasContent && createContent(content),
|
|
151
|
+
].filter(Boolean));
|
|
149
152
|
|
|
150
|
-
const [is] = getFile(dirPathFiles, newFilename);
|
|
153
|
+
const [is, fileToOverwrite] = getFile(dirPathFiles, newFilename);
|
|
151
154
|
|
|
152
|
-
if (
|
|
153
|
-
|
|
155
|
+
if (is)
|
|
156
|
+
fileToOverwrite.remove();
|
|
157
|
+
|
|
158
|
+
dirPathFiles.node.value.elements.push(copiedFile);
|
|
154
159
|
|
|
155
160
|
maybeFS.copyFile(filename, newFilename);
|
|
156
161
|
};
|
|
@@ -158,6 +163,7 @@ module.exports.copyFile = (filePath, dirPath) => {
|
|
|
158
163
|
const createType = (type) => ObjectProperty(StringLiteral('type'), StringLiteral(type));
|
|
159
164
|
const createFiles = (files) => ObjectProperty(StringLiteral('files'), ArrayExpression(files));
|
|
160
165
|
const createFilename = (filename) => ObjectProperty(StringLiteral('filename'), StringLiteral(filename));
|
|
166
|
+
const createContent = (content) => ObjectProperty(StringLiteral('content'), StringLiteral(content));
|
|
161
167
|
|
|
162
168
|
module.exports.createDirectory = (dirPath, name) => {
|
|
163
169
|
const dirPathFiles = getProperty(dirPath, 'files');
|
|
@@ -183,7 +189,7 @@ module.exports.createDirectory = (dirPath, name) => {
|
|
|
183
189
|
|
|
184
190
|
const createContentProperty = (content) => {
|
|
185
191
|
const contentKey = StringLiteral('content');
|
|
186
|
-
const contentValue = StringLiteral(btoa(content));
|
|
192
|
+
const contentValue = StringLiteral(btoa(encodeURI(content)));
|
|
187
193
|
|
|
188
194
|
return ObjectProperty(contentKey, contentValue);
|
|
189
195
|
};
|
|
@@ -192,8 +198,12 @@ module.exports.readFileContent = (filePath) => {
|
|
|
192
198
|
const [hasContent, content] = getFileContent(filePath);
|
|
193
199
|
|
|
194
200
|
if (hasContent) {
|
|
195
|
-
const [, decoded] = tryCatch(atob, content);
|
|
196
|
-
|
|
201
|
+
const [e, decoded] = tryCatch(atob, content);
|
|
202
|
+
|
|
203
|
+
if (!e)
|
|
204
|
+
return decodeURI(decoded);
|
|
205
|
+
|
|
206
|
+
return content;
|
|
197
207
|
}
|
|
198
208
|
|
|
199
209
|
const filename = getFilename(filePath);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/operator-filesystem",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.6.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",
|