diff --git a/.gitignore b/.gitignore index 6cdb689..f743b2a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,7 @@ build/.* .idea conf/conf.yml -conf/conf.example.yml \ No newline at end of file +conf/conf.example.yml + +release/ +packages/ \ No newline at end of file diff --git a/Makefile.cross-compiles b/Makefile.cross-compiles new file mode 100644 index 0000000..dba64c6 --- /dev/null +++ b/Makefile.cross-compiles @@ -0,0 +1,22 @@ +export PATH := $(GOPATH)/bin:$(PATH) +export GO111MODULE=on +LDFLAGS := -s -w + +os-archs=darwin:amd64 darwin:arm64 linux:amd64 linux:arm64 windows:amd64 windows:arm64 + +all: build + +build: app + +app: + @$(foreach n, $(os-archs),\ + os=$(shell echo "$(n)" | cut -d : -f 1);\ + arch=$(shell echo "$(n)" | cut -d : -f 2);\ + gomips=$(shell echo "$(n)" | cut -d : -f 3);\ + target_suffix=$${os}_$${arch};\ + echo "Build $${os}-$${arch}...";\ + GOOS=$${os} GOARCH=$${arch} GOMIPS=$${gomips} go build -trimpath -ldflags "$(LDFLAGS)" -o ./release/helloword_$${target_suffix} main.go;\ + echo "Build $${os}-$${arch} done";\ + ) + @mv ./release/helloword_windows_amd64 ./release/helloword_windows_amd64.exe + @mv ./release/helloword_windows_arm64 ./release/helloword_windows_arm64.exe diff --git a/README.md b/README.md index cdf98af..c378dc2 100644 --- a/README.md +++ b/README.md @@ -43,7 +43,7 @@ notify: # 通知配置,目前支持telegram,dingtalk,lark可以全配, 指定单词数量,随机选择单词,生成一段小短文,推送到用户指定平台。 ```shell -go run main.go daemon --files="CET4.txt,CET6.txt" --spec="@every 10s" --word-number=8 +./helloword daemon --files="CET4.txt,CET6.txt" --spec="@every 10s" --word-number=8 ``` **参数说明** @@ -65,7 +65,7 @@ go run main.go daemon --files="CET4.txt,CET6.txt" --spec="@every 10s" --word-num ### 指定单词,直接生成短语 ```shell -go run main.go phrase "approach,proportion,academy,weapon" +./helloword phrase "approach,proportion,academy,weapon" ``` ### 单词游戏 @@ -78,7 +78,7 @@ go run main.go phrase "approach,proportion,academy,weapon" 使用 ```shell -go run main.go games chain --files="CET4.txt,CET6.txt" +./helloword games chain --files="CET4.txt,CET6.txt" ``` **参数说明** diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..17ec4ed --- /dev/null +++ b/build.sh @@ -0,0 +1,44 @@ + + +# cross_compiles +make -f ./Makefile.cross-compiles +rm -rf ./release/packages +mkdir -p ./release/packages + +os_all='linux windows darwin' +arch_all='amd64 arm64' + +cd ./release + +for os in $os_all; do + for arch in $arch_all; do + hello_dir_name="helloword_${os}_${arch}" + hello_path="./packages/helloword_${os}_${arch}" + + if [ "x${os}" = x"windows" ]; then + if [ ! -f "./helloword_${os}_${arch}.exe" ]; then + continue + fi + mkdir ${hello_path} + mv ./helloword_${os}_${arch}.exe ${hello_path}/helloword.exe + else + if [ ! -f "./helloword_${os}_${arch}" ]; then + continue + fi + mkdir ${hello_path} + mv ./helloword_${os}_${arch} ${hello_path}/helloword + fi + cp ../LICENSE ${hello_path} + cp -rf ../library/* ${hello_path} + + # packages + cd ./packages + if [ "x${os}" = x"windows" ]; then + zip -rq ${hello_dir_name}.zip ${hello_dir_name} + else + tar -zcf ${hello_dir_name}.tar.gz ${hello_dir_name} + fi + cd .. + rm -rf ${hello_path} + done +done diff --git a/collector/file/file.go b/collector/file/file.go index 943019a..a7c4cb0 100644 --- a/collector/file/file.go +++ b/collector/file/file.go @@ -4,7 +4,6 @@ import ( "bufio" "context" "os" - "path/filepath" "strings" "github.com/wuqinqiang/helloword/logging" @@ -20,9 +19,8 @@ type File struct { func New(fileNames string) *File { file := new(File) - for _, name := range strings.Split(fileNames, ",") { - // hard code - file.fileList = append(file.fileList, filepath.Join("library", name)) + for _, fileName := range strings.Split(fileNames, ",") { + file.fileList = append(file.fileList, fileName) } return file }