Socket
Socket
Sign inDemoInstall

bilderhic

Package Overview
Dependencies
75
Maintainers
1
Versions
105
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.1.7 to 1.1.8

3

package.json
{
"name": "bilderhic",
"version": " 1.1.7",
"version": " 1.1.8",
"description": "Bilderhic (bhic) is a smart and simple command tool for automatization.",

@@ -77,4 +77,5 @@ "preferGlobal": true,

"safe-eval-2": "^0.4.2",
"wildcard-match": "^5.1.2",
"yaml": "^1.7.2"
}
}

@@ -258,8 +258,40 @@ <img src="https://lucianorasente.com/public_img/bhic.png" style="max-width:100px;width:100%;">

```bash
:each folder [recursive] [filter]
```
```bash
:each file [recursive] [filter]
```
Example 1
```bash
:each folder
:begin
echo [$currentFolder]
:end
```
Example 2
```bash
:each file
:each folder recursive
:begin
echo [$currentFolder]
:end
```
Example 3
```bash
:each folder recursive **/node_*
:begin
echo [$currentFolder]
:end
```
Example 4
```bash
:each folder **/node_*
:begin
echo [$currentFolder]
:end
```
#### Logger

@@ -266,0 +298,0 @@ Adds a logger instance.

@@ -7,2 +7,3 @@ /* eslint-disable no-await-in-loop */

const safeEval = require("safe-eval-2");
const wildcardMatch = require("wildcard-match");
const CommandBase = require("../base/command-base");

@@ -175,8 +176,11 @@ const { loadCommands } = require("../load-commands");

if (cmd[0] === ":each") {
const isRecursive = cmd[2] && cmd[2].toLowerCase() === "recursive";
const filter = (isRecursive ? cmd[3] : cmd[2]) || null;
if (cmd[1] === "folder") {
await this._pipeCmdEachFolder(instructions);
await this._pipeCmdEachFolder(instructions, isRecursive, filter);
return instructions.length === 0;
}
if (cmd[1] === "file") {
await this._pipeCmdEachFile(instructions);
await this._pipeCmdEachFile(instructions, isRecursive, filter);
return instructions.length === 0;

@@ -351,5 +355,5 @@ }

async _pipeCmdEachFolder(instructions) {
async _pipeCmdEachFolder(instructions, isRecursive, filter) {
const rootFolder = this.environment.cwd;
const folders = getDirectories(rootFolder);
const folders = getDirectories(rootFolder, isRecursive, filter);
let subPipeId = 1;

@@ -371,12 +375,14 @@

const dirname = folders[i];
const folderPath = folders[i];
const dirname = path.basename(folderPath);
const fork = this.environment.fork(dirname);
const fork = this.environment.fork(folderPath);
fork.setVariables({
$currentFolder: dirname,
$currentFolderPath: path.join(rootFolder, dirname),
$currentFolderAbsolutePath: path.resolve(path.join(rootFolder, dirname)),
$currentFolderPath: folderPath,
$currentFolderAbsolutePath: path.resolve(folderPath),
$foldersCount: folders.length,
$folderIndex: i,
});
const pipe = new Pipe(fork, `${this.pipeId}.${subPipeId++}`);

@@ -387,5 +393,5 @@ await pipe.load(instructionsBlock.join("\n"));

async _pipeCmdEachFile(instructions) {
async _pipeCmdEachFile(instructions, isRecursive, filter) {
const folder = this.environment.cwd;
const files = getFiles(folder);
const files = getFiles(folder, isRecursive, filter);
let subPipeId = 1;

@@ -406,10 +412,19 @@

await this.breakpoint();
const filePath = files[i];
const fileName = path.basename(filePath);
const folderPath = path.dirname(filePath);
const folderName = path.basename(folderPath);
const fork = this.environment.fork();
fork.setVariables({
$currentFile: files[i],
$currentFilePath: path.join(folder, files[i]),
$currentFileAbsolutePath: path.resolve(path.join(folder, files[i])),
$currentFolder: folderName,
$currentFolderPath: folderPath,
$currentFile: fileName,
$currentFilePath: filePath,
$currentFileAbsolutePath: path.resolve(filePath),
$filesCount: files.length,
$fileIndex: i,
});
const pipe = new Pipe(fork, `${this.pipeId}.${subPipeId++}`);

@@ -421,10 +436,57 @@ await pipe.load(instructionsBlock.join("\n"));

function getDirectories(directory) {
return fs.readdirSync(directory).filter(file => fs.statSync(`${directory}/${file}`).isDirectory());
/**
* Gets a list of directories.
* @todo Put the method into a helper class.
* @param {string} directory Root directory
* @param {string} [isRecursive] Is recursive?
* @param {string} [filter] Wilcard filter
* @returns {string[]} Directories
*/
function getDirectories(directory, isRecursive, filter) {
const folders = fs.readdirSync(directory)
.filter(file => fs.statSync(`${directory}/${file}`).isDirectory())
.map(m => path.join(directory, m));
if (isRecursive) {
folders.forEach(folder => {
folders.push(...getDirectories(folder, true));
});
}
if (filter && filter !== "*") {
const isMatch = wildcardMatch(filter);
return folders.filter(f => isMatch(f));
}
return folders;
}
function getFiles(directory) {
return fs.readdirSync(directory).filter(file => fs.statSync(`${directory}/${file}`).isFile());
/**
* Gets a list of files.
* @todo Put the method into a helper class.
* @param {string} directory Root directory
* @param {string} [isRecursive] Is recursive?
* @param {string} [filter] Wilcard filter
* @returns {string[]} Directories
*/
function getFiles(directory, isRecursive, filter) {
const files = fs.readdirSync(directory)
.filter(file => fs.statSync(`${directory}/${file}`).isFile())
.map(m => path.join(directory, m));
if (isRecursive) {
const folders = getDirectories(directory, true);
folders.forEach(folder => {
files.push(...getFiles(folder, false));
});
}
if (filter && filter !== "*") {
const isMatch = wildcardMatch(filter);
return files.filter(f => isMatch(f));
}
return files;
}
module.exports = Pipe;
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc