@putout/operator-match-files 2.0.1 → 2.2.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 +15 -0
- package/lib/match-files.js +67 -38
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -48,6 +48,21 @@ And you want to help users avoid updating `.putout.json` config with:
|
|
|
48
48
|
}
|
|
49
49
|
```
|
|
50
50
|
|
|
51
|
+
If you want to pass options use:
|
|
52
|
+
|
|
53
|
+
```json
|
|
54
|
+
{
|
|
55
|
+
"match": {
|
|
56
|
+
"tsconfig.json": {
|
|
57
|
+
"nextjs/update-tsconfig": ["on", {
|
|
58
|
+
"ignore": []
|
|
59
|
+
}]
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
"plugins": ["nextjs"]
|
|
63
|
+
}
|
|
64
|
+
```
|
|
65
|
+
|
|
51
66
|
Instead of this, [`redlint`](https://github.com/putoutjs/redlint) can be used, it will generate `.filesystem.json` which can be processed by 🐊**Putout**.
|
|
52
67
|
|
|
53
68
|
## License
|
package/lib/match-files.js
CHANGED
|
@@ -3,35 +3,33 @@
|
|
|
3
3
|
const {parse, print} = require('@putout/engine-parser');
|
|
4
4
|
const {transform} = require('putout/transform');
|
|
5
5
|
const {findPlaces} = require('putout/find-places');
|
|
6
|
+
const ignores = require('putout/ignores');
|
|
6
7
|
|
|
7
|
-
const {
|
|
8
|
-
__filesystem,
|
|
9
|
-
toJS,
|
|
10
|
-
fromJS,
|
|
11
|
-
} = require('@putout/operator-json');
|
|
8
|
+
const {toJS, fromJS} = require('@putout/operator-json');
|
|
12
9
|
|
|
13
10
|
const {
|
|
14
11
|
readFileContent,
|
|
15
12
|
findFile,
|
|
16
13
|
writeFileContent,
|
|
14
|
+
getFilename,
|
|
17
15
|
} = require('@putout/operator-filesystem');
|
|
18
16
|
|
|
19
17
|
const isObject = (a) => a && typeof a === 'object';
|
|
20
18
|
const {entries} = Object;
|
|
21
|
-
const report = ({message}) => message;
|
|
19
|
+
const report = (path, {message}) => message;
|
|
22
20
|
|
|
23
21
|
module.exports.matchFiles = (files) => {
|
|
24
22
|
check(files);
|
|
25
|
-
const
|
|
23
|
+
const scan = createScan(files);
|
|
26
24
|
|
|
27
25
|
return {
|
|
28
26
|
fix,
|
|
29
|
-
|
|
27
|
+
scan,
|
|
30
28
|
report,
|
|
31
29
|
};
|
|
32
30
|
};
|
|
33
31
|
|
|
34
|
-
function fix({filename,
|
|
32
|
+
function fix(path, {filename, matchedJS, matchedAST, plugins}) {
|
|
35
33
|
transform(matchedAST, matchedJS, {
|
|
36
34
|
plugins,
|
|
37
35
|
});
|
|
@@ -41,41 +39,64 @@ function fix({filename, path, matchedJS, matchedAST, plugins}) {
|
|
|
41
39
|
writeFileContent(path, matchedJSON);
|
|
42
40
|
}
|
|
43
41
|
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
const
|
|
53
|
-
const [matchedJS, matchedAST] = magicParse(filename, fileContent);
|
|
54
|
-
|
|
55
|
-
const plugins = [
|
|
56
|
-
[`match-file/${filename}`, plugin],
|
|
57
|
-
];
|
|
58
|
-
|
|
59
|
-
const places = findPlaces(matchedAST, matchedJS, {
|
|
60
|
-
plugins,
|
|
61
|
-
});
|
|
42
|
+
const createScan = (files) => (path, {push, progress, options}) => {
|
|
43
|
+
const allFiles = [];
|
|
44
|
+
const cwd = getFilename(path);
|
|
45
|
+
|
|
46
|
+
for (const [filename, plugin] of entries(files)) {
|
|
47
|
+
const files = findFile(path, filename);
|
|
48
|
+
|
|
49
|
+
for (const file of files) {
|
|
50
|
+
const filename = getFilename(file);
|
|
62
51
|
|
|
63
|
-
if (
|
|
52
|
+
if (ignores(cwd, filename, options))
|
|
64
53
|
continue;
|
|
65
54
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
55
|
+
allFiles.push({
|
|
56
|
+
plugin,
|
|
57
|
+
file,
|
|
69
58
|
filename,
|
|
70
|
-
message,
|
|
71
|
-
plugins,
|
|
72
|
-
path: filePath,
|
|
73
|
-
matchedAST,
|
|
74
|
-
matchedJS,
|
|
75
59
|
});
|
|
76
60
|
}
|
|
77
|
-
}
|
|
78
|
-
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const n = allFiles.length;
|
|
64
|
+
|
|
65
|
+
for (const [i, {file, filename, plugin}] of allFiles.entries()) {
|
|
66
|
+
progress({
|
|
67
|
+
i,
|
|
68
|
+
n,
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
const fileContent = readFileContent(file) || '{}';
|
|
72
|
+
const [matchedJS, matchedAST] = magicParse(filename, fileContent);
|
|
73
|
+
|
|
74
|
+
const plugins = [
|
|
75
|
+
[
|
|
76
|
+
`match-file/${filename}`,
|
|
77
|
+
plugin,
|
|
78
|
+
],
|
|
79
|
+
];
|
|
80
|
+
|
|
81
|
+
const places = findPlaces(matchedAST, matchedJS, {
|
|
82
|
+
plugins,
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
if (!places.length)
|
|
86
|
+
continue;
|
|
87
|
+
|
|
88
|
+
const {message} = places[0];
|
|
89
|
+
|
|
90
|
+
push(file, {
|
|
91
|
+
filename,
|
|
92
|
+
message,
|
|
93
|
+
plugins,
|
|
94
|
+
|
|
95
|
+
matchedAST,
|
|
96
|
+
matchedJS,
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
};
|
|
79
100
|
|
|
80
101
|
function magicParse(name, content) {
|
|
81
102
|
if (/\.json$/.test(name)) {
|
|
@@ -85,6 +106,14 @@ function magicParse(name, content) {
|
|
|
85
106
|
return [js, ast];
|
|
86
107
|
}
|
|
87
108
|
|
|
109
|
+
if (/\.(c|m)?ts(x)?$/.test(name)) {
|
|
110
|
+
const ast = parse(content, {
|
|
111
|
+
isTS: true,
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
return [content, ast];
|
|
115
|
+
}
|
|
116
|
+
|
|
88
117
|
return [content, parse(content)];
|
|
89
118
|
}
|
|
90
119
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/operator-match-files",
|
|
3
|
-
"version": "2.0
|
|
3
|
+
"version": "2.2.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",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"report": "madrun report"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@putout/babel": "^
|
|
27
|
+
"@putout/babel": "^2.0.0",
|
|
28
28
|
"@putout/engine-parser": "^10.0.2",
|
|
29
29
|
"@putout/operator-filesystem": "^3.0.0",
|
|
30
30
|
"@putout/operator-json": "^1.3.0"
|