Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I implement Flow? #907

Closed
Dionid opened this issue Jun 28, 2018 · 7 comments
Closed

How can I implement Flow? #907

Dionid opened this issue Jun 28, 2018 · 7 comments
Assignees

Comments

@Dionid
Copy link

Dionid commented Jun 28, 2018

I'm trying to use Flow with AdonisJS.

I want my app to work in adonis serve --dev --debug mode, but with Flow type checking.

I have idea to create folder like flowApp write code there, run something like nodemon that will transpile code to app folder, where adonis serve --dev --debug will get code and reload server. What do you think about this idea? Is there better way to use Flow in Adonis?

@Dionid
Copy link
Author

Dionid commented Jun 28, 2018

I think I've discovered answer. I'll write it here in a days.

@Dionid
Copy link
Author

Dionid commented Jul 3, 2018

So, that's what I've ended up with:

Stack

Folder structer

In the root directory (where app folder is), I've created appFlow folder (you can name it as you wish) and copy everything from app. That's what it looks like:

/app
/appFlow
/config
...

Package.json

{
    ...
    "scripts": {
    ...
    "dev": "adonis serve --dev --debug",
    "flow": "flow",
    "flow:deps": "flow-typed install",
    "babel:build": "babel appFlow -d app",
    "babel:watch": "babel appFlow --watch -d app"
  },
  "dependencies": {
    ....
  },
  "devDependencies": {
    "babel-cli": "6.26.0",
    "babel-eslint": "8.2.5",
    "babel-plugin-tcomb": "0.3.26",
    "babel-preset-env": "1.7.0",
    "babel-preset-flow": "6.23.0",
    "eslint": "4.19.1",
    "eslint-config-airbnb-base": "13.0.0",
    "eslint-plugin-flowtype": "2.49.3",
    "eslint-plugin-import": "2.13.0",
    "flow-bin": "0.75.0",
    "flow-typed": "2.4.0",
    "tcomb": "3.2.27"
  }
  ...
}

.babelrc

{
  "presets": [
    ["env", {
      "targets": {
        "node": "10.5"
      }
    }],
    "flow"
    ],
  "plugins": [
    "syntax-flow",
    "tcomb",
    "transform-flow-strip-types"
  ]
}

.eslintrc.js

module.exports = {
  "extends": ["airbnb-base", 'plugin:flowtype/recommended'],
  plugins: [
    'import',
    'flowtype',
  ],
  parser: 'babel-eslint',
  env: {
    node: true,
  },
};

.flowconfig

[ignore]
.*/node_modules/.*

[include]


[libs]
flow-typed

[lints]

[options]
all=true

[strict]

Start

To start everything working you need to open 2 terminals:

  1. one with npm run dev (or adonis serve --dev --debug)
  2. the other for npm run babel:watch (or babel appFlow --watch -d app).

When you make changes in any appFlow file (like adding new types or something) babel transpile it in to app folder, where adonis serve see changes, grab them and reload itself.

Lifehacks

  1. One of the best thing is that now I can describe props in Lucid models like this:
class User extends Model {

  id:number
  email:string
  password:string
  deleted:boolean

  static boot () {
    ...
  }

  ...

}

P.S.

I'll appreciate and advices or questions.

.

@thetutlage
Copy link
Member

@Dionid Thanks for sharing. I will close the issue, since it's not actionable on my end

@jakesylvestre
Copy link

@thetutlage what are your thoughts on implementing flow in the library?

@jakesylvestre
Copy link

@Dionid did you define global functions (e.g. use())?

@jakesylvestre
Copy link

jakesylvestre commented Oct 18, 2018

For reference: facebook/flow#7014

Also, if you're coming off google reading this, I'd check out adonisjs/discussion#65

@lock
Copy link

lock bot commented Mar 11, 2020

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked and limited conversation to collaborators Mar 11, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants