bilderhic
Advanced tools
Comparing version 1.2.4 to 1.2.5
{ | ||
"name": "bilderhic", | ||
"version": " 1.2.4", | ||
"version": " 1.2.5", | ||
"description": "Bilderhic (bhic) is a smart and simple command tool for automatization.", | ||
@@ -5,0 +5,0 @@ "preferGlobal": true, |
const fs = require("fs"); | ||
const path = require("path"); | ||
const inquirer = require("inquirer"); | ||
const CommandBase = require("../base/command-base"); | ||
@@ -5,0 +4,0 @@ const DirectoryHelper = require("../helpers/directory-helper"); |
@@ -175,7 +175,28 @@ /* eslint-disable no-await-in-loop */ | ||
if (cmd[0] === ":each") { | ||
const isRecursive = cmd[2] && cmd[2].toLowerCase() === "recursive"; | ||
const filter = (isRecursive ? cmd[3] : cmd[2]) || null; | ||
let isRecursive = false; | ||
let isAsync = false; | ||
let filterIdx = 2; | ||
for (let i = 2; i < cmd.length; i++) { | ||
const c = cmd[i] ? cmd[i].toLowerCase() : ""; | ||
if (cmd[i] === "recursive") { | ||
isRecursive = true; | ||
++filterIdx; | ||
} | ||
else if (cmd[i] === "async") { | ||
isAsync = true; | ||
++filterIdx; | ||
} | ||
} | ||
const filter = cmd[filterIdx] || null; | ||
if (cmd[1] === "folder") { | ||
await this._pipeCmdEachFolder(instructions, isRecursive, filter); | ||
if (isAsync) { | ||
await this._pipeCmdEachFolderAsync(instructions, isRecursive, filter); | ||
} | ||
else { | ||
await this._pipeCmdEachFolder(instructions, isRecursive, filter); | ||
} | ||
return instructions.length === 0; | ||
@@ -354,3 +375,3 @@ } | ||
async _pipeCmdEachFolder(instructions, isRecursive, filter) { | ||
async _pipeCmdEachFolderAsync(instructions, isRecursive, filter) { | ||
const rootFolder = this.environment.cwd; | ||
@@ -370,23 +391,55 @@ const folders = getDirectories(rootFolder, isRecursive, filter); | ||
const count = folders.length; | ||
const promises = []; | ||
for (let i = 0; i < folders.length; i++) { | ||
this.debug(`Forking pipe to ${folders[i]}`); | ||
await this.breakpoint(); | ||
promises.push(this.forkFolderPipe(folders[i], instructionsBlock, subPipeId++, i, count)); | ||
} | ||
const folderPath = folders[i]; | ||
const dirname = path.basename(folderPath); | ||
await Promise.all(promises); | ||
} | ||
const fork = this.environment.fork(folderPath); | ||
fork.setVariables({ | ||
$currentFolder: dirname, | ||
$currentFolderPath: folderPath, | ||
$currentFolderAbsolutePath: path.resolve(folderPath), | ||
$foldersCount: folders.length, | ||
$folderIndex: i, | ||
}); | ||
async _pipeCmdEachFolder(instructions, isRecursive, filter) { | ||
const rootFolder = this.environment.cwd; | ||
const folders = getDirectories(rootFolder, isRecursive, filter); | ||
let subPipeId = 1; | ||
const pipe = new Pipe(fork, `${this.pipeId}.${subPipeId++}`); | ||
await pipe.load(instructionsBlock.join("\n")); | ||
let instructionsBlock; | ||
if (instructions[0] && instructions[0].trim().toLowerCase() === ":begin") { | ||
instructionsBlock = CommandsExtractor.extractBlock(instructions); | ||
} | ||
else { | ||
instructionsBlock = [...instructions]; | ||
instructions.splice(0, instructions.length); | ||
} | ||
const count = folders.length; | ||
for (let i = 0; i < count; i++) { | ||
await this.forkFolderPipe(folders[i], instructionsBlock, subPipeId++, i, count); | ||
} | ||
} | ||
async forkFolderPipe(folder, instructionsBlock, subPipeId, i, count) { | ||
this.debug(`Forking pipe to ${folder}`); | ||
await this.breakpoint(); | ||
const folderPath = folder; | ||
const dirname = path.basename(folderPath); | ||
const fork = this.environment.fork(folderPath); | ||
fork.setVariables({ | ||
$currentFolder: dirname, | ||
$currentFolderPath: folderPath, | ||
$currentFolderAbsolutePath: path.resolve(folderPath), | ||
$foldersCount: count, | ||
$folderIndex: i, | ||
}); | ||
const pipe = new Pipe(fork, `${this.pipeId}.${subPipeId}`); | ||
await pipe.load(instructionsBlock.join("\n")); | ||
} | ||
async _pipeCmdEachFile(instructions, isRecursive, filter) { | ||
@@ -393,0 +446,0 @@ const folder = this.environment.cwd; |
cd .. | ||
:each folder | ||
echo [$currentFolder] | ||
echo [$currentFolderPath] | ||
echo [$currentFolderAbsolutePath] | ||
echo [$foldersCount] | ||
echo [$folderIndex] | ||
exit | ||
echo Current folder: [$currentFolder] | ||
echo Current folder path: [$currentFolderPath] | ||
echo Current folder abs path: [$currentFolderAbsolutePath] | ||
echo Folders: [$foldersCount] | ||
echo Index: [$folderIndex] |
145867
90
3754