基于 Node.js/TypeScript 开发的自动化填报工作日志工具,扫描本地 Git 仓库获取提交记录,自动整理后提交到 OA 系统。
cd alog
npm install
npm run build
在 Windows PowerShell 中执行脚本前,需要设置执行策略:
Set-ExecutionPolicy RemoteSigned -Scope CurrentUser
此设置仅对当前用户生效,允许执行本地脚本和远程签名的脚本。
{
"oa": {
"baseUrl": "https://npms.newcapec.cn",
},
"git": {
"scanDir": "~/work",
"excludeDirs": ["node_modules", ".git", "dist", "build", "vendor"],
"excludeRepos": [],
"repos": [],
"includeScanDir": false
},
"log": {
"morningCutoff": "12:00",
"afternoonCutoff": "18:30",
"defaultMorningHours": 3,
"defaultAfternoonHours": 5,
"maxNightHours": 8
},
"task": {
"defaultObjectType": "task_你的默认任务",
"location": "company"
},
"schedule": {
"enabled": false,
"cron": "0 20 * * 1-5"
}
}
Git 扫描配置支持多种模式,可根据实际需求灵活配置:
| 字段 | 类型 | 说明 |
|---|---|---|
scanDir | string | string[] | 扫描目录,支持单个路径或路径数组,递归扫描这些目录下的所有 Git 仓库 |
excludeDirs | string[] | 递归扫描时要排除的目录名(如 node_modules) |
excludeRepos | string[] | 要排除的仓库,支持路径或仓库名称匹配 |
repos | RepoConfig[] | 精确指定的仓库列表,不进行递归扫描 |
includeScanDir | boolean | 当配置了 repos 时,是否同时扫描 scanDir(默认 false) |
配置示例:
方式一:递归扫描单个目录
{
"git": {
"scanDir": "~/work",
"excludeDirs": ["node_modules", ".git", "dist", "build", "vendor"]
}
}
方式二:递归扫描多个目录
{
"git": {
"scanDir": ["~/work", "~/projects", "~/opensource"],
"excludeDirs": ["node_modules", ".git", "dist", "build"]
}
}
方式三:精确指定仓库(推荐)
适用于仓库分散在不同位置,或需要精确控制扫描哪些仓库:
{
"git": {
"repos": [
{ "path": "~/work/project-a" },
{ "path": "~/projects/project-b", "name": "项目B" },
{ "path": "/Users/xxx/opensource/lib-xyz" }
]
}
}
方式四:混合模式
精确指定仓库,同时扫描其他目录:
{
"git": {
"scanDir": "~/work",
"repos": [
{ "path": "~/projects/important-project" }
],
"includeScanDir": true
}
}
方式五:排除不需要的仓库
{
"git": {
"scanDir": "~/work",
"excludeRepos": ["test-repo", "archive", "/Users/xxx/work/old-project"]
}
}
{
"mobile": "",
"zentaosid": ""
}
首次使用需要配置登录 Cookie:
zentaosid 的值credentials.json,填入 Cookie 值config.json中的task.defaultObjectType扫描今日提交并自动填报:
# 方式一(推荐)
alog today
# 方式二
alog scan
预览模式(不提交):
alog today --preview
交互式选择日期补填:
alog fill
指定日期补填:
alog fill -d 2026-03-11
预览模式:
alog fill -d 2026-03-11 --preview
自动模式(处理所有有提交的日期):
alog fill --auto
指定日期范围补填:
alog fill --start-date 2026-03-01 --end-date 2026-03-10
日期范围参数说明:
| 参数 | 说明 | 示例 |
|---|---|---|
--start-date | 日期范围开始 | --start-date 2026-03-01 |
--end-date | 日期范围结束 | --end-date 2026-03-10 |
查看定时任务配置:
alog schedule --info
注意:内置定时任务需要保持进程运行。更推荐使用系统 crontab(见下文)。
alog status
推荐使用系统 crontab (Linux/macOS) 或 Task Scheduler (Windows) 配置定时任务,无需保持进程运行:
# 编辑 crontab
crontab -e
# 添加以下行(每天晚上8点执行)
# Linux/macOS 使用 nvm/node 路径,Windows 使用 Task Scheduler
0 20 * * 1-5 /path/to/your/alog/node_modules/.bin/node /path/to/your/alog/dist/index.js today >> /path/to/your/alog/alog.log 2>&1
| 表达式 | 含义 |
|---|---|
0 20 * * 1-5 | 每周一到周五晚上20:00 |
0 18 * * 1-5 | 每周一到周五晚上18:00 |
0 9 * * 1-5 | 每周一到周五早上9:00 |
crontab -l
crontab -r
| 时段 | 时间范围 | 默认耗时 |
|---|---|---|
| 上午 (am) | 00:00 - 12:00 | 3 小时 |
| 下午 (pm) | 12:00 - 18:30 | 5 小时 |
| 晚间 (nt) | 18:30 - 24:00 | 动态计算 |
如果当天只有 1 条提交记录,将自动填充整天:
节假日配置存储在 holidays.json 文件中,格式如下:
{
"2026": [
"2026-01-01",
"2026-01-26",
...
]
}
补填日志时:
A: 重新登录 OA 系统,获取新的 zentaosid 值,更新到 credentials.json。
A: 编辑 config.json 中的 git.scanDir 字段,支持以下方式:
scanDir 为目录路径repos 数组中添加仓库路径excludeRepos 中添加要排除的仓库名称或路径详见上方 git 配置说明 章节。
A: 1. 检查 Cookie 是否有效;2. 检查当天是否已填报;3. 使用 --preview 查看提交内容是否正确。
| 命令 | 说明 |
|---|---|
scan | 扫描并填报今日日志 |
fill | 补填历史日期日志 |
set-password | 设置登录密码 |
schedule | 定时任务管理 |
status | 查看登录状态 |
alog/ ├── src/ │ ├── index.ts # CLI 入口 │ ├── git-scanner.ts # Git 提交扫描 │ ├── log-builder.ts # 日志整理 │ ├── oa-auth.ts # OA 登录 │ ├── oa-api.ts # OA API 交互 │ ├── config.ts # 配置管理 │ ├── holiday-checker.ts # 节假日检查 │ └── types.ts # 类型定义 ├── config.json # 配置文件 ├── credentials.json # 登录凭据 ├── holidays.json # 节假日配置 ├── package.json └── tsconfig.json