@putout/operator-match-files 1.1.0 → 1.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/lib/match-files.js +26 -8
- package/package.json +2 -1
package/lib/match-files.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const {parse} = require('@putout/
|
|
4
|
-
const {print} = require('@putout/printer');
|
|
3
|
+
const {parse, print} = require('@putout/engine-parser');
|
|
5
4
|
const {transform} = require('putout/transform');
|
|
6
5
|
const {findPlaces} = require('putout/find-places');
|
|
7
6
|
|
|
@@ -30,13 +29,12 @@ module.exports.matchFiles = (files) => {
|
|
|
30
29
|
};
|
|
31
30
|
};
|
|
32
31
|
|
|
33
|
-
function fix({path, matchedJS, matchedAST, plugins}) {
|
|
32
|
+
function fix({filename, path, matchedJS, matchedAST, plugins}) {
|
|
34
33
|
transform(matchedAST, matchedJS, {
|
|
35
34
|
plugins,
|
|
36
35
|
});
|
|
37
36
|
|
|
38
|
-
const
|
|
39
|
-
const matchedJSON = fromJS(updatedMatchedJS);
|
|
37
|
+
const matchedJSON = magicPrint(filename, matchedAST);
|
|
40
38
|
|
|
41
39
|
writeFileContent(path, matchedJSON);
|
|
42
40
|
}
|
|
@@ -50,9 +48,7 @@ const createTraverse = (files) => ({push}) => ({
|
|
|
50
48
|
return;
|
|
51
49
|
|
|
52
50
|
const fileContent = readFileContent(filePath) || '{}';
|
|
53
|
-
|
|
54
|
-
const matchedJS = toJS(fileContent);
|
|
55
|
-
const matchedAST = parse(matchedJS);
|
|
51
|
+
const [matchedJS, matchedAST] = magicParse(filename, fileContent);
|
|
56
52
|
|
|
57
53
|
const plugins = [
|
|
58
54
|
[`match-file/${filename}`, plugin],
|
|
@@ -68,6 +64,7 @@ const createTraverse = (files) => ({push}) => ({
|
|
|
68
64
|
const {message} = places[0];
|
|
69
65
|
|
|
70
66
|
push({
|
|
67
|
+
filename,
|
|
71
68
|
message,
|
|
72
69
|
plugins,
|
|
73
70
|
path: filePath,
|
|
@@ -77,3 +74,24 @@ const createTraverse = (files) => ({push}) => ({
|
|
|
77
74
|
}
|
|
78
75
|
},
|
|
79
76
|
});
|
|
77
|
+
|
|
78
|
+
function magicParse(name, content) {
|
|
79
|
+
if (/\.json$/.test(name)) {
|
|
80
|
+
const js = toJS(content);
|
|
81
|
+
const ast = parse(js);
|
|
82
|
+
|
|
83
|
+
return [js, ast];
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return [content, parse(content)];
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function magicPrint(name, ast) {
|
|
90
|
+
if (/\.json$/.test(name)) {
|
|
91
|
+
const js = print(ast);
|
|
92
|
+
|
|
93
|
+
return fromJS(js);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
return print(ast);
|
|
97
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/operator-match-files",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.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",
|
|
@@ -38,6 +38,7 @@
|
|
|
38
38
|
"match-files"
|
|
39
39
|
],
|
|
40
40
|
"devDependencies": {
|
|
41
|
+
"@putout/plugin-nodejs": "*",
|
|
41
42
|
"@putout/test": "^7.0.0",
|
|
42
43
|
"c8": "^8.0.0",
|
|
43
44
|
"eslint": "^8.0.1",
|