A command line interface for working with flow-runtime and Flow.
What?
Discovers imported and global type dependencies in your source code and produces a single file containing the flow-runtime type definitions for those dependencies.
Storage is a global type, built in to Flow, but flow-runtime itself doesn't know anything about it - if you compile this code, flow-runtime will emit a warning about being unable to resolve a type called "Storage".
A possible solution to this would be to include all the type definitions which come with Flow as part of flow-runtime, but this is wasteful - the file would be very large and most definitions would go unused.
To solve this problem, flow-runtime-cli:
Crawls your project source code looking for these types.
Discovers the matching type definitions in flow-typed or wherever specified by your .flowconfig file.
Creates a graph of dependencies and generates the code for only the types you use, this produces a file that looks like this:
import t from "flow-runtime";t.declare( t.class( "Storage", t.object( t.property("length", t.number()), t.property( "getItem", t.function(t.param("key", t.string()), t.return(t.nullable(t.string()))) ), t.property( "setItem", t.function( t.param("key", t.
You can then import this file once, in your entry point, and flow-runtime will be able to validates values of this type.
Installation
npm install flow-runtime-cli
or
yarn add flow-runtime-cli
Usage
If your source files are in a folder called src, run:
flow-runtime generate ./src > ./src/typedefs.js
then, in your entry point (e.g. index.js) your first import should be: