## Dependencies

`bower_components` = from bower

`node_modules` = from npm

`patched_modules` = locally patched modules

For modules you want to quickly patch. Fork in Github. Create a branch with
the name of this project. Make a git dependency to this branch in package.json.

`npm link --ignore-scripts patched_modules/react-leaflet`

## Webpack

See here to optimize the build: https://github.com/petehunt/webpack-howto

## DB

http: `open ec2-52-24-35-142.us-west-2.compute.amazonaws.com`

ssh: `ssh -i /Users/Vaughan/dev-quantitec/aws/root/intranav.pem.txt -l ubuntu ec2-52-24-35-142.us-west-2.compute.amazonaws.com`

## App Server

copy `/Users/Vaughan/dev-quantitec/aws/root/intranav.pem.txt` to `~/.ssh` and rename to `intranav`
ssh: `eb ssh`

### ssh root

`ssh intranav-staging`

```
~/.ssh/config

Host intranav-staging

  HostName      ec2-52-11-223-199.us-west-2.compute.amazonaws.com
  User          root
  IdentityFile  ~/.ssh/intranav
```

---

follow node.js logs: `eb ssh && tail -f /var/log/nodejs/nodejs.log`


follow all logs: `eb ssh && tail -f /var/log/*` NOTE: Doesn't recurse.

TODO: Deploy with Docker...or maybe not.

Enable root access to use `Remote Host` pane in IntelliJ.
http://blog.tiger-workshop.com/enable-root-access-on-amazon-ec2-instance/

## TODO

- Add check for `fsevents` on OSX.

## SLC

Create `.aws/config`:

```
[profile <global.profile from `.elasticbeanstalk/config.yml`>]
aws_access_key_id = <insert>
aws_secret_access_key = <insert>
```

We can build our app to the deploy branch, and then deploy that to EB.

If we want to deploy a zip to EB instead:
http://stackoverflow.com/questions/28763205/exclude-directories-from-elastic-beanstalk-deploy

`slc build`
`git show deploy:./`

`ssh intranav-staging`

## Style

Separate relative and module imports.

# Type checking

`flow check`

# Server Startup Time Performance

```
gulp server --require time-require --sorted
CTRL+C
```

NOTE: `timeRequire.js` must be modified to use:

```
process.on("SIGINT", function() {
```

# Deploy Debugging

Use `Tools > Deployment > Browse Remote Hosts` in IntelliJ.

Then you can `Alt + Shift + Q` to upload any file changes to test things out.

```
ssh intranav-staging
```

```
su - nodejs -c 'NODE_ENV=staging gulp build'

>>> The account is currently not available

Because shell is set to /sbin/nologin
```

```
NODE_ENV=staging gulp build && chown -R nodejs:nodejs build/
```

NOTE: Must use `nodejs` user, otherwise you will get `EACCESS` errors in gulp/npm because the deploy script uses
the `nodejs` user, and if you are logged in as root, `build` will be locked to `root` user.

This will rebuild the assets on the server.

Takes about 43s with Uglify/Dedupe.
Takes 16s without it.

In the future we will probably do compilation elsewhere, like on continuous integration server, or bundle into docker.

## RSYNC

Deploy to server minus `node_modules` and `bower_components`. Instant deploy.

WARNING: Remove `patched_modules` because of symlink in node_modules. You must keep your modules up to date if `delete-excluded` option is used.

`gulp dev-deploy`

### Testing rsync

To check that our rsync task is updating only the neccessary files:

```
eb ssh
cd /var/app
cp -pR current currentbak
gulp dev-deploy
rm -rf current
cp -pR currentbak current 
```

Ensure only locally changed files are being transferred.

## Start and Stop remote server 

```
/opt/elasticbeanstalk/hooks/appdeploy/enact/10stop.sh
/opt/elasticbeanstalk/hooks/appdeploy/enact/50start.sh
```

## cp -pR -- keep permissions

# Deploy times

28/05/2015 -- 46s

# Deploy assets remotely

Not good because server-side rendering. Better to use other task.

`time gulp frontend-deploy --env staging`

# Use time-require

`webpack --profile --json > stats.json`

# Debug asset compilation process

```
eb ssh

cd /tmp/deployment/application
sudo /opt/elasticbeanstalk/hooks/appdeploy/pre/90assets.sh
```

# OSX terminal hyperlinks to code locations

See https://youtrack.jetbrains.com/issue/IDEA-65879

On OSX you can hold down CMD and double click on an url in the console to open it.

Use `http://www.rubicode.com/Software/RCDefaultApp/` to setup.

TODO
