Git Product home page Git Product logo

hsync's Introduction

hsync

基于fsnotify的实时文件同步工具

可用来帮助我们码农将本地办公电脑上的代码实时同步并部署到远程测试环境,以达到实时预览效果的目的。

【办公电脑】 -----(变化的文件)--(实时)----> 【测试机】

install

go get -u github.com/xieyuhua/hsync

go generate

useage

server:

hsync -d hsyncd.json

{
    "addr":":8700",
    "home":"./",
    "token":"abc",
    "deploy":[
        {"from":"a/","to":"d/"},
        {"from":"phpsrc/","to":"/home/work/app/phpsrc/"}
    ],
     "deployCmd":"bash deploy.sh /home/work/app/phpsrc/index.php phpsrc/index.php update"
}

说明:

  1. token:验证用,客户端和服务端必须保持一致
  2. deploy.from是以home为根目录的相对目录,deploy.to可以是相对目录或者决定目录
  3. deploy:同步完成后进行在对文件进行拷贝部署
  4. deployCmd:在每次deploy 之后运行,用来做一些自动化修改。如:"bash {pwd}/deploy.sh"
  5. "{pwd}":是配置文件当前目录
  6. home:本地保存接收文件的目录,可以是相对于配置文件的相对路径,也可以是绝对路径

deployCmd运行时的实际参数:

bash deploy.sh dst_path src_path update

即运行时会添加上参数 dst_path src_path update,deploy.sh脚本可以自己依据参数做一些业务逻辑

bash deploy.sh /home/work/app/phpsrc/index.php phpsrc/index.php update

deploy.sh demo

#!/bin/bash

DST=$1
SRC=$2
if [ "$SRC" == "a/d1" ];then
 grep -rl hello $DST |xargs -n 1 sed -i s/hello/nihao/g
fi

####force deploy all

hsync -deploy hsyncd.json

client:

hsync hsync.json

{
    "server":"127.0.0.1:8700",
    "home":"./",
    "token":"abc",
    "ignore":[
        "*.exe",
        "log/*"
    ]
}

说明:

  1. token:验证用,客户端和服务端必须保持一致
  2. home:是待同步文件的目录(也就是代码的workspace),可以是相对于配置文件的相对路径,也可以是绝对路径
  3. ignore:不同步到远端的忽略文件列表
  4. server: 服务端地址

默认忽略的文件:

.*
*~

Config File(asset.json)

> go generate
2022/03/07 14:21:44 [goasset] asset Config: {"src":"resource/","dest":"resource/asset.go","package":"resource","debug":""}
2022/03/07 14:21:44 [goasset] Current Dir: E:\gitdada\hsync\hsync
2022/03/07 14:21:44 [goasset] Total  0 Assets
2022/03/07 14:21:44 [goasset] pack asset success

{
  "src":"res|res2",
  "dest":"resource/asset.go",
  "package":"resource"
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.