@putout/operator-filesystem 2.8.0 → 2.9.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 +7 -16
- package/package.json +1 -1
package/lib/filesystem.js
CHANGED
|
@@ -102,15 +102,6 @@ module.exports.removeFile = (filePath) => {
|
|
|
102
102
|
maybeFS.removeFile(filename);
|
|
103
103
|
};
|
|
104
104
|
|
|
105
|
-
function getFile(dirPathFiles, name) {
|
|
106
|
-
for (const file of dirPathFiles.get('value.elements')) {
|
|
107
|
-
if (name === getFilename(file))
|
|
108
|
-
return file;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
return null;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
105
|
module.exports.moveFile = (filePath, dirPath) => {
|
|
115
106
|
const dirname = getFilename(dirPath);
|
|
116
107
|
const filename = getFilename(filePath);
|
|
@@ -159,8 +150,7 @@ module.exports.copyFile = (filePath, dirPath) => {
|
|
|
159
150
|
|
|
160
151
|
function maybeRemoveFile(dirPath, filename) {
|
|
161
152
|
const dirPathFiles = getProperty(dirPath, 'files');
|
|
162
|
-
|
|
163
|
-
const fileToOverwrite = getFile(dirPathFiles, filename);
|
|
153
|
+
const [fileToOverwrite] = findFile(dirPathFiles, filename);
|
|
164
154
|
|
|
165
155
|
if (!fileToOverwrite)
|
|
166
156
|
return;
|
|
@@ -173,7 +163,7 @@ const createFiles = (files) => ObjectProperty(StringLiteral('files'), ArrayExpre
|
|
|
173
163
|
const createFilename = (filename) => ObjectProperty(StringLiteral('filename'), StringLiteral(filename));
|
|
174
164
|
const createContent = (content) => ObjectProperty(StringLiteral('content'), StringLiteral(content));
|
|
175
165
|
|
|
176
|
-
module.exports.createFile = (dirPath, name, content) => {
|
|
166
|
+
module.exports.createFile = (dirPath, name, content = '') => {
|
|
177
167
|
maybeRemoveFile(dirPath, name);
|
|
178
168
|
|
|
179
169
|
const dirPathFiles = getFiles(dirPath);
|
|
@@ -183,14 +173,13 @@ module.exports.createFile = (dirPath, name, content) => {
|
|
|
183
173
|
const typeProperty = createType('file');
|
|
184
174
|
const filenameProperty = createFilename(filename);
|
|
185
175
|
|
|
186
|
-
dirPathFiles.node.value.elements.push(ObjectExpression([typeProperty, filenameProperty]));
|
|
176
|
+
dirPathFiles.node.value.elements.push(ObjectExpression([typeProperty, filenameProperty, createContent(content)]));
|
|
187
177
|
|
|
188
178
|
const filePath = dirPathFiles
|
|
189
179
|
.get('value.elements')
|
|
190
180
|
.at(-1);
|
|
191
181
|
|
|
192
|
-
|
|
193
|
-
writeFileContent(filePath, content);
|
|
182
|
+
writeFileContent(filePath, content);
|
|
194
183
|
|
|
195
184
|
return filePath;
|
|
196
185
|
};
|
|
@@ -265,5 +254,7 @@ function writeFileContent(filePath, content) {
|
|
|
265
254
|
|
|
266
255
|
const property = createContentProperty(content);
|
|
267
256
|
filePath.node.properties.push(property);
|
|
268
|
-
}
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
module.exports.init = maybeFS.init;
|
|
269
260
|
module.exports.deinit = maybeFS.deinit;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/operator-filesystem",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.9.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",
|