Skip to content

Commit

Permalink
enable flow types on the back-end
Browse files Browse the repository at this point in the history
  • Loading branch information
AtnNn committed Aug 22, 2017
1 parent b2830c2 commit 8ea5dfa
Show file tree
Hide file tree
Showing 11 changed files with 88 additions and 91 deletions.
26 changes: 24 additions & 2 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@
"env": {
"es6": true
},
"extends": "eslint:recommended",
"plugins": [
"flowtype"
],
"extends": [
"eslint:recommended",
"plugin:flowtype/recommended"
],
"parserOptions": {
"ecmaVersion": 8,
"sourceType": "module"
Expand Down Expand Up @@ -43,6 +49,22 @@
"brace-style": ["error"],
"curly": ["error"],
"eqeqeq": ["error", "always", {"null": "never"}],
"no-multi-spaces": ["error"]
"no-multi-spaces": ["error"],
"flowtype/boolean-style": ["error", "boolean"],
"flowtype/define-flow-type": 1,
"flowtype/delimiter-dangle": ["error", "never"],
"flowtype/generic-spacing": ["error", "never"],
"flowtype/no-primitive-constructor-types": "error",
"flowtype/no-types-missing-file-annotation": "error",
"flowtype/no-weak-types": 0,
"flowtype/object-type-delimiter": ["error", "comma"],
"flowtype/require-parameter-type": 0,
"flowtype/semi": ["error", "always"],
"flowtype/space-after-type-colon": ["error", "always"],
"flowtype/space-before-generic-bracket": ["error", "never"],
"flowtype/space-before-type-colon": ["error", "never"],
"flowtype/union-intersection-spacing": ["error", "always"],
"flowtype/use-flow-type": "warn",
"flowtype/valid-syntax": "warn"
}
}
1 change: 0 additions & 1 deletion .flowconfig
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
<PROJECT_ROOT>/node_modules/.*/test/.*
<PROJECT_ROOT>/node_modules/styled-components/.*
<PROJECT_ROOT>/.git/.*
<PROJECT_ROOT>/server/.*
<PROJECT_ROOT>/public/.*

