Skip to content

Latest commit

 

History

History
147 lines (94 loc) · 3.38 KB

TOOL_watchman.md

File metadata and controls

147 lines (94 loc) · 3.38 KB

#facebook watchman

watch 某个目录

watchman watch /path/to/dir

删除 某个watched 目录

watchman watch-del /path/to/dir

查看 watch list

watchman watch-list

设置trigger

watchman -- trigger /path/to/dir triggername [patterns] -- [cmd]

patterns 必须使用单引号 '' , 如 '*.txt'

match 模式: '*.lua' , 只会出发 根目录下的 lua 文件

正则查询: -p '.lua$' , 所有 .lua 后缀的文件

删除某个 trigger

watchman trigger-del /path/to/dir triggername

查看 trigger 列表

watchman trigger-list /path/to/dir

关闭watchman 服务

watchman shutdown-server

查看 watchman 相关路径设置

ps -ef | grep watchman

一个简单的 监视 lua 文件改动的例子

WATCH_ROOT=$PWD/../Resources/lua_scripts
DIST_FOLDER=$PWD/tmp
echo python $PWD/watch.py $WATCH_ROOT $DIST_FOLDER
watchman -- trigger $WATCH_ROOT watchLua  -p '.lua$'  -- python $PWD/watch.py $WATCH_ROOT $DIST_FOLDER

监视 Resources/lua_scripts, 如果有 lua 文件发生修改,调用 watch.py 脚本,处理文件同步。

import os,sys , shutil


if len( sys.argv )>3:
    #print "py notifie:" , sys.argv[1:]
    WATCH_ROOT = sys.argv[1]
    DIST_FOLDER = sys.argv[2]

    print "all args:" , sys.argv[1:]

    if not os.path.exists( DIST_FOLDER ):
        os.makedirs( DIST_FOLDER )


    for v in sys.argv[3:]:
        print "py notifie:" , v

        full_path_src = os.path.join(  WATCH_ROOT , v  )

        #flatten dist path , all lua file will in same flat folder
        _,v  = os.path.split( v )
        
        # full path of dist file
        full_path_dist = os.path.join( DIST_FOLDER, v ) 
        path , f = os.path.split( full_path_dist )
        path2createOrDelete =  path

        #try to make dir
        if not os.path.exists( path2createOrDelete ):
            os.makedirs( path2createOrDelete )
        pass

        if os.path.exists( full_path_src  ):
            shutil.copy( full_path_src , full_path_dist )

        # src not exists, but dist exists
        elif os.path.exists( full_path_dist  ) :
            os.remove(full_path_dist)