简体   繁体   English

将流类型检查添加到grunt服务器开发工作流

[英]Adding flow type-checking to grunt server development workflow

I have added grunt-flow-type-check to my Gruntfile.js and it is working within watch . 我已经在我的Gruntfile.js添加了grunt-flow-type-check ,它在watch How can I add a task to strip the flow-type-annotations out of the code sent to the browser? 如何添加任务以从发送到浏览器的代码中剥离流类型注释?

flow server seems to do this automatically, but I would like to be using the flow checking within my existing grunt-server based development workflow. 流服务器似乎自动执行此操作,但是我想在现有的基于grunt-server的开发工作流中使用流检查。

Also, how can I also add custom interface files to be referenced by grunt-flow-type-check and not have to include declarations in my actual code? 另外,如何也可以添加要由grunt-flow-type-check引用的自定义接口文件,而不必在实际代码中包含声明?

I just set this all up myself a couple days ago. 我只是几天前自己设置的。

To just strip the annotations, you have to use the react jsx transpiler. 要仅删除注释,您必须使用react jsx transpiler。

Install the transpiler: npm install -g react-tools 安装transpiler: npm install -g react-tools

Running the transpiler: jsx --strip-types --harmony --watch src/ build/ 运行编译器: jsx --strip-types --harmony --watch src/ build/

Using this as part of your grunt build is accomplished by using grunt shell. 通过使用grunt shell将其用作grunt构建的一部分。 ( Grunt shell info ) 咕unt的外壳信息

Grunt shell lets you use shell commands as part of your grunt build. Grunt Shell使您可以将Shell命令用作Grunt构建的一部分。 In my case I use it to both run the type checker and the transpiler, before the rest of my js build. 就我而言,在其余的js构建之前,我都使用它来运行类型检查器和编译器。

My setup here will run the type checker and then strip the annotations if no errors were found: 如果没有发现错误,这里的设置将运行类型检查器,然后剥离注释:

    shell: {
        'flow': {
            command: [
                'cd path/to/your/js',
                'flow check --lib globals_lib'
            ].join('&&')
        },
        'transpile': {
            command: 'jsx --strip-types path/to/src/ path/to/dist/',
            stdout: true,
            failOnError: true
        }
    },

As for your second question. 至于第二个问题。 The --lib flag above allows you to have a file (or multiple files) that contain all your declarations. 上面的--lib标志使您可以拥有一个包含所有声明的文件(或多个文件)。 In this case I follow fb's example and just a have a globals_lib folder with a file called globals.js inside, which has all my declarations (jQuery, _, etc). 在这种情况下,我按照fb的示例进行操作,只是有一个globals_lib文件夹,其中包含一个名为globals.js的文件,其中包含我的所有声明(jQuery,_等)。

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

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