[include]
Expand Down
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ node_modules
.DS_Store
launch.json
*~
server/env.js
/env.js
/coverage
/build
npm-debug.log*
yarn-debug.log*
yarn-error.log*
server/run
/run
.env*
/*.tgz
/server-notypes
45 changes: 26 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,20 @@ the [CMPD Explorers Christmas Project].

# Getting Started

[NodeJS 7.9.0] is **required**. We recommend installing `nvm` if you're on a Mac so you can
[NodeJS 7.9.0] or above is **required**. We recommend installing `nvm` if you're on a Mac so you can
easily switch between Node versions on a per-project basis.

See [Dependencies Documentation](#dependencies-documentation) below for more information
on the dependencies we use.

Clone.
* Clone from github: `git clone https://github.com/CodeForCharlotte/cmpd-holiday-gift.git && cd cmpd-holiday-gift`
* Run `npm install` to install the dependencies.
* Run `npm run seed-server` to generate sample data.

Run `npm install` to install the dependencies.

Run `npm run seeds` to generate sample data.

Then run `npm start` to start the front end in development mode. Access
Then run `npm start-client` to start the front-end in development mode. Access
the application on http://localhost:3000.

In a separate terminal, run `npm run server-nodemon` to start the back
In a separate terminal, run `npm run nodemon-server` to start the back
end in development mode. The back end will run on port 3001 and the
development mode front end server will act as a reverse proxy for it.

Expand All @@ -37,8 +35,8 @@ To access the PHP version of the project from 2016 you can run `git checkout 1.3
### Resetting your database

When you pull changes to the database schema or sample data the application may stop working. When this occurs you need
to delete the SQLite database in `/server/run` and restart your server instance. After restarting the server be sure to
seed the database using `npm run seeds`. You should now be good to keep going!
to delete the SQLite database in `run/` and restart your server instance. After restarting the server be sure to
seed the database using `npm run seed-server`. You should now be good to keep going!

# Build for Production

Expand All @@ -48,7 +46,7 @@ Optionally run `npm prune --production`.

Start the production-mode server with `NODE_ENV=production npm run start-server`

# Front end development
# Front-end development

Static assets are in `public/`. The react app is in `src/`.

Expand All @@ -57,20 +55,17 @@ All front-end dependencies should be added using `npm install

# Back end development

The entire backend is in `server/`, except for the dependencies and
scripts which are in `package.json`.

Most commands in this section assume the working directory is `server/`.
The entire backend source is in `server/`. The dependencies and
scripts are in `package.json`. The logs, database and temporary test
files are placed in `run/`.

Optionally, set up a [mailtrap.io] account if you are working on
emails. Put your account info in `env.js` (see `env.example.js` for an
example).

Seed database: `node seeds`

Run tests: `npm test` <-- Not working yet
Seed database: `node seed-server`

Check and fix code style: `npm run lint`
Run tests: `npm test-server`

Why we chose Node.js over PHP: https://medium.com/fuzz/php-a0d0b1d365d8

Expand All @@ -94,6 +89,16 @@ The `private: true` property prevents a field from being output as JSON in API r

The `encrypt: true` property causes the field to be encrypted before storing it into the database.

# Tests, types and lint

Before pushing your code or sending a pull request, make sure the
tests pass and let [ESLint] clean up your code.

* To test the front-end: `npm run test-client`
* To test the back-end: `npm run test-server`
* To run eslint: `npm run lint`.
* To run the [flow] type-checker: `npm run flow`

# Dependencies Documentation

The backend is an [Express] application running in [Node]. Some newer
Expand Down Expand Up @@ -147,3 +152,5 @@ Coding style is enforced by [eslint].
[eslint]: http://eslint.org/docs/user-guide/getting-started
[NodeJS 7]: https://nodejs.org/en/download/current/
[Mustache]: https://www.npmjs.com/package/mustache
[ESLint]: https://eslint.org/docs/user-guide/getting-started
[flow]: https://flow.org/en/docs/
File renamed without changes.
23 changes: 14 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,27 @@
"version": "2017.1.0",
"private": true,
"scripts": {
"start": "cross-env-shell NODE_PATH=./src react-scripts start",
"build": "cross-env-shell NODE_PATH=./src react-scripts build",
"prepack": "cross-env-shell NODE_PATH=./src npm run build",
"start-client": "cross-env-shell NODE_PATH=./src react-scripts start",
"build-client": "cross-env-shell NODE_PATH=./src react-scripts build",
"test-client": "cross-env-shell NODE_PATH=./src react-scripts test --env=jsdom",
"start-server": "cd server && node apps/serve.js",
"test-server": "cd server && jasmine",
"build-server": "flow-remove-types --extensions '.js,.mail' --out-dir server-notypes server",
"start-server": "cd server-notypes && node apps/serve.js",
"test-server": "npm run build-server -- --quiet && cd server-notypes && jasmine spec/*.spec.js",
"nodemon-server": "cd server && nodemon -x flow-node apps/serve.js -w env.js -w apps -w models -w config -w ../node_modules",
"server-nodemon": "echo 'Please use `npm run nodemon-server` instead.' && false",
"seed-server": "flow-node server/seeds",
"prepack": "npm run build-client && npm run build-server",
"lint": "eslint -f unix --fix --ext js server src",
"server-nodemon": "cd server && nodemon apps/serve.js -w env.js -w apps -w models -w config -w ../node_modules",
"flow": "flow",
"seeds": "node server/seeds"
"test": "npm run test-client && npm run test-server",
"start": "echo 'Please use `npm run start-client` or `npm run start-server`.' && false"
},
"bin": {
"cmpd-explorers": "server/apps/serve.js"
"cmpd-explorers": "server-notypes/apps/serve.js"
},
"files": [
"build",
"server"
"server-notypes"
],
"main": "server/apps/serve.js",
"devDependencies": {
Expand Down Expand Up @@ -67,6 +71,7 @@
"compression": "^1.6.2",
"express": "~4.15.2",
"express-jwt": "^5.3.0",
"flow-remove-types": "^1.2.1",
"jsonwebtoken": "^7.4.1",
"morgan": "^1.8.1",
"mustache": "^2.3.0",
Expand Down
File renamed without changes.
File renamed without changes.
4 changes: 3 additions & 1 deletion server/apps/lib/asyncDo.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
module.exports = fun => {
// @flow

module.exports = (fun: () => Promise<void>) => {
setTimeout(() => {
fun().then(() => {}).catch((error) => {
console.error('Unhandled error:', error);
Expand Down
16 changes: 13 additions & 3 deletions server/config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,24 @@ var path = require('path');
var vm = require('vm');
var fs = require('fs');

// Default config values can be overridden by ../env.js
// Default config values can be overridden by ../../env.js

if (fs.existsSync(path.join(__dirname, '../run'))) {
console.error('Refusing to run: detected presence of `server/run/`. The `run/` folder should be moved to the root of the repository');
process.exit(1);
}

if (fs.existsSync(path.join(__dirname, '../env.js'))) {
console.error('Refusing to run: detected presence of `server/env.js`. The `env.js` file should be moved to the root of the repository');
process.exit(1);
}

var config = {};

config.run = path.join(__dirname, '../run');
config.run = path.join(__dirname, '../../run');
config.pid = process.pid;

var customEnvFile = path.join(__dirname, '../env.js');
var customEnvFile = path.join(__dirname, '../../env.js');

if (process.env.NODE_ENV === 'production') {
config.mode = 'production';
Expand Down
59 changes: 5 additions & 54 deletions src/.eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"browser": true
},
"extends": [
"plugin:flowtype/recommended",
"plugin:react/recommended"
],
"parserOptions": {
Expand All @@ -13,64 +12,16 @@
}
},
"rules": {
"flowtype/boolean-style": [
2,
"boolean"
],
"flowtype/define-flow-type": 1,
"flowtype/delimiter-dangle": [
2,
"never"
],
"flowtype/generic-spacing": [
2,
"never"
],
"flowtype/no-primitive-constructor-types": 2,
"flowtype/no-types-missing-file-annotation": 2,
"flowtype/no-weak-types": 0,
"flowtype/object-type-delimiter": [
2,
"comma"
],
"flowtype/require-parameter-type": 0,
"flowtype/require-return-type": [
2,
"always",
{
"annotateUndefined": "never",
"excludeArrowFunctions": true
}
],
"flowtype/require-valid-file-annotation": [ 2, "always" ],
"flowtype/semi": [
2,
"always"
],
"flowtype/space-after-type-colon": [
2,
"always"
],
"flowtype/space-before-generic-bracket": [
2,
"never"
],
"flowtype/space-before-type-colon": [
2,
"never"
],
"flowtype/union-intersection-spacing": [
2,
"always"
],
"flowtype/use-flow-type": 1,
"flowtype/valid-syntax": 1,
"flowtype/require-valid-file-annotation": [ "error", "always" ],
"flowtype/require-return-type": ["error", "always", {
"annotateUndefined": "never",
"excludeArrowFunctions": true
}],
"react/prop-types": 0,
"no-console": 0,
"no-duplicate-imports": 0
},
"plugins": [
"flowtype",
"react"
]
}

0 comments on commit 8ea5dfa

Please sign in to comment.