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