Skip to content

Commit

Permalink
Merge pull request #136 from iam4x/babel6
Browse files Browse the repository at this point in the history
update to babel6
  • Loading branch information
Max Tyler committed Feb 25, 2016
2 parents c79638a + f664636 commit 9d0e784
Show file tree
Hide file tree
Showing 16 changed files with 87 additions and 61 deletions.
36 changes: 22 additions & 14 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -1,20 +1,28 @@
{
"stage": 0,
"presets": [ "es2015", "react", "stage-0" ],
"plugins": [
"transform-decorators-legacy",
"add-module-exports"
],
"env": {
"browser": {
"plugins": ["react-transform"],
"extra": {
"react-transform": {
"transforms": [{
"transform": "react-transform-hmr",
"imports": ["react"],
"locals": ["module"]
}, {
"transform": "react-transform-catch-errors",
"imports": ["react", "redbox-react"]
}]
}
}
"plugins": [
"transform-decorators-legacy",
"add-module-exports",
["react-transform", {
"transforms": [
{
"transform": "react-transform-hmr",
"imports": [ "react" ],
"locals": [ "module" ]
},
{
"transform": "react-transform-catch-errors",
"imports": [ "react", "redbox-react" ]
}
]
}]
]
}
}
}
2 changes: 1 addition & 1 deletion app/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Browser ES6 Polyfill
require('babel/polyfill');
require('babel-polyfill');

// Start application
require('./main');
2 changes: 1 addition & 1 deletion app/utils/intl-polyfill.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const hasBuiltInLocaleData = (locale) =>
(Intl.NumberFormat.supportedLocalesOf(locale)[0] === locale &&
Intl.DateTimeFormat.supportedLocalesOf(locale)[0] === locale);

export default (locales) => {
module.exports = (locales) => {
if (!process.env.BROWSER) {
if (global.Intl) {
if (!locales.every(hasBuiltInLocaleData)) {
Expand Down
18 changes: 9 additions & 9 deletions karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,23 @@ if (process.env.CIRCLECI) {
type: 'lcov',
dir: process.env.CIRCLE_ARTIFACTS
};
reporters = ['coverage', 'coveralls'];
reporters = [ 'coverage', 'coveralls' ];
} else {
coverage = {
type: 'html',
dir: 'coverage/'
};
reporters = ['progress', 'coverage'];
reporters = [ 'progress', 'coverage' ];
}

export default function(config) {
export default function (config) {
config.set({
browsers: ['Firefox'],
reporters,
browsers: [ 'Firefox' ],
browserNoActivityTimeout: 30000,
frameworks: ['mocha', 'chai', 'sinon-chai'],
files: ['tests.webpack.js'],
preprocessors: { 'tests.webpack.js': ['webpack'] },
reporters: reporters,
frameworks: [ 'mocha', 'chai', 'sinon-chai' ],
files: [ 'tests.webpack.js' ],
preprocessors: { 'tests.webpack.js': [ 'webpack' ] },
coverageReporter: coverage,
webpack: {
...baseConfig,
Expand All @@ -35,7 +35,7 @@ export default function(config) {
...baseConfig.module.loaders,
{
test: /\.js$|.jsx$/,
loader: 'isparta?{babel: {stage: 0}}',
loader: 'isparta',
exclude: /node_modules|test|utils/
},
{
Expand Down
23 changes: 16 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,21 @@
"alt-utils": "^1.0.0",
"autoprefixer": "^6.1.0",
"axios": "^0.9.1",
"babel": "^5.8.3",
"babel-core": "^5.8.34",
"babel-loader": "^5.4.0",
"babel-runtime": "^5.8.34",
"babel": "^6.5.2",
"babel-cli": "^6.5.1",
"babel-core": "^6.5.2",
"babel-eslint": "^5.0.0",
"babel-loader": "^6.2.3",
"babel-plugin-add-module-exports": "^0.1.2",
"babel-plugin-react-transform": "^2.0.0",
"babel-plugin-transform-decorators-legacy": "^1.3.4",
"babel-plugin-transform-es2015-modules-commonjs": "^6.5.2",
"babel-polyfill": "^6.5.0",
"babel-preset-es2015": "^6.5.0",
"babel-preset-react": "^6.5.0",
"babel-preset-stage-0": "^6.5.0",
"babel-register": "^6.5.2",
"babel-runtime": "^6.5.0",
"classnames": "^2.1.3",
"connect-alt": "^1.0.0",
"cookies-js": "^1.2.1",
Expand Down Expand Up @@ -70,8 +81,6 @@
"webpack": "^1.12.6"
},
"devDependencies": {
"babel-eslint": "^4.0.5",
"babel-plugin-react-transform": "^1.0.3",
"blocked": "^1.1.0",
"browser-sync": "^2.8.0",
"dev-ip": "^1.0.1",
Expand All @@ -80,7 +89,7 @@
"eslint-loader": "^1.0.0",
"eslint-plugin-react": "^3.0.0",
"faux-jax": "^4.1.0",
"isparta-loader": "^1.0.0",
"isparta-loader": "^2.0.0",
"karma": "^0.13.3",
"karma-chai-plugins": "^0.6.0",
"karma-cli": "^0.1.0",
Expand Down
6 changes: 5 additions & 1 deletion server/api/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const simplifyUsers = (collection) => collection
.map(({ user, seed }) => ({ ...user, seed }))
.map(({ email, name, seed, picture }) => ({ email, name, seed, picture }));

export default function (router) {
function routes(router) {
router.get('/users', async function (ctx) {
ctx.body = simplifyUsers(users.slice(0, 10));
});
Expand All @@ -20,3 +20,7 @@ export default function (router) {
}
});
}

// can't export directly function, run into const issue
// see: https://phabricator.babeljs.io/T2892
export default routes;
26 changes: 26 additions & 0 deletions server/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const { NODE_ENV, PORT = 3000 } = process.env;

const config = {

default: {
port: parseInt(PORT, 10),
locales: [ 'fr', 'en' ]
},

development: {

},

staging: {

},

production: {
port: 3010
}

};

export default config[NODE_ENV] ?
{ ...config.default, ...config[NODE_ENV] } :
{ ...config.default, ...config.development };
3 changes: 0 additions & 3 deletions server/config/all.json

This file was deleted.

3 changes: 0 additions & 3 deletions server/config/development.js

This file was deleted.

13 changes: 0 additions & 13 deletions server/config/init.js

This file was deleted.

3 changes: 0 additions & 3 deletions server/config/production.js

This file was deleted.

5 changes: 3 additions & 2 deletions server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ process.env.NODE_PATH = 'app';
require('module').Module._initPaths();

// Install `babel` hook for ES6
require('babel/register');
require('babel-core/register');
require('babel-polyfill');

// Load Intl polyfill
require('utils/intl-polyfill')(require('./config/init').locales);
require('utils/intl-polyfill')(require('./config').locales);

// Start the server
require('./koa.js');
2 changes: 1 addition & 1 deletion server/koa.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import Router from 'koa-router';
import convert from 'koa-convert';

import router from './router';
import config from './config/init';
import config from './config';

const app = new Koa();
const env = process.env.NODE_ENV || 'development';
Expand Down
2 changes: 1 addition & 1 deletion server/router.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default async function (ctx) {

// Get request locale for rendering
const locale = ctx.cookies.get('_lang') ||
ctx.acceptsLanguages(require('./config/init').locales) ||
ctx.acceptsLanguages(require('./config').locales) ||
'en';

const { messages } = require(`data/${locale}`);
Expand Down
2 changes: 1 addition & 1 deletion shared/api-client.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import axios from 'axios';
import { port } from '../server/config/init';
import { port } from '../server/config';

const { BROWSER } = process.env;

Expand Down
2 changes: 1 addition & 1 deletion tests.webpack.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Browser ES6 Polyfill
require('babel/polyfill');
require('babel-polyfill');
const context = require.context('./test/spec', true, /\.test\.jsx$|\.test\.js$/);
context.keys().forEach(context);

0 comments on commit 9d0e784

Please sign in to comment.