GithubHelp home page GithubHelp logo

gen-flow-files's Introduction

gen-flow-files

npm version npm downloads

This is a script which finds .js files with @flow annotation, extract flow definitions and save to specific folder.

As example, <inputDir>/example.js

// @flow

extract function foo(arg1: number, arg2: string): string {
    // some code here
}

will be transformed to <outputDir>/example.js.flow:

// @flow

declare extract function foo(arg1: number, arg2: string): string;

Installation

Install it with yarn:

yarn add gen-flow-files

Or with npm:

npm i gen-flow-files --save

Usage

As part of build process

scripts": {
    ...
    "flow": "flow",
    "build:flow": "gen-flow-files src --out-dir dist",
    ...
  },

transfrom all .js files from src to .js.flow files and save them at dist.

As command

npx gen-flow-files <inputDir> --out-dir <outputDir>

transfrom all .js files from <inputDir> to .js.flow files and save them at <outputDir>.

gen-flow-files's People

Contributors

creatorrr avatar ilyalesik avatar nshahri avatar tsmmark avatar valoricde avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

gen-flow-files's Issues

BUG: error thrown from ClassDeclaration

Issue: When generating .flow.js files the build fails with the following error: TypeError: Property name expected type of string but got null

Steps to reproduce:

  1. Try to run gen-flow-files on a Class structured like this:
type ResponseObject = {
  body: mixed,
  callback: () => void,
  error: string,
  statusCode: number,
};

class RandomUtil {
    static RandomUtilReturn({ body, callback, error, statusCode } : ResponseObject) {
...

Expected Result:

  • A randomUtil.flow.js file

Actual Result:

  • An error
  • No files generated

Additional:

  • It only happens when a method in the class is using an object spread in the arguments.

Environment:
macOS 10.14.2
node v8.11.3
yarn v1.5.1
flow-bin v^0.94.0
gen-flow-files v^0.4.3

BUG: generation fails

Issue: When running yarn run gen-flow-files src --out-dir lib an error is thrown
Steps to reproduce:

  1. Install gen-flow-files via yarn
    2.Run yarn run gen-flow-files src --out-dir lib

Expected behaviour:

  • lib folder to contain types extracted from src folder
    Actual behaviour:
  • Error in code block below is thrown

Environment:

  • macOS 10.14.2
  • node v8.11.3
  • yarn v1.5.1
  • flow-bin v^0.93.0
  • gen-flow-files v^0.4.1

Additional:

  • I have attempted the build version with node v10, latest version of flow-bin and gen-flow-files
  • This was working at last run on a different machine 1 month ago
njm-scripts [master●●] % yarn run gen-flow-files src --out-dir lib
yarn run v1.5.1
$ /Users/nazimjamil/Sites/njm-test/njm-scripts/node_modules/.bin/gen-flow-files src --out-dir lib
/Users/nazimjamil/Sites/njm-test/njm-scripts/node_modules/@babel/generator/lib/printer.js:277
      throw new ReferenceError(`unknown node of type ${JSON.stringify(node.type)} with constructor ${JSON.stringify(node && node.constructor.name)}`);
      ^

ReferenceError: unknown node of type "Property" with constructor "Node"
    at Generator.print (/Users/nazimjamil/Sites/njm-test/njm-scripts/node_modules/@babel/generator/lib/printer.js:277:13)
    at Generator.printJoin (/Users/nazimjamil/Sites/njm-test/njm-scripts/node_modules/@babel/generator/lib/printer.js:362:12)
    at Generator.printList (/Users/nazimjamil/Sites/njm-test/njm-scripts/node_modules/@babel/generator/lib/printer.js:422:17)
    at Generator.ObjectExpression (/Users/nazimjamil/Sites/njm-test/njm-scripts/node_modules/@babel/generator/lib/generators/types.js:69:10)
    at withSource (/Users/nazimjamil/Sites/njm-test/njm-scripts/node_modules/@babel/generator/lib/printer.js:299:19)
    at Buffer.withSource (/Users/nazimjamil/Sites/njm-test/njm-scripts/node_modules/@babel/generator/lib/buffer.js:185:28)
    at Generator.withSource (/Users/nazimjamil/Sites/njm-test/njm-scripts/node_modules/@babel/generator/lib/printer.js:178:15)
    at Generator.print (/Users/nazimjamil/Sites/njm-test/njm-scripts/node_modules/@babel/generator/lib/printer.js:298:10)
    at Generator.ExportDeclaration (/Users/nazimjamil/Sites/njm-test/njm-scripts/node_modules/@babel/generator/lib/generators/modules.js:114:10)
    at Generator.ExportDefaultDeclaration (/Users/nazimjamil/Sites/njm-test/njm-scripts/node_modules/@babel/generator/lib/generators/modules.js:108:21)
error An unexpected error occurred: "Command failed.
Exit code: 1
Command: sh
Arguments: -c /Users/nazimjamil/Sites/njm-test/njm-scripts/node_modules/.bin/gen-flow-files src --out-dir lib
Directory: /Users/nazimjamil/Sites/njm-test/njm-scripts
Output:
".
info If you think this is a bug, please open a bug report with the information provided in "/Users/nazimjamil/Sites/eps/eps-guild/eps-scripts/yarn-error.log".
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

BUG: error thrown from ClassDeclaration when using argument default

Issue: When generating .flow.js files the build fails with the following error: TypeError: Property name expected type of string but got null

Steps to reproduce:

Try to run gen-flow-files on a Class structured like this:

type TitleType = {
  title: 'Mr' | 'Ms' | 'Dr',
};

class TestClass {
    static TestClassFunc(title: TitleType = 'Mr') {
    ...

Expected Result:

  • A testClass.flow.js file

Actual Result:

  • An error
  • No files generated

Additional:

It only happens when a method in the class is using a default in the arguments.
Environment:
macOS 10.14.2
node v8.11.3
yarn v1.5.1
flow-bin v^0.94.0
gen-flow-files v^0.4.4

Use as babel plugin?

Thanks for building this!
I'm trying to bundle all my source code into one single .js.flow file. Is it possible to do so with this project?
I did notice there's a plugin.js file in src. Is it possible to use this project as a babel plugin and achieve my goal?

Would really appreciate any help!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.