@putout/operator-match-files 2.3.0 → 2.4.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 CHANGED
@@ -65,6 +65,8 @@ If you want to pass options use:
65
65
 
66
66
  Instead of this, [`redlint`](https://github.com/putoutjs/redlint) can be used, it will generate `.filesystem.json` which can be processed by 🐊**Putout**.
67
67
 
68
+ ### Rename
69
+
68
70
  If you want to save with other name use `->`:
69
71
 
70
72
  ```js
@@ -77,6 +79,32 @@ module.exports = matchFiles({
77
79
  });
78
80
  ```
79
81
 
82
+ ### Matcher
83
+
84
+ You can even use file matchers:
85
+
86
+ ```json
87
+ {
88
+ "rules": {
89
+ "filesystem/convert-json-to-js": ["on", {
90
+ "filename": "package.json"
91
+ }]
92
+ }
93
+ }
94
+ ```
95
+
96
+ Matchers: `__filename = __name.__ext`
97
+
98
+ ```js
99
+ const {operator} = require('putout');
100
+ const {matchFiles} = operator;
101
+ const updateTSConfig = require('../update-tsconfig');
102
+
103
+ module.exports = matchFiles({
104
+ '__name.json -> __name.js': updateTSConfig,
105
+ });
106
+ ```
107
+
80
108
  ## License
81
109
 
82
110
  MIT
@@ -46,7 +46,7 @@ const createScan = (files) => (path, {push, progress, options}) => {
46
46
  const cwd = getFilename(path);
47
47
 
48
48
  for (const [filename, plugin] of entries(files)) {
49
- const [matchInputFilename, outputFilename = matchInputFilename] = filename.split(' -> ');
49
+ const [matchInputFilename, outputFilename = matchInputFilename] = parseMatcher(filename, options);
50
50
  const inputFiles = findFile(path, matchInputFilename);
51
51
 
52
52
  for (const inputFile of inputFiles) {
@@ -157,3 +157,16 @@ function getOutputFile(path, {dirPath, matchInputFilename, outputFilename, input
157
157
 
158
158
  return createFile(dirPath, outputFilename);
159
159
  }
160
+
161
+ function parseMatcher(matcher, options) {
162
+ for (const [name, value] of entries(options)) {
163
+ if (name === 'filename') {
164
+ const [name, ext] = value.split('.');
165
+
166
+ matcher = matcher.replaceAll(`__name`, name);
167
+ matcher = matcher.replaceAll(`__ext`, ext);
168
+ }
169
+ }
170
+
171
+ return matcher.split(' -> ');
172
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/operator-match-files",
3
- "version": "2.3.0",
3
+ "version": "2.4.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,7 +38,7 @@
38
38
  "devDependencies": {
39
39
  "@putout/plugin-nodejs": "*",
40
40
  "@putout/test": "^8.0.0",
41
- "c8": "^8.0.0",
41
+ "c8": "^9.0.0",
42
42
  "eslint": "^9.0.0-alpha.0",
43
43
  "eslint-plugin-n": "^16.0.0",
44
44
  "eslint-plugin-putout": "^22.0.0",