Compare commits
8 Commits
v1.15.beta
...
v1.15.beta
Author | SHA1 | Date | |
---|---|---|---|
|
2d409fbce0 | ||
|
550dc01dfb | ||
|
d0492bad8c | ||
|
55625d51bc | ||
|
8ddc124f89 | ||
|
8b7042411c | ||
|
b72caedcbb | ||
|
f989590d14 |
68
README.md
68
README.md
@@ -17,6 +17,7 @@ fileboy,文件变更监听通知系统,使用 Go 编写。
|
||||
- 命令支持变量占位符
|
||||
- 支持冗余任务丢弃,自定义冗余任务范围
|
||||
- 支持 http 通知
|
||||
- 高级指令用法
|
||||
- 更多...
|
||||
|
||||
## 编译环境
|
||||
@@ -130,19 +131,6 @@ command:
|
||||
# 如果不需要该特性,设置为 0
|
||||
delayMillSecond: 2000
|
||||
|
||||
# 特殊指令
|
||||
# 可以通过预定义的指令来控制 command 的行为,指令可以有多个
|
||||
# exec-when-start fileboy启动就绪后,自动执行一次 'exec' 定义的命令
|
||||
# should-finish 触发执行 'exec' 时(C),如果上一次的命令(L)未退出(还在执行),会等待 L 退出,直到有明确 exit code 才会开始执行本次命令。
|
||||
# 在等待 L 退出时,又有新事件触发了命令执行(N),则 C 执行取消,只会保留最后一次的 N 执行
|
||||
# ignore-stdout 执行 'exec' 产生的 stdout 会被丢弃
|
||||
# ignore-warn fileboy 自身的 warn 信息会被丢弃
|
||||
# ignore-info fileboy 自身的 info 信息会被丢弃
|
||||
# ignore-exec-error 执行 'exec' 出错仍继续执行下面的命令而不退出
|
||||
instruction:
|
||||
#- should-finish
|
||||
#- exec-when-start
|
||||
|
||||
# 通知器
|
||||
notifier:
|
||||
# 文件更改会向该 url 发送请求(POST 一段 json 文本数据)
|
||||
@@ -155,40 +143,44 @@ notifier:
|
||||
# 例: http://example.com/notifier/fileboy-listener
|
||||
# 不启用通知,请留空 ""
|
||||
callUrl: ""
|
||||
|
||||
# 特殊指令
|
||||
instruction:
|
||||
# 可以通过特殊的指令选项来控制 command 的行为,指令可以有多个
|
||||
# 指令选项解释:
|
||||
# exec-when-start fileboy启动就绪后,自动执行一次 'exec' 定义的命令
|
||||
# should-finish 触发执行 'exec' 时(C),如果上一次的命令(L)未退出(还在执行),会等待 L 退出(而不是强制 kill ),直到 L 有明确 exit code 才会开始执行本次命令。
|
||||
# 在等待 L 退出时,又有新事件触发了命令执行(N),则 C 执行取消,只会保留最后一次的 N 执行
|
||||
# ignore-stdout 执行 'exec' 产生的 stdout 会被丢弃
|
||||
# ignore-warn fileboy 自身的 warn 信息会被丢弃
|
||||
# ignore-info fileboy 自身的 info 信息会被丢弃
|
||||
# ignore-exec-error 执行 'exec' 出错仍继续执行下面的命令而不退出
|
||||
|
||||
#- should-finish
|
||||
#- exec-when-start
|
||||
- ignore-warn
|
||||
```
|
||||
|
||||
### TODO
|
||||
|
||||
- [x] 命令支持变量占位符
|
||||
- [x] 支持多命令
|
||||
- [x] 支持监听指定文件夹
|
||||
- [x] 支持不监听指定文件夹
|
||||
- [x] 支持监听指定后缀文件
|
||||
- [x] 支持自定事件监听
|
||||
- [x] 支持 http 通知
|
||||
- [x] 支持冗余任务丢弃
|
||||
- [ ] 支持 http 合并任务的通知
|
||||
|
||||
## QA
|
||||
|
||||
#### 很多框架都自带了 hot reload 的功能,为什么还要单独写个 fileboy 呢?
|
||||
### 很多框架都自带了 hot reload 的功能,为什么还要单独写个 fileboy 呢?
|
||||
|
||||
这个是一款通用的 hot reload 的软件,理论上适用于任何需要 hot reload 的场景,并不局限于语言层面上。只要灵活的配置 `filegirl.yaml`文件就行了。
|
||||
|
||||
#### fileboy 可以应用在那些具体的场景?
|
||||
### fileboy 可以应用在那些具体的场景?
|
||||
|
||||
在开发中,我们很需要一款可以帮助我们自动打包编译的工具,那 fileboy 就非常适合这样的场景。比如 go 项目的热编译,让我们可以边修改代码边运行得到反馈。又比如 PHP Swoole 框架,由于常驻进程的原因,无法更改代码立即reload,使用 fileboy 就可以辅助做到传统 PHP 开发的体验。
|
||||
对于一些需要监控文件日志或者配置变动的场景, fileboy 同样适合。你可以事先编写好相应的通知报警脚本,然后定义`filegirl.yaml`中的`command`命令,交由 fileboy 自动运行监控报警。
|
||||
|
||||
#### 通知器在什么时候会发送 http 请求 ?
|
||||
### 通知器在什么时候会发送 http 请求 ?
|
||||
|
||||
通知器发送 http 通知的前提是在配置文件中设置了 `callUrl` 参数(不为空即为已设置)。触发请求的时机和执行 command 命令是一致的,`command -> delayMillSecond` 参数对于触发器同样有效。请求超时默认15秒.
|
||||
|
||||
#### idea 下更改文件,为什么会执行两次或者多次 command ?
|
||||
### idea 下更改文件,为什么会执行两次或者多次 command ?
|
||||
|
||||
由于 idea 系列软件特殊的文件保存策略,他会自动创建一些临时文件,并且在需要时多次重写文件,所以有时反映在文件上就是有多次的更改,所以会出现这种情况。1.5之后的版本增加了 `delayMillSecond` 参数,可以解决这个问题。
|
||||
|
||||
#### filegirl.yaml 里面的 command 如何配置复杂命令?
|
||||
### filegirl.yaml 里面的 command 如何配置复杂命令?
|
||||
|
||||
fileboy 目前支持 `命令 + 参数`这种形式的 command,而且 参数中不能有""符号或者有空格。如:
|
||||
`go build`:支持;
|
||||
@@ -197,19 +189,21 @@ fileboy 目前支持 `命令 + 参数`这种形式的 command,而且 参数中
|
||||
`cat a.txt | grep "q" | wc -l`:不支持
|
||||
对于不支持的命令,可以把它写到一个文件里,然后在 command 中执行这个文件来解决。
|
||||
|
||||
#### 为什么起名为 fileboy,又把配置名叫做 filegirl ?
|
||||
### 为什么起名为 fileboy,又把配置名叫做 filegirl ?
|
||||
|
||||
因为爱情~~ (◡ᴗ◡✿)
|
||||
|
||||
|
||||
|
||||
### 贡献者
|
||||
## 贡献者
|
||||
|
||||
> 排名不分先后
|
||||
| | | |
|
||||
| ------------ | ------------ | ------------ |
|
||||
| <a href="https://github.com/dengsgo"><img src="https://avatars1.githubusercontent.com/u/7929002?s=460&v=4" width=64 style="border-radius:45px;" /></a> | <a href="https://github.com/jason-gao"><img src="https://avatars1.githubusercontent.com/u/9896574?s=460&v=4" width=64 style="border-radius:45px;" /></a> | <a href="https://github.com/itwesley"><img src="https://avatars1.githubusercontent.com/u/1928721?s=460&v=4" width=64 style="border-radius:45px;" /></a> |
|
||||
|
||||
[@dengsgo](https://www.yoytang.com) <dengsgo@gmail.com>
|
||||
## 感谢支持
|
||||
|
||||
[@itwesley](https://github.com/itwesley) <wcshen1126@gmail.com>
|
||||
|
||||
[@jason-gao](https://github.com/jason-gao) <3048789891@qq.com>
|
||||
| |
|
||||
| ------------ |
|
||||
| <a href="https://www.jetbrains.com/?from=fileboy"><img src="./resources/jetbrains.png" width=140 /></a> |
|
||||
|
||||
|
44
README_EN.md
44
README_EN.md
@@ -17,6 +17,7 @@ For Hot Reload scenarios (typically for developing go projects without having to
|
||||
- Command support variable placeholders
|
||||
- Supporting redundant task discarding and customizing redundant task scope
|
||||
- Supporting HTTP notifications
|
||||
- Advanced instruction usage
|
||||
- more...
|
||||
|
||||
## COMPILE
|
||||
@@ -127,19 +128,6 @@ command:
|
||||
# If this feature is not required, set to 0
|
||||
delayMillSecond: 2000
|
||||
|
||||
# 特殊指令
|
||||
# 可以通过预定义的指令来控制 command 的行为,指令可以有多个
|
||||
# exec-when-start fileboy启动就绪后,自动执行一次 'exec' 定义的命令
|
||||
# should-finish 触发执行 'exec' 时(C),如果上一次的命令(L)未退出(还在执行),会等待 L 退出,直到有明确 exit code 才会开始执行本次命令。
|
||||
# 在等待 L 退出时,又有新事件触发了命令执行(N),则 C 执行取消,只会保留最后一次的 N 执行
|
||||
# ignore-stdout 执行 'exec' 产生的 stdout 会被丢弃
|
||||
# ignore-warn fileboy 自身的 warn 信息会被丢弃
|
||||
# ignore-info fileboy 自身的 info 信息会被丢弃
|
||||
# ignore-exec-error 执行 'exec' 出错仍继续执行下面的命令而不退出
|
||||
instruction:
|
||||
#- should-finish
|
||||
#- exec-when-start
|
||||
|
||||
notifier:
|
||||
# file changes send requests to the URL (POST JSON text data)
|
||||
# the timing of triggering the request is consistent with executing the command command
|
||||
@@ -151,13 +139,35 @@ notifier:
|
||||
# e.g: http://example.com/notifier/fileboy-listener
|
||||
# no notice is enabled. Please leave it blank. ""
|
||||
callUrl: ""
|
||||
|
||||
instruction:
|
||||
# command behavior can be controlled by special command options. there can be multiple instructions
|
||||
# options:
|
||||
# exec-when-start when fileboy is ready to start, execute the command defined by 'exec' once automatically
|
||||
# should-finish when the execution of 'exec' is triggered (C), if the last command (L) does not exit (still executing),
|
||||
# it will wait for L to exit (instead of forcing kill), and the execution of this command will not start until L has an explicit exit code.
|
||||
# when waiting for L to exit, and a new event triggers command execution (n), C execution is cancelled, and only the last N execution is retained
|
||||
# ignore-stdout stdout generated by executing 'exec' will be discarded
|
||||
# ignore-warn the warn information of fileboy itself will be discarded
|
||||
# ignore-info the info information of fileboy itself will be discarded
|
||||
# ignore-exec-error error executing 'exec' continue to execute the following command without exiting
|
||||
|
||||
#- should-finish
|
||||
#- exec-when-start
|
||||
- ignore-warn
|
||||
```
|
||||
|
||||
### CONTRIBUTOR
|
||||
## CONTRIBUTOR
|
||||
|
||||
[@dengsgo](https://www.yoytang.com) <dengsgo@gmail.com>
|
||||
| | | |
|
||||
| ------------ | ------------ | ------------ |
|
||||
| <a href="https://github.com/dengsgo"><img src="https://avatars1.githubusercontent.com/u/7929002?s=460&v=4" width=64 style="border-radius:45px;" /></a> | <a href="https://github.com/jason-gao"><img src="https://avatars1.githubusercontent.com/u/9896574?s=460&v=4" width=64 style="border-radius:45px;" /></a> | <a href="https://github.com/itwesley"><img src="https://avatars1.githubusercontent.com/u/1928721?s=460&v=4" width=64 style="border-radius:45px;" /></a> |
|
||||
|
||||
[@itwesley](https://github.com/itwesley) <wcshen1126@gmail.com>
|
||||
|
||||
[@jason-gao](https://github.com/jason-gao) <3048789891@qq.com>
|
||||
|
||||
## THANKS
|
||||
|
||||
| |
|
||||
| ------------ |
|
||||
| <a href="https://www.jetbrains.com/?from=fileboy"><img src="./resources/jetbrains.png" width=140></a> |
|
||||
|
||||
|
26
fileboy.go
26
fileboy.go
@@ -57,29 +57,29 @@ func parseConfig() {
|
||||
cfg = new(FileGirl)
|
||||
fc, err := ioutil.ReadFile(getFileGirlPath())
|
||||
if err != nil {
|
||||
logError("The filegirl.yaml file in", projectFolder, "is not exist! ", err)
|
||||
logError("the filegirl.yaml file in", projectFolder, "is not exist! ", err)
|
||||
fmt.Print(firstRunHelp)
|
||||
logAndExit("Fileboy unable to run.")
|
||||
logAndExit("fileboy unable to run.")
|
||||
}
|
||||
err = yaml.Unmarshal(fc, cfg)
|
||||
if err != nil {
|
||||
logAndExit("Parsed filegirl.yaml failed: ", err)
|
||||
logAndExit("parsed filegirl.yaml failed: ", err)
|
||||
}
|
||||
if cfg.Core.Version > Version {
|
||||
logAndExit("Current fileboy support max version : ", Version)
|
||||
logAndExit("current fileboy support max version : ", Version)
|
||||
}
|
||||
// init map
|
||||
cfg.Monitor.TypesMap = map[string]bool{}
|
||||
cfg.Monitor.IncludeDirsMap = map[string]bool{}
|
||||
cfg.Monitor.ExceptDirsMap = map[string]bool{}
|
||||
cfg.Monitor.IncludeDirsRec = map[string]bool{}
|
||||
cfg.Command.InstructionMap = map[string]bool{}
|
||||
cfg.InstructionMap = map[string]bool{}
|
||||
// convert to map
|
||||
for _, v := range cfg.Monitor.Types {
|
||||
cfg.Monitor.TypesMap[v] = true
|
||||
}
|
||||
for _, v := range cfg.Command.Instruction {
|
||||
cfg.Command.InstructionMap[v] = true
|
||||
for _, v := range cfg.Instruction {
|
||||
cfg.InstructionMap[v] = true
|
||||
}
|
||||
log.Printf("%+v", cfg)
|
||||
}
|
||||
@@ -283,15 +283,15 @@ func parseArgs() {
|
||||
case "init":
|
||||
_, err := ioutil.ReadFile(getFileGirlPath())
|
||||
if err == nil {
|
||||
logError("Profile filegirl.yaml already exists.")
|
||||
logAndExit("If you want to regenerate filegirl.yaml, delete it first")
|
||||
logError("profile filegirl.yaml already exists.")
|
||||
logAndExit("delete it first when you want to regenerate filegirl.yaml")
|
||||
}
|
||||
err = ioutil.WriteFile(getFileGirlPath(), []byte(exampleFileGirl), 0644)
|
||||
if err != nil {
|
||||
logError("Profile filegirl.yaml create failed! ", err)
|
||||
logError("profile filegirl.yaml create failed! ", err)
|
||||
return
|
||||
}
|
||||
logUInfo("Profile filegirl.yaml created ok")
|
||||
logUInfo("profile filegirl.yaml created ok")
|
||||
return
|
||||
case "exec":
|
||||
parseConfig()
|
||||
@@ -302,11 +302,11 @@ func parseArgs() {
|
||||
case "help", "--help", "--h", "-h":
|
||||
fmt.Print(helpStr)
|
||||
default:
|
||||
logAndExit("Unknown parameter, use 'fileboy help' to view available commands")
|
||||
logAndExit("unknown parameter, use 'fileboy help' to view available commands")
|
||||
}
|
||||
return
|
||||
default:
|
||||
logAndExit("Unknown parameters, use `fileboy help` show help info.")
|
||||
logAndExit("unknown parameters, use `fileboy help` show help info.")
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -18,14 +18,14 @@ type FileGirl struct {
|
||||
IncludeDirsRec map[string]bool `yaml:"-"`
|
||||
}
|
||||
Command struct {
|
||||
Instruction []string `yaml:"instruction"`
|
||||
Exec []string `yaml:"exec"`
|
||||
DelayMillSecond int `yaml:"delayMillSecond"`
|
||||
|
||||
// convert to
|
||||
InstructionMap map[string]bool `yaml:"-"`
|
||||
}
|
||||
Notifier struct {
|
||||
CallUrl string `yaml:"callUrl"`
|
||||
}
|
||||
Instruction []string `yaml:"instruction"`
|
||||
|
||||
// convert to
|
||||
InstructionMap map[string]bool `yaml:"-"`
|
||||
}
|
||||
|
31
raw.go
31
raw.go
@@ -69,19 +69,6 @@ command:
|
||||
# 如果不需要该特性,设置为 0
|
||||
delayMillSecond: 2000
|
||||
|
||||
# 特殊指令
|
||||
# 可以通过预定义的指令来控制 command 的行为,指令可以有多个
|
||||
# exec-when-start fileboy启动就绪后,自动执行一次 'exec' 定义的命令
|
||||
# should-finish 触发执行 'exec' 时(C),如果上一次的命令(L)未退出(还在执行),会等待 L 退出,直到有明确 exit code 才会开始执行本次命令。
|
||||
# 在等待 L 退出时,又有新事件触发了命令执行(N),则 C 执行取消,只会保留最后一次的 N 执行
|
||||
# ignore-stdout 执行 'exec' 产生的 stdout 会被丢弃
|
||||
# ignore-warn fileboy 自身的 warn 信息会被丢弃
|
||||
# ignore-info fileboy 自身的 info 信息会被丢弃
|
||||
# ignore-exec-error 执行 'exec' 出错仍继续执行下面的命令而不退出
|
||||
instruction:
|
||||
#- should-finish
|
||||
#- exec-when-start
|
||||
|
||||
# 通知器
|
||||
notifier:
|
||||
# 文件更改会向该 url 发送请求(POST 一段 json 文本数据)
|
||||
@@ -94,6 +81,22 @@ notifier:
|
||||
# 例: http://example.com/notifier/fileboy-listener
|
||||
# 不启用通知,请留空 ""
|
||||
callUrl: ""
|
||||
|
||||
# 特殊指令
|
||||
instruction:
|
||||
# 可以通过特殊的指令选项来控制 command 的行为,指令可以有多个
|
||||
# 指令选项解释:
|
||||
# exec-when-start fileboy启动就绪后,自动执行一次 'exec' 定义的命令
|
||||
# should-finish 触发执行 'exec' 时(C),如果上一次的命令(L)未退出(还在执行),会等待 L 退出(而不是强制 kill ),直到 L 有明确 exit code 才会开始执行本次命令。
|
||||
# 在等待 L 退出时,又有新事件触发了命令执行(N),则 C 执行取消,只会保留最后一次的 N 执行
|
||||
# ignore-stdout 执行 'exec' 产生的 stdout 会被丢弃
|
||||
# ignore-warn fileboy 自身的 warn 信息会被丢弃
|
||||
# ignore-info fileboy 自身的 info 信息会被丢弃
|
||||
# ignore-exec-error 执行 'exec' 出错仍继续执行下面的命令而不退出
|
||||
|
||||
#- should-finish
|
||||
#- exec-when-start
|
||||
- ignore-warn
|
||||
`
|
||||
|
||||
var firstRunHelp = `第一次运行 fileboy ?
|
||||
@@ -142,7 +145,7 @@ var statement = `Dengsgo [dengsgo@gmail.com] Open Source with MIT License`
|
||||
|
||||
var versionDesc = `
|
||||
Version fileboy: v1.15 filegirl: v` + strconv.Itoa(Version) + `
|
||||
Released 2020.01.05
|
||||
Released 2020.03.03
|
||||
Licence MIT
|
||||
Author dengsgo [dengsgo@gmail.com]
|
||||
Website https://github.com/dengsgo/fileboy
|
||||
|
BIN
resources/jetbrains.png
Normal file
BIN
resources/jetbrains.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 164 KiB |
@@ -33,7 +33,7 @@ func newTaskMan(delay int, callUrl string) *TaskMan {
|
||||
if len(t.waitQueue) > 0 {
|
||||
cf := t.waitQueue[len(t.waitQueue)-1]
|
||||
if len(t.waitQueue) > 1 {
|
||||
logInfo("Number of redundant tasks dropped:", len(t.waitQueue)-1)
|
||||
logInfo("redundant tasks dropped:", len(t.waitQueue)-1)
|
||||
}
|
||||
t.waitQueue = []*changedFile{}
|
||||
go t.preRun(cf)
|
||||
@@ -69,8 +69,8 @@ func (t *TaskMan) dispatcher(cf *changedFile) {
|
||||
t.waitChan <- true
|
||||
return
|
||||
}
|
||||
logInfo("Waitting for the last task to finish")
|
||||
logInfo("Number of waiting tasks:", len(t.waitQueue))
|
||||
logInfo("waitting for the last task to finish")
|
||||
logInfo("waiting tasks:", len(t.waitQueue))
|
||||
} else {
|
||||
t.preRun(cf)
|
||||
}
|
||||
@@ -113,7 +113,7 @@ func (t *TaskMan) run(cf *changedFile) {
|
||||
}
|
||||
err = t.cmd.Wait()
|
||||
if err != nil {
|
||||
logWarn("command exec failed:", carr, err)
|
||||
logError("command exec failed:", carr, err)
|
||||
if keyInInstruction(InstIgnoreExecError) {
|
||||
continue
|
||||
}
|
||||
|
Reference in New Issue
Block a user