All Projects → joarwilk → Flowgen

joarwilk / Flowgen

Licence: other
Generate flowtype definition files from TypeScript

Programming Languages

typescript
32286 projects
flow
126 projects
flowtype
47 projects

Projects that are alternatives of or similar to Flowgen

Gltf To Usdz Research
Research and proof of concept of converting glTF to USDZ for AR Quick Look (iOS 12+).
Stars: ✭ 164 (-73.63%)
Mutual labels:  cli, converter
Arf Converter
Bulk ARF file converter
Stars: ✭ 10 (-98.39%)
Mutual labels:  cli, converter
Png To Ico
convert png to ico format
Stars: ✭ 88 (-85.85%)
Mutual labels:  cli, converter
Converter
database table to golang struct (table to struct) converter with cli and go lib support
Stars: ✭ 167 (-73.15%)
Mutual labels:  cli, converter
Density Converter
A multi platform image density converting tool converting single or batches of images to Android, iOS, Windows or CSS specific formats and density versions given the source scale factor or width/height in dp. It has a graphical and command line interface and supports many image types (svg, psd, 9-patch, etc.) aswell as some lossless compressors like pngcrush.
Stars: ✭ 222 (-64.31%)
Mutual labels:  cli, converter
Jet
CLI to transform between JSON, EDN and Transit, powered with a minimal query language.
Stars: ✭ 331 (-46.78%)
Mutual labels:  cli, converter
Sqawk
Like Awk but with SQL and table joins
Stars: ✭ 263 (-57.72%)
Mutual labels:  cli, converter
Remarshal
Convert between CBOR, JSON, MessagePack, TOML, and YAML
Stars: ✭ 421 (-32.32%)
Mutual labels:  cli, converter
Ignite Bowser
Bowser is now re-integrated into Ignite CLI! Head to https://github.com/infinitered/ignite to check it out.
Stars: ✭ 586 (-5.79%)
Mutual labels:  cli
Ponzu
Headless CMS with automatic JSON API. Featuring auto-HTTPS from Let's Encrypt, HTTP/2 Server Push, and flexible server framework written in Go.
Stars: ✭ 5,373 (+763.83%)
Mutual labels:  cli
Gifski
🌈 Convert videos to high-quality GIFs on your Mac
Stars: ✭ 5,691 (+814.95%)
Mutual labels:  converter
Rustfix
Automatically apply the suggestions made by rustc
Stars: ✭ 586 (-5.79%)
Mutual labels:  cli
Sqlitebiter
A CLI tool to convert CSV / Excel / HTML / JSON / Jupyter Notebook / LDJSON / LTSV / Markdown / SQLite / SSV / TSV / Google-Sheets to a SQLite database file.
Stars: ✭ 601 (-3.38%)
Mutual labels:  converter
Ffsend
📬 Easily and securely share files from the command line. A fully featured Firefox Send client.
Stars: ✭ 5,448 (+775.88%)
Mutual labels:  cli
Tailwindo
🔌 Convert Bootstrap CSS code to Tailwind CSS code
Stars: ✭ 606 (-2.57%)
Mutual labels:  converter
Python Mss
An ultra fast cross-platform multiple screenshots module in pure Python using ctypes.
Stars: ✭ 582 (-6.43%)
Mutual labels:  cli
Venice
Ruby Gem for In-App Purchase Receipt Verification
Stars: ✭ 578 (-7.07%)
Mutual labels:  cli
Dev Setup
macOS development environment setup: Easy-to-understand instructions with automated setup scripts for developer tools like Vim, Sublime Text, Bash, iTerm, Python data analysis, Spark, Hadoop MapReduce, AWS, Heroku, JavaScript web development, Android development, common data stores, and dev-based OS X defaults.
Stars: ✭ 5,590 (+798.71%)
Mutual labels:  cli
Very good cli
A Very Good Command Line Interface for Dart created by Very Good Ventures 🦄
Stars: ✭ 605 (-2.73%)
Mutual labels:  cli
Autocomplete
Autocomplete for terminals on MacOS
Stars: ✭ 569 (-8.52%)
Mutual labels:  cli

Flowgen

The state of the converter

It's surprisingly robust and non-lossy as it stands right now, in big part thanks to how similar flow and typescript definition files are. Please see the output in this flow-typed PR for the state of the output.

Supported? Syntax TypeScript Flow
Void type void void
Undefined type undefined void
Unknown type unknown mixed
Symbol type symbol Symbol
Unique symbol type unique symbol Symbol
Object type object {[key: string]: any}
Never type never empty
Variance interface A { readonly b: B, c: C } interface A { +b: B, c: C }
Functions (a: A, b: B) => C (a: A, b: B) => C
Indexers {[k: string]: string} {[k: string]: string}
This type (this: X, a: A, b: B) => C (a: A, b: B) => C
Type guards (a: X) => a is A (a: X) => boolean
Type parameter bounds function f<A extends string>(a:A){} function f<A: string>(a:A){}
keyof X keyof X $Keys<X>
X[keyof X] X[keyof X] $ElementType<X, $Keys<X>>
Partial Partial<X> $Rest<X, {}>
Readonly Readonly<X> $ReadOnly<X>
ReadonlyArray ReadonlyArray<X> $ReadOnlyArray<X>
ReadonlySet ReadonlySet<X> $ReadOnlySet<X>
ReadonlyMap ReadonlyMap<X, Y> $ReadOnlyMap<X, Y>
Record Record<K, T> { [key: K]: T }
Pick Pick<T, K>
Exclude Exclude<T, U>
Extract Extract<T, U>
NonNullable NonNullable<X> $NonMaybeType<X>
ReturnType ReturnType<F> $Call<<R>((...args: any[]) => R) => R, F>
InstanceType InstanceType<X>
Required Required<X>
ThisType ThisType<X>
T['string'] T['string'] $PropertyType<T, k>
T[k] T[k] $ElementType<T, k>
Mapped types {[K in keyof Obj]: Obj[K]} $ObjMapi<Obj, <K>(K) => $ElementType<Obj, K>>
Conditional types A extends B ? C : D any
typeof operator typeof foo typeof foo
Tuple type [number, string] [number, string]
Type alias type A = string type A = string
type/typeof import import A from 'module' import type A from 'module'

Usage

Install using npm i flowgen --save

import { compiler } from 'flowgen';

// To compile a d.ts file
const flowdef = compiler.compileDefinitionFile(filename);

// To compile a string
const flowdef = compiler.compileDefinitionString(str);

// To compile a typescript test file to JavaScript
// esTarget = ES5/ES6 etc
const testCase = compiler.compileTest(path, esTarget)

Recommended second step:

import { beautify } from 'flowgen';

// Make the definition human readable
const readableDef = beautify(generatedFlowdef);

CLI

Standard usage (will produce export.flow.js):

npm i -g flowgen
flowgen lodash.d.ts

Options

-o / --output-file [outputFile]: Specifies the filename of the exported file, defaults to export.flow.js

Flags for specific cases

--flow-typed-format: Format output so it fits in the flow-typed repo
--compile-tests: Compile any sibling <filename>-tests.ts files found
--no-inexact: Do not mark object types as inexact (using `...`)
--no-module-exports: Convert `export = Type` only to default export, instead of `declare module.exports: Type`
--interface-records: Convert TypeScript interfaces to Exact Objects
--no-jsdoc: Ignore TypeScript JSDoc
--add-flow-header: Add `// @flow` to generated files. Should be used for libs.

The difficult parts

Namespaces

Namespaces have been a big headache. What it does right now is that it splits any namespace out into prefixed global scope declarations instead. It works OK, but its not pretty and there's some drawbacks to it.

External library imports

Definitions in TS and flow are often quite different, and imported types from other libraries don't usually have a one-to-one mapping. Common cases are React.ReactElement, React.CSSPropsetc. This might require manual processing, or we add a set of hardcoded mutations that handle common cases.

Odd TS conventions

Lodash has been one of the reference libraries i've worked with when creating the converter. The definition is mostly just a series of interfaces with the same name being re-declared over and over again for each function, which doesn't translate to flow at all. There's multiple ways of solving this but I don't have a great solution for it in place yet.

Sample of finding all typescript definition files and generate flow file with shell script

If your typescript definition files are built in lib add below shell script and run it.

for i in $(find lib -type f -name "*.d.ts");
  do sh -c "flowgen $i -o ${i%.*.*}.js.flow";
done;

So if you have definition files in different dir, you can rename lib and run the script.

Contributing

All help is appreciated. Please tweet at me if you want some help getting started, or just want to discuss ideas on how to solve the trickier parts.

Distribution

  • git pull origin master
  • yarn compile
  • Change the version in package.json
  • git add .
  • `git commit -m "New release"
  • npm publish
  • git push
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].