@putout/operator-match-files 3.2.2 → 3.3.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/match-files.js +42 -30
- package/package.json +1 -1
package/lib/match-files.js
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const {
|
|
4
|
-
join,
|
|
5
|
-
basename,
|
|
6
|
-
extname,
|
|
7
|
-
} = require('node:path');
|
|
3
|
+
const {join, extname} = require('node:path');
|
|
8
4
|
|
|
9
5
|
const {parse, print} = require('@putout/engine-parser');
|
|
10
6
|
const {transform} = require('putout/transform');
|
|
@@ -38,44 +34,46 @@ module.exports.matchFiles = (files) => {
|
|
|
38
34
|
};
|
|
39
35
|
};
|
|
40
36
|
|
|
41
|
-
function fix(
|
|
37
|
+
function fix(inputFile, {dirPath, mainPath, matchInputFilename, outputFilename, matchedJS, matchedAST, plugins}) {
|
|
42
38
|
transform(matchedAST, matchedJS, {
|
|
43
39
|
plugins,
|
|
44
40
|
});
|
|
45
41
|
|
|
46
42
|
const matchedJSON = magicPrint(outputFilename, matchedAST);
|
|
43
|
+
const outputFile = getOutputFile(mainPath, {
|
|
44
|
+
dirPath,
|
|
45
|
+
matchInputFilename,
|
|
46
|
+
outputFilename,
|
|
47
|
+
inputFile,
|
|
48
|
+
});
|
|
47
49
|
|
|
48
|
-
writeFileContent(
|
|
50
|
+
writeFileContent(outputFile, matchedJSON);
|
|
49
51
|
|
|
50
|
-
if (
|
|
52
|
+
if (inputFile !== outputFile)
|
|
51
53
|
removeFile(inputFile);
|
|
52
54
|
}
|
|
53
55
|
|
|
54
|
-
const createScan = (files) => (
|
|
56
|
+
const createScan = (files) => (mainPath, {push, progress, options}) => {
|
|
55
57
|
const allFiles = [];
|
|
56
|
-
const cwd = getFilename(
|
|
58
|
+
const cwd = getFilename(mainPath);
|
|
57
59
|
|
|
58
60
|
for (const [filename, plugin] of entries(files)) {
|
|
59
61
|
const [matchInputFilename, outputFilename = matchInputFilename] = parseMatcher(filename, options);
|
|
60
|
-
const inputFiles = findFile(
|
|
62
|
+
const inputFiles = findFile(mainPath, matchInputFilename);
|
|
61
63
|
|
|
62
64
|
for (const inputFile of inputFiles) {
|
|
63
65
|
const dirPath = getParentDirectory(inputFile);
|
|
64
66
|
const inputFilename = getFilename(inputFile);
|
|
65
|
-
const outputFile = getOutputFile(path, {
|
|
66
|
-
dirPath,
|
|
67
|
-
matchInputFilename,
|
|
68
|
-
outputFilename,
|
|
69
|
-
inputFile,
|
|
70
|
-
});
|
|
71
67
|
|
|
72
68
|
if (ignores(cwd, inputFilename, options))
|
|
73
69
|
continue;
|
|
74
70
|
|
|
75
71
|
allFiles.push({
|
|
72
|
+
mainPath,
|
|
73
|
+
dirPath,
|
|
74
|
+
matchInputFilename,
|
|
76
75
|
plugin,
|
|
77
76
|
inputFile,
|
|
78
|
-
outputFile,
|
|
79
77
|
inputFilename,
|
|
80
78
|
outputFilename,
|
|
81
79
|
});
|
|
@@ -84,7 +82,17 @@ const createScan = (files) => (path, {push, progress, options}) => {
|
|
|
84
82
|
|
|
85
83
|
const n = allFiles.length;
|
|
86
84
|
|
|
87
|
-
for (const [i,
|
|
85
|
+
for (const [i, current] of allFiles.entries()) {
|
|
86
|
+
const {
|
|
87
|
+
dirPath,
|
|
88
|
+
matchInputFilename,
|
|
89
|
+
inputFile,
|
|
90
|
+
inputFilename,
|
|
91
|
+
outputFilename,
|
|
92
|
+
plugin,
|
|
93
|
+
mainPath,
|
|
94
|
+
} = current;
|
|
95
|
+
|
|
88
96
|
progress({
|
|
89
97
|
i,
|
|
90
98
|
n,
|
|
@@ -107,8 +115,11 @@ const createScan = (files) => (path, {push, progress, options}) => {
|
|
|
107
115
|
|
|
108
116
|
const {message} = places[0];
|
|
109
117
|
|
|
110
|
-
push(
|
|
111
|
-
|
|
118
|
+
push(inputFile, {
|
|
119
|
+
dirPath,
|
|
120
|
+
mainPath,
|
|
121
|
+
matchInputFilename,
|
|
122
|
+
|
|
112
123
|
outputFilename,
|
|
113
124
|
message,
|
|
114
125
|
plugins,
|
|
@@ -169,15 +180,16 @@ function getOutputFile(path, {dirPath, matchInputFilename, outputFilename, input
|
|
|
169
180
|
}
|
|
170
181
|
|
|
171
182
|
function parseMatcher(matcher, options) {
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
183
|
+
const {filename} = options;
|
|
184
|
+
|
|
185
|
+
if (!filename)
|
|
186
|
+
return matcher.split(' -> ');
|
|
187
|
+
|
|
188
|
+
const ext = extname(filename);
|
|
189
|
+
const shortName = filename.replace(ext, '');
|
|
190
|
+
|
|
191
|
+
matcher = matcher.replaceAll(`__name`, shortName);
|
|
192
|
+
matcher = matcher.replaceAll(`__ext`, ext);
|
|
181
193
|
|
|
182
194
|
return matcher.split(' -> ');
|
|
183
195
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/operator-match-files",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.3.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 match files to plugins",
|