bilderhic
Advanced tools
Comparing version 1.2.5 to 1.3.0
{ | ||
"name": "bilderhic", | ||
"version": " 1.2.5", | ||
"version": " 1.3.0", | ||
"description": "Bilderhic (bhic) is a smart and simple command tool for automatization.", | ||
@@ -80,2 +80,2 @@ "preferGlobal": true, | ||
} | ||
} | ||
} |
@@ -268,4 +268,5 @@ <img src="https://lucianorasente.com/public_img/bhic.png" style="max-width:100px;width:100%;"> | ||
```bash | ||
:each folder [recursive] [filter] | ||
:each folder [recursive] [async [limit x]] [filter] | ||
``` | ||
```bash | ||
@@ -307,2 +308,18 @@ :each file [recursive] [filter] | ||
Example 5 | ||
```bash | ||
:each folder async | ||
:begin | ||
echo [$currentFolder] | ||
:end | ||
``` | ||
Example 6 | ||
```bash | ||
:each folder async limit 5 | ||
:begin | ||
echo [$currentFolder] | ||
:end | ||
``` | ||
#### Logger | ||
@@ -309,0 +326,0 @@ Adds a logger instance. |
@@ -14,2 +14,3 @@ /* eslint-disable no-await-in-loop */ | ||
const Log = require("../../log"); | ||
const AsyncHelper = require("../helpers/async-helper"); | ||
@@ -178,2 +179,3 @@ let commands = null; | ||
let isAsync = false; | ||
let asyncLimit = 0; | ||
@@ -192,2 +194,7 @@ let filterIdx = 2; | ||
} | ||
else if (cmd[i] === "limit") { | ||
asyncLimit = +cmd[++i]; | ||
++filterIdx; | ||
++filterIdx; | ||
} | ||
} | ||
@@ -199,3 +206,3 @@ | ||
if (isAsync) { | ||
await this._pipeCmdEachFolderAsync(instructions, isRecursive, filter); | ||
await this._pipeCmdEachFolderAsync(instructions, isRecursive, filter, asyncLimit); | ||
} | ||
@@ -378,3 +385,3 @@ else { | ||
async _pipeCmdEachFolderAsync(instructions, isRecursive, filter) { | ||
async _pipeCmdEachFolderAsync(instructions, isRecursive, filter, asyncLimit) { | ||
const rootFolder = this.environment.cwd; | ||
@@ -396,9 +403,12 @@ const folders = getDirectories(rootFolder, isRecursive, filter); | ||
const promises = []; | ||
const argsForGenerators = []; | ||
for (let i = 0; i < folders.length; i++) { | ||
promises.push(this.forkFolderPipe(folders[i], instructionsBlock, subPipeId++, i, count)); | ||
const taskArgs = { folder: folders[i], instructionsBlock, subPipeId: subPipeId++, i, count }; | ||
argsForGenerators.push(taskArgs); | ||
} | ||
await Promise.all(promises); | ||
const fns = argsForGenerators.map(m => (() => this.forkFolderPipe(m.folder, m.instructionsBlock, m.subPipeId, m.i, m.count))); | ||
await AsyncHelper.waitForAllWithLimit(fns, asyncLimit); | ||
} | ||
@@ -405,0 +415,0 @@ |
cd .. | ||
:each folder async | ||
:each folder async limit 10 | ||
echo Current folder: [$currentFolder] | ||
@@ -4,0 +4,0 @@ echo Current folder path: [$currentFolderPath] |
146864
91
3776
490