Skip to content

Commit 9975fe8

Browse files
committed
feature: @putout/operator-filesystem: property: move out
1 parent 78c27f3 commit 9975fe8

File tree

2 files changed

+43
-20
lines changed

2 files changed

+43
-20
lines changed

packages/operator-filesystem/lib/filesystem.js

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,13 @@ const {
1818
const maybeFS = require('./maybe-fs');
1919

2020
const {
21-
arrayExpression,
22-
stringLiteral,
23-
objectProperty,
21+
createTypeProperty,
22+
createFilesProperty,
23+
createFilenameProperty,
24+
createContentProperty,
25+
} = require('./property');
26+
27+
const {
2428
isProgram,
2529
objectExpression,
2630
} = types;
@@ -261,22 +265,6 @@ function maybeRemoveFile(dirPath, filename) {
261265
fileToOverwrite.remove();
262266
}
263267

264-
const createTypeProperty = (type) => objectProperty(stringLiteral('type'), stringLiteral(type));
265-
266-
module.exports.createTypeProperty = createTypeProperty;
267-
268-
const createFilesProperty = (files) => objectProperty(stringLiteral('files'), arrayExpression(files));
269-
270-
module.exports.createFilesProperty = createFilesProperty;
271-
272-
const createFilenameProperty = (filename) => objectProperty(stringLiteral('filename'), stringLiteral(filename));
273-
274-
module.exports.createFilenameProperty = createFilenameProperty;
275-
276-
const createContentProperty = (content) => objectProperty(stringLiteral('content'), stringLiteral(content));
277-
278-
module.exports.createContentProperty = createContentProperty;
279-
280268
module.exports.createFile = (dirPath, name, content) => {
281269
maybeRemoveFile(dirPath, name);
282270

@@ -416,7 +404,9 @@ module.exports.createNestedDirectory = (path, name) => {
416404

417405
const n = directories.length;
418406

419-
for (let i = directories.indexOf(lastDirectoryName) + 1; i < n; i++) {
407+
let i = directories.indexOf(lastDirectoryName) + 1;
408+
409+
for (; i < n; i++) {
420410
const name = basename(directories[i]);
421411
lastDirectoryPath = createDirectory(lastDirectoryPath, name);
422412
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
'use strict';
2+
3+
const {types} = require('@putout/babel');
4+
const {
5+
arrayExpression,
6+
stringLiteral,
7+
objectProperty,
8+
} = types;
9+
10+
module.exports.createTypeProperty = (type) => {
11+
const value = stringLiteral(type);
12+
return createProperty('type', value);
13+
};
14+
15+
module.exports.createFilesProperty = (files) => {
16+
const value = arrayExpression(files);
17+
return createProperty('files', value);
18+
};
19+
20+
module.exports.createFilenameProperty = (filename) => {
21+
const value = stringLiteral(filename);
22+
return createProperty('filename', value);
23+
};
24+
25+
module.exports.createContentProperty = (content) => {
26+
const value = stringLiteral(content);
27+
return createProperty('content', value);
28+
};
29+
30+
function createProperty(name, value) {
31+
const key = stringLiteral(name);
32+
return objectProperty(key, value);
33+
}

0 commit comments

Comments
 (0)