Skip to content

Commit

Permalink
Merge pull request #90 from IGME-Research-Studio/IS-89-babel-fix
Browse files Browse the repository at this point in the history
Swap Babel hook for explicit registration
  • Loading branch information
dropofwill committed Oct 28, 2015
2 parents 7d82f9d + 5f2c716 commit 7a898d4
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 56 deletions.
35 changes: 22 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,40 @@ Server for our Brainstorm App, a [Sails](http://sailsjs.org) application.
Clone the repo.

```
$ git clone git@github.com:IGME-Research-Studio/StormServer.git
$ cd StormServer
$ npm install
$ npm install -g grunt-cli
$ git clone git@github.com:IGME-Research-Studio/StormServer.git
$ cd StormServer
$ npm install
$ npm install -g grunt-cli
```

### Commands
```
# Lift the sails server
$ npm start
# Lift the sails server
$ npm start
# Run the test suite
$ npm test
# Lift the sails server in debug mode
$ npm run debug
# Check the source code for stylistic correctness
$ npm run lint
# Check the source code for stylistic correctness
$ npm run lint
# Run the unit tests
$ npm run unit-test
# Run the linter followed by the test suite
$ npm test
# Lift the sails server in debug mode
$ npm run debug
```

## Contributing guide

See [CONTRIBUTING.md](CONTRIBUTING.md) for contributing guidelines.

We use ES6 JavaScript transpiled with Babel and enforced by Airbnb's eslint config.

One hiccup is that files in the `config/` folder are loaded inside Sails and thus are not transpiled by default. All you need to do is explicitly tell Babel to transpile a config file by putting `require('babel/register')` at the top of the file.

Technically this only needs to be done on one config file, but since there are no guarantees on what order sails loads these files (being objects and all), it's safer to just be explicit.

## Documentation

Github page coming soon.
Expand Down
41 changes: 2 additions & 39 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
* => `modulus deploy`
* => `heroku scale`
*
*
* The same command-line arguments are supported, e.g.:
* `node app.js --silent --port=80 --prod`
*/
Expand All @@ -22,41 +21,5 @@
// no matter where we actually lift from.
process.chdir(__dirname);

// Ensure a "sails" can be located:
(function() {
let sails;
try {
sails = require('sails');
}
catch (e) {
console.error('To run an app using `node app.js`, you usually need to have a version of `sails` installed in the same directory as your app.');
console.error('To do that, run `npm install sails`');
console.error('');
console.error('Alternatively, if you have sails installed globally (i.e. you did `npm install -g sails`), you can use `sails lift`.');
console.error('When you run `sails lift`, your app will still use a local `./node_modules/sails` dependency if it exists,');
console.error('but if it doesn\'t, the app will run with the global sails instead!');
return;
}

// Try to get `rc` dependency
let rc;
try {
rc = require('rc');
}
catch (e0) {
try {
rc = require('sails/node_modules/rc');
}
catch (e1) {
console.error('Could not find dependency: `rc`.');
console.error('Your `.sailsrc` file(s) will be ignored.');
console.error('To resolve this, run:');
console.error('npm install rc --save');
rc = function () { return {}; };
}
}


// Start server
sails.lift(rc('sails'));
})();
require('babel/register');
require('sails').lift(require('rc')('sails'));
1 change: 1 addition & 0 deletions config/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
* http://sailsjs.org/#!/documentation/reference/sails.config/sails.config.bootstrap.html
*/

require('babel/register');
module.exports.bootstrap = function(cb) {

// It's very important to trigger this callback method when you are finished
Expand Down
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"name": "StormServer",
"version": "0.0.6",
"version": "0.0.7",
"description": "Storm app server",
"scripts": {
"debug": "sails lift --verbose",
"start": "sails lift",
"debug": "sails lift --verbose",
"test": "grunt test",
"unit-test": "grunt unit-test",
"lint": "grunt lint",
Expand All @@ -19,6 +19,7 @@
"private": true,
"license": "UNLICENSED",
"dependencies": {
"babel": "^5.8.29",
"bcryptjs": "^2.2.2",
"ejs": "~0.8.4",
"grunt": "0.4.2",
Expand Down Expand Up @@ -46,7 +47,7 @@
"sails": "~0.11.0",
"sails-disk": "~0.10.0",
"sails-generate-auth": "^0.3.1",
"sails-hook-babel": "^5.0.1",
"validator": "^4.0.6",
"sails-mongo": "^0.11.4",
"sails-service-error-codes": "^1.0.5",
"shortid": "^2.2.2",
Expand Down
2 changes: 1 addition & 1 deletion test/bootstrap.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const options = {
extensions: null,
};

global.babel = require('sails-hook-babel/node_modules/babel/register')(options);
global.babel = require('babel/register')(options);

before(function(done) {

Expand Down

0 comments on commit 7a898d4

Please sign in to comment.