简体   繁体   English

是否可以在.watchmanconfig中配置Watchman触发器?

[英]Is it possible to configure watchman triggers in .watchmanconfig?

Facebook watchman docs describe how to configure triggers by passing json into the command like so: Facebook看守文档描述了如何通过将json传递给命令来配置触发器,如下所示:

watchman --json-command < ./tasks/cmds/watchman-build-trigger.json where watchman-build-trigger.json contains the following: watchman --json-command < ./tasks/cmds/watchman-build-trigger.json -build- watchman --json-command < ./tasks/cmds/watchman-build-trigger.json其中watchman --json-command < ./tasks/cmds/watchman-build-trigger.json -build-trigger.json包含以下内容:

[
    "trigger", 
    "/Users/michaelprescott/Projects/neuro", 
    {
        "name": "build",
        "expression": [
            "anyof",
            [
                "match",
                "src/*.js",
                "wholename"
            ],
            [
                "match",
                "src/*.ts",
                "wholename"
            ],
            [
                "match",
                "src/*.html",
                "wholename"
            ]
        ],
        "command": [
            "./tasks/cmds/build.sh"
        ]
    }
]

However, I'm trying to understand how to use .watchmanconfig to setup a watch and set of triggers with watchman watch-project I have the following, but triggers aren't created. 但是,我试图了解如何使用.watchmanconfig通过watchman watchman watch-project来设置手表和触发器集,但我没有执行以下操作。 Is this possible? 这可能吗? Does anyone have examples for .watchmanconfig's 有没有人有.watchmanconfig的示例

{
    "ignore_dirs": [
        "node_modules"
    ],
    "watched": [
        {
            "path": "/Users/michaelprescott/Projects/neuro",
            "triggers": [
                {
                    "command": [
                        "./tasks/cmds/build.sh"
                    ],
                    "expression": [
                        "anyof",
                        [
                            "match",
                            "src/*.js",
                            "wholename"
                        ],
                        [
                            "match",
                            "src/*.ts",
                            "wholename"
                        ],
                        [
                            "match",
                            "src/*.html",
                            "wholename"
                        ]
                    ],
                    "name": "build"
                }
            ]
        }
    ]
}

No, it's not possible via .watchmanconfig . 不,通过.watchmanconfig The rationale is that, since .watchmanconfig is intended to be checked into a repo that may be cloned by arbitrary folks, we'd rather not allow it to be a vehicle by which arbitrary code could be run without those people explicitly taking an action to run it. 理由是,由于.watchmanconfig旨在被检查到可以由任意人克隆的存储库中,因此我们宁愿不允许它成为可以运行任意代码而无需那些人明确采取行动的工具。运行。

Our recommendation is to wrap up the trigger creation in a script of some kind that you can direct users to run when they would like to enable the triggering behavior. 我们的建议是将触发器创建包装在某种类型的脚本中,当用户希望启用触发行为时,可以指导用户运行该脚本。

In addition, I'd urge you to instead take a look at watchman-make for this use case; 另外,我敦促您代替这个用例看守望者 it has nicer ergonomics than triggers because it is very much easier to see the output from the commands that are being run and to terminate them when you want them to stop. 它具有比触发器更好的人体工程学,因为它很容易看到正在运行的命令的输出并在您希望它们停止时终止它们。

For example, you could implement your trigger this way instead: 例如,您可以改为通过以下方式实现触发器:

watchman-make -r tasks/cmds/build.sh -p 'src/*.js' -p 'src/*.ts' -p 'src/*.html'

(the single quotes are important!) (单引号很重要!)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM