@putout/operator-match-files 5.0.0 → 5.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 CHANGED
@@ -101,6 +101,23 @@ module.exports = matchFiles({
101
101
  });
102
102
  ```
103
103
 
104
+ ### Exclude
105
+
106
+ If you want to exclude some files, use:
107
+
108
+ ```js
109
+ const {operator} = require('putout');
110
+ const {matchFiles} = operator;
111
+ const updateTSConfig = require('../update-tsconfig');
112
+
113
+ module.exports = matchFiles({
114
+ files: {
115
+ '__name.ts -> __name.js': updateTSConfig,
116
+ },
117
+ exclude: ['*.d.ts'],
118
+ });
119
+ ```
120
+
104
121
  ### Options
105
122
 
106
123
  You can also pass `options`:
@@ -25,9 +25,16 @@ const isObject = (a) => a && typeof a === 'object';
25
25
  const {entries} = Object;
26
26
  const report = (path, {message}) => message;
27
27
 
28
- module.exports.matchFiles = (files) => {
28
+ module.exports.matchFiles = (options) => {
29
+ const files = options.files ?? options;
30
+ const exclude = options.exclude ?? [];
31
+
29
32
  check(files);
30
- const scan = createScan(files);
33
+
34
+ const scan = createScan({
35
+ files,
36
+ exclude,
37
+ });
31
38
 
32
39
  return {
33
40
  fix,
@@ -36,11 +43,11 @@ module.exports.matchFiles = (files) => {
36
43
  };
37
44
  };
38
45
 
39
- function fix(inputFile, {dirPath, mainPath, matchInputFilename, outputFilename, matchedJS, matchedAST, options}) {
46
+ function fix(inputFile, {dirPath, matchInputFilename, outputFilename, matchedJS, matchedAST, options}) {
40
47
  transform(matchedAST, matchedJS, options);
41
48
 
42
49
  const matchedJSON = magicPrint(outputFilename, matchedAST);
43
- const outputFile = getOutputFile(mainPath, {
50
+ const outputFile = getOutputFile({
44
51
  dirPath,
45
52
  matchInputFilename,
46
53
  outputFilename,
@@ -53,23 +60,26 @@ function fix(inputFile, {dirPath, mainPath, matchInputFilename, outputFilename,
53
60
  removeFile(inputFile);
54
61
  }
55
62
 
56
- const createScan = (files) => (mainPath, {push, progress, options}) => {
63
+ const createScan = ({files, exclude}) => (mainPath, {push, progress, options}) => {
57
64
  const allFiles = [];
58
65
  const cwd = getFilename(mainPath);
59
66
 
60
67
  for (const [filename, rawOptions] of entries(files)) {
61
- const [matchInputFilename, outputFilename = matchInputFilename] = parseMatcher(filename, options);
62
- const inputFiles = findFile(mainPath, matchInputFilename);
68
+ const [matchInputFilenameMask] = parseMatcher(filename, options);
69
+ const inputFiles = findFile(mainPath, matchInputFilenameMask, exclude);
63
70
 
64
71
  for (const inputFile of inputFiles) {
65
72
  const dirPath = getParentDirectory(inputFile);
66
73
  const inputFilename = getFilename(inputFile);
67
74
 
75
+ const [matchInputFilename, outputFilename = matchInputFilename] = parseMatcher(filename, {
76
+ filename: inputFilename,
77
+ });
78
+
68
79
  if (ignores(cwd, inputFilename, options))
69
80
  continue;
70
81
 
71
82
  allFiles.push({
72
- mainPath,
73
83
  dirPath,
74
84
  matchInputFilename,
75
85
  rawOptions,
@@ -90,7 +100,6 @@ const createScan = (files) => (mainPath, {push, progress, options}) => {
90
100
  inputFilename,
91
101
  outputFilename,
92
102
  rawOptions,
93
- mainPath,
94
103
  } = current;
95
104
 
96
105
  progress({
@@ -111,7 +120,6 @@ const createScan = (files) => (mainPath, {push, progress, options}) => {
111
120
 
112
121
  push(inputFile, {
113
122
  dirPath,
114
- mainPath,
115
123
  matchInputFilename,
116
124
 
117
125
  outputFilename,
@@ -160,7 +168,7 @@ function check(files) {
160
168
  }
161
169
  }
162
170
 
163
- function getOutputFile(path, {dirPath, matchInputFilename, outputFilename, inputFile}) {
171
+ function getOutputFile({dirPath, matchInputFilename, outputFilename, inputFile}) {
164
172
  if (matchInputFilename === outputFilename)
165
173
  return inputFile;
166
174
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/operator-match-files",
3
- "version": "5.0.0",
3
+ "version": "5.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": "^2.0.0",
27
+ "@putout/babel": "^3.0.0",
28
28
  "@putout/engine-parser": "^11.0.1",
29
29
  "@putout/operator-filesystem": "^5.0.0",
30
30
  "@putout/operator-json": "^2.0.0"