# file-batch-script

> * 支持多进程任务 * 通配符查找过滤文件。通配符的用法可以查阅[glob文档](https://www.npmjs.com/package/glob) * 可自定义处理文件 * 可输出基础操作日志 * 可扩展日志处理

Latest version **0.5.4** (published 2022-03-19) · MIT license · 0 weekly downloads

## Install

```sh
npm install file-batch-script
pnpm add file-batch-script
yarn add file-batch-script
bun add file-batch-script
```

Provides the command `file-batch-script`.

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.5.4 |
| Published | 2022-03-19 |
| First published | 2021-12-16 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 7 |
| Unpacked size | 9.4 MB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | huyoo |

## Links

- npm: https://www.npmjs.com/package/file-batch-script
- Repository: https://gitee.com/huyoo/file-batch-script
- npm.io page: https://npm.io/package/file-batch-script

## Dependencies (7)

- [ora](https://npm.io/package/ora.md) ^5.4.1
- [glob](https://npm.io/package/glob.md) ^7.2.0
- [chalk](https://npm.io/package/chalk.md) ^4.1.2
- [shelljs](https://npm.io/package/shelljs.md) ^0.8.4
- [inquirer](https://npm.io/package/inquirer.md) ^8.2.0
- [commander](https://npm.io/package/commander.md) ^8.3.0
- [download-git-repo](https://npm.io/package/download-git-repo.md) ^3.0.2

## Recent versions

- 0.5.4 (latest) — 2022-03-19
- 0.5.3 — 2022-03-19
- 0.5.2 — 2022-03-19
- 0.5.1 — 2021-12-17
- 0.5.0 — 2021-12-17
- 0.4.4 — 2021-12-17
- 0.4.3 — 2021-12-16
- 0.4.2 — 2021-12-16
- 0.4.1 — 2021-12-16
- 0.4.0 — 2021-12-16

## README

# 文件批处理脚本

* 支持多进程任务
* 通配符查找过滤文件。通配符的用法可以查阅[glob文档](https://www.npmjs.com/package/glob)
* 可自定义处理文件
* 可输出基础操作日志
* 可扩展日志处理

# 版本依赖
```
node >= 14.18.0
npm >= 7
```

# 使用
```bash
# 安装依赖
$ npm install file-batch-script -g

# 初始化脚本
$ file-batch-script init
# 根据提示输入必要参数后，等待下载模板、依赖安装完毕

# 执行或自行修改配置
$ npm run default

# !!! 注意 !!!
# package.json 里配置的环境参数 default 需要和 default.config.js 对应。
```

# 模板文件说明
```text
├── config                    # 脚本配置
│   └── default.config.js     # 初始脚本命令，可用于文本替换
├── keywordFiles              # 关键字文件存放，可自行调整
├── src                       # 代码存放地，可自行调整
├── .gitignore                
├── package.json
```

# API
| 属性 | 说明 | 类型 | 默认值 |
| --- | --- | --- | --- |
| after | 文件处理完毕后的回调 | `() => void` | - |
| dealFn | 自定义文件处理函数。`options`配置在`*.config.js`中的自定义属性，子进程在调用`dealFn`时，会过滤掉 api 属性 | `(filePath:string, options:object, callback:(msg: DealLog) => void) => void` | required |
| files | 要处理的文件列表，使用文件的绝对路径。优先级高于`includes` | `string[]` | - |
| filterFiles | 自定义过滤文件 | `(files: string[]) => string[]` | - |
| ignoreFiles | 忽略的文件，可使用通配符和字符串路径 | `string[]` | - |
| includes | 通配符匹配目标文件，使用`glob`实现 | `string[]` | required |
| logger | 日志配置，设置真值时启用日志记录。具体说明如下 | `LoggerType` | - |
| multiProcess | 是否启用多进程处理，设为`number`可以控制进程数，`true`使用最大cpu数创建进程 | `boolean` `number` | `true` |
| root | 目标文件根目录，配合`includes`使用。如不配置，会用上一级目录作为入口，并将过滤本目录 | `string` | - |

## DealLog
| 类型 | 说明 | 备注 |
| --- | --- | --- |
| Log | 通用日志 | `{ type: string, message:string/number }` |
| string/number | 以字符串或数字传值，默认为`log`类型数据 | - |
| array | 批量回传日志 | `Log[]` |

## LoggerType
| 属性 | 说明 | 类型 | 默认值 |
| --- | --- | --- | --- |
| types | 自定义日志处理类型和函数，函数返回`false`，本条日志会重新加入日志队列。`type`设为`log/error`，将覆盖内置的处理函数 | `{ [type:string]: (msg:string) => boolean }` | - |

---
_Source: https://npm.io/package/file-batch-script · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
