@putout/engine-runner 20.2.0 → 20.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
@@ -254,7 +254,20 @@ export const scan = (rootPath) => {
254
254
  };
255
255
  ```
256
256
 
257
+ Or better `trackFile`:
257
258
 
259
+ ```js
260
+ export const report = () => 'Add file';
261
+ export const fix = (file) => {
262
+ writeFileContent(file, 'hello');
263
+ };
264
+
265
+ export const scan = (rootPath, {push, trackFile}) => {
266
+ for (const file of trackFile(rootPath, 'hello.txt')) {
267
+ push(file);
268
+ }
269
+ };
270
+ ```
258
271
 
259
272
  ### Finder
260
273
 
package/lib/progress.js CHANGED
@@ -13,11 +13,12 @@ module.exports.createProgress = () => {
13
13
  pluginsCount = 0;
14
14
  };
15
15
 
16
- progress.file = ({i, n, rule}) => {
16
+ progress.file = ({i, n, percent, rule}) => {
17
17
  progress.emit('file', {
18
18
  i,
19
19
  n,
20
20
  rule,
21
+ percent,
21
22
  });
22
23
  };
23
24
 
@@ -3,7 +3,11 @@
3
3
  const fullstore = require('fullstore');
4
4
  const {compare} = require('@putout/compare');
5
5
  const {__filesystem_name} = require('@putout/operator-json');
6
- const {pause, start} = require('@putout/operator-filesystem');
6
+ const {
7
+ findFile,
8
+ pause,
9
+ start,
10
+ } = require('@putout/operator-filesystem');
7
11
  const log = require('debug')('putout:runner:scanner');
8
12
 
9
13
  const fromSimple = require('@putout/plugin-filesystem/from-simple');
@@ -42,13 +46,30 @@ const watchPush = ({push, rule, progress}) => (...a) => {
42
46
  };
43
47
 
44
48
  const createFileProgress = ({rule, progress}) => ({i, n}) => {
49
+ ++i;
50
+ const percent = `${Math.round(i / n * 100)}%`;
51
+
45
52
  progress.file({
46
53
  i,
47
54
  n,
55
+ percent,
48
56
  rule,
49
57
  });
50
58
  };
51
59
 
60
+ const createTrackFile = (fileProgress) => function*(...a) {
61
+ const files = findFile(...a);
62
+ const n = files.length;
63
+
64
+ for (const [i, file] of files.entries()) {
65
+ fileProgress({
66
+ i,
67
+ n,
68
+ });
69
+ yield file;
70
+ }
71
+ };
72
+
52
73
  const getTraverse = ({scan, rule, progress}) => ({push, options}) => ({
53
74
  ['__putout_processor_filesystem(__)'](path) {
54
75
  log(rule);
@@ -57,6 +78,13 @@ const getTraverse = ({scan, rule, progress}) => ({push, options}) => ({
57
78
  const rootPath = path.get('arguments.0');
58
79
  const isSimple = fullstore(false);
59
80
 
81
+ const fileProgress = createFileProgress({
82
+ rule,
83
+ progress,
84
+ });
85
+
86
+ const trackFile = createTrackFile(fileProgress);
87
+
60
88
  runSimple(fromSimple, {
61
89
  path,
62
90
  rootPath,
@@ -69,10 +97,8 @@ const getTraverse = ({scan, rule, progress}) => ({push, options}) => ({
69
97
  rule,
70
98
  progress,
71
99
  }),
72
- progress: createFileProgress({
73
- rule,
74
- progress,
75
- }),
100
+ progress: fileProgress,
101
+ trackFile,
76
102
  options,
77
103
  });
78
104
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/engine-runner",
3
- "version": "20.2.0",
3
+ "version": "20.4.0",
4
4
  "type": "commonjs",
5
5
  "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
6
6
  "description": "Run 🐊Putout plugins",