Skip to content
New issue

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

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

Already on GitHub? # to your account

Update Gatsby to use Babel 6 #197

Merged
merged 10 commits into from
Mar 26, 2016
Merged
2 changes: 1 addition & 1 deletion .babelrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"stage": 0,
"presets": ['react', 'es2015', 'stage-0']
}
30 changes: 30 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Filing an issue

If you want your issue to be resolved quickly, please include in your
issue:

* Gatsby version, node.js version, OS version
* The contents of your `gatsby.config.js` and `package.json`.

# Contributing
You can install the latest `master` version of Gatsby by following these
simple steps:

* Clone the repo, navigate to its directory.
* Execute `npm install` to install packages.
* Execute `npm uninstall -g gatsby && npm link`
* Use `git pull` to update to latest Gatsby.

Test suite can be run via `npm test`.

The usual contributing steps are:

* Fork the [official repository](https://github.com/gatsbyjs/gatsby).
* Clone your fork: git clone `git@github.com:<your-username>/gatsby.git`
* Make sure tests are passing for you: npm install && npm test
* Create a topic branch: git checkout -b topics/new-feature-name
* Run `npm run watch` to watch code and compile your changes.
* Add tests and code for your changes.
* Once you‘re done, make sure all tests still pass: npm install && npm test
* Commit and push to your fork.
* Create an pull request from your branch.
18 changes: 4 additions & 14 deletions bin/build.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,9 @@
/*eslint-disable */
var program = require('commander')
var path = require('path')
var program = require('commander') // eslint-disable-line no-var
var path = require('path') // eslint-disable-line no-var

var packageJson = require('../package.json')
/*eslint-enable */

// Use compiled version of code when installed globally, otherwise use
// babelscript version.
var build // eslint-disable-line no-var
var packageJson = require('../package.json') // eslint-disable-line no-var
var build = require('../dist/utils/build') // eslint-disable-line no-var
var relativeDirectory // eslint-disable-line no-var
if (require('./published')) {
build = require('../dist/utils/build')
} else {
build = require('../lib/utils/build')
}

program
.version(packageJson.version)
Expand Down
27 changes: 10 additions & 17 deletions bin/develop.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,20 @@
/*eslint-disable */
var program = require('commander')
var path = require('path')
var program = require('commander') // eslint-disable-line no-var
var path = require('path') // eslint-disable-line no-var

var packageJson = require('../package.json')
var packageJson = require('../package.json') // eslint-disable-line no-var
var relativeDirectory // eslint-disable-line no-var
var develop = require('../dist/utils/develop') // eslint-disable-line no-var

// Use compiled version of code when installed globally, otherwise use
// babelscript version.
var develop
var relativeDirectory
if (require('./published')) {
develop = require('../dist/utils/develop')
} else {
develop = require('../lib/utils/develop')
}

var defaultHost = process.platform === 'win32'
var defaultHost = process.platform === 'win32' // eslint-disable-line no-var
? 'localhost'
: '0.0.0.0'

program
.version(packageJson.version)
.option('-h, --host <url>', 'Set host. Defaults to ' + defaultHost, defaultHost)
.option('-h, --host <url>',
'Set host. Defaults to ' + defaultHost, // eslint-disable-line prefer-template
defaultHost
)
.option('-p, --port <port>', 'Set port. Defaults to 8000', '8000')
.parse(process.argv)

Expand All @@ -34,4 +28,3 @@ program.directory = directory
program.relativeDirectory = relativeDirectory

develop(program)
/*eslint-enable */
2 changes: 1 addition & 1 deletion bin/gatsby-build.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env node

require('babel/register')
require('babel-core/register')
require('./build')
2 changes: 1 addition & 1 deletion bin/gatsby-develop.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env node

require('babel/register')
require('babel-core/register')
require('./develop')
2 changes: 1 addition & 1 deletion bin/gatsby-new.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env node

require('babel/register')
require('babel-core/register')
require('./new')
2 changes: 1 addition & 1 deletion bin/gatsby.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env node

require('babel/register')
require('babel-core/register')
require('./index')
18 changes: 4 additions & 14 deletions bin/new.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,10 @@
/*eslint-disable */
var program = require('commander')
var loggy = require('loggy')
var program = require('commander') // eslint-disable-line no-var
var loggy = require('loggy') // eslint-disable-line no-var

var packageJson = require('../package.json')
/*eslint-enable */

// Use compiled version of code when installed globally, otherwise use
// babelscript version.
var initStarter // eslint-disable-line no-var
var packageJson = require('../package.json') // eslint-disable-line no-var
var rootPath // eslint-disable-line no-var
var starter // eslint-disable-line no-var
if (require('./published')) {
initStarter = require('../dist/utils/init-starter')
} else {
initStarter = require('../lib/utils/init-starter')
}
var initStarter = require('../dist/utils/init-starter') // eslint-disable-line no-var

program
.version(packageJson.version)
Expand Down
23 changes: 0 additions & 23 deletions lib/utils/babel-exclude-test.js

This file was deleted.

22 changes: 7 additions & 15 deletions lib/utils/develop.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,16 @@ import Negotiator from 'negotiator'
import parsePath from 'parse-filepath'
import find from 'lodash/find'
import webpackRequire from 'webpack-require'
import fs from 'fs'
import toml from 'toml'
import WebpackPlugin from 'hapi-webpack-plugin'

import getUserGatsbyConfig from './get-user-gatsby-config'
import globPages from './glob-pages'
import webpackConfig from './webpack.config'
const debug = require('debug')('gatsby:application')
import babelExcludeTest from './babel-exclude-test'

module.exports = (program) => {
const directory = program.directory

// Read in site config.
let siteConfig
try {
siteConfig = toml.parse(fs.readFileSync(`${directory}/config.toml`))
} catch (e) {
console.log("Couldn't load your site config", e)
}

// Load pages for the site.
return globPages(directory, (err, pages) => {
const compilerConfig = webpackConfig(program, directory, 'develop', program.port)
Expand All @@ -44,15 +33,19 @@ module.exports = (program) => {
htmlCompilerConfig.removeLoader('js')
htmlCompilerConfig.loader('js', {
test: /\.jsx?$/, // Accept either .js or .jsx files.
exclude: babelExcludeTest,
exclude: /(node_modules|bower_components)/,
loader: 'babel',
query: {
presets: ['react', 'es2015', 'stage-1'],
plugins: ['add-module-exports'],
},
})

const htmlConfig = getUserGatsbyConfig(htmlCompilerConfig, 'develop')

webpackRequire(htmlConfig.resolve(), require.resolve(HTMLPath), (error, factory) => {
if (error) {
console.log(`Failed to require ${directory}/html.jsx`)
console.log(`Failed to require ${directory}/html.js`)
error.forEach((e) => {
console.log(e)
})
Expand All @@ -79,8 +72,7 @@ module.exports = (program) => {
try {
const htmlElement = React.createElement(
HTML, {
pages,
config: siteConfig,
body: '',
}
)
let html = ReactDOMServer.renderToStaticMarkup(htmlElement)
Expand Down
2 changes: 1 addition & 1 deletion lib/utils/static-entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ module.exports = (locals, callback) => {
}

const html = `<!DOCTYPE html>\n ${renderToStaticMarkup(
<HTML config={config} body={body} {...renderProps} />
<HTML body={body} {...renderProps} />
)}`
callback(null, html)
}
Expand Down
25 changes: 8 additions & 17 deletions lib/utils/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import StaticSiteGeneratorPlugin from 'static-site-generator-webpack-plugin'
import ExtractTextPlugin from 'extract-text-webpack-plugin'
import Config from 'webpack-configurator'
const debug = require('debug')('gatsby:webpack-config')
import babelExcludeTest from './babel-exclude-test'

module.exports = (program, directory, stage, webpackPort = 1500, routes = []) => {
debug(`Loading webpack config for stage "${stage}"`)
Expand Down Expand Up @@ -141,8 +140,11 @@ module.exports = (program, directory, stage, webpackPort = 1500, routes = []) =>
})
config.loader('js', {
test: /\.jsx?$/, // Accept either .js or .jsx files.
exclude: babelExcludeTest,
loaders: ['babel'],
exclude: /(node_modules|bower_components)/,
loader: 'babel',
query: {
plugins: ['add-module-exports'],
},
})
config.loader('coffee', {
test: /\.coffee$/,
Expand Down Expand Up @@ -245,22 +247,11 @@ module.exports = (program, directory, stage, webpackPort = 1500, routes = []) =>
config.removeLoader('js')
config.loader('js', {
test: /\.jsx?$/, // Accept either .js or .jsx files.
exclude: babelExcludeTest,
exclude: /(node_modules|bower_components)/,
loader: 'babel',
query: {
plugins: ['react-transform'],
extra: {
'react-transform': {
transforms: [{
transform: 'react-transform-hmr',
imports: ['react'],
locals: ['module'],
}, {
transform: 'react-transform-catch-errors',
imports: ['react', 'redbox-react'],
}],
},
},
presets: ['react-hmre', 'react', 'es2015', 'stage-1'],
plugins: ['add-module-exports'],
},
})
return config
Expand Down
29 changes: 16 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,17 @@
"gatsby": "./bin/gatsby.js"
},
"bugs": {
"url": "https://github.com/gatsby-group/gatsby/issues"
"url": "https://github.com/gatsbyjs/gatsby/issues"
},
"dependencies": {
"async": "^1.2.1",
"babel": "^5.8.35",
"babel-core": "^5.8.35",
"babel-loader": "^5.4.0",
"babel-plugin-react-transform": "^1.1.1",
"babel-core": "^6.7.2",
"babel-loader": "^6.2.4",
"babel-plugin-add-module-exports": "^0.1.2",
"babel-preset-es2015": "^6.6.0",
"babel-preset-react": "^6.5.0",
"babel-preset-react-hmre": "^1.1.1",
"babel-preset-stage-0": "^6.5.0",
"boom": "^2.7.2",
"cjsx-loader": "^2.0.1",
"coffee-loader": "^0.7.2",
Expand Down Expand Up @@ -59,9 +62,6 @@
"react-dom": "^0.14.7",
"react-hot-loader": "^1.3.0",
"react-router": "^2.0.0",
"react-transform-catch-errors": "^1.0.0",
"react-transform-hmr": "^1.0.0",
"redbox-react": "^1.0.1",
"sass-loader": "^3.1.2",
"scroll-behavior": "^0.3.2",
"slash": "^1.0.0",
Expand All @@ -78,12 +78,13 @@
"yaml-loader": "^0.1.0"
},
"devDependencies": {
"babel-eslint": "^5.0.0",
"babel-cli": "^6.6.5",
"babel-eslint": "^6.0.0",
"eslint": "^2.4.0",
"eslint-config-airbnb": "^6.1.0",
"eslint-plugin-react": "^4.2.1"
},
"homepage": "https://github.com/gatsby-group/gatsby#readme",
"homepage": "https://github.com/gatsbyjs/gatsby#readme",
"keywords": [
"blog",
"generator",
Expand All @@ -97,10 +98,12 @@
"main": "index.js",
"repository": {
"type": "git",
"url": "git+https://github.com/gatsby-group/gatsby.git"
"url": "git+https://github.com/gatsbyjs/gatsby.git"
},
"scripts": {
"lint": "./node_modules/.bin/eslint --ext .js,.jsx --ignore-pattern dist .",
"test": "npm run lint"
"lint": "eslint --ext .js,.jsx --ignore-pattern dist .",
"test": "npm run lint",
"watch": "babel -w lib --out-dir dist/",
"build": "babel lib --out-dir dist/"
}
}
2 changes: 0 additions & 2 deletions scripts/build.sh

This file was deleted.

8 changes: 1 addition & 7 deletions scripts/prepublish.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,2 @@
npm test
./scripts/build.sh

# Write out script so cli knows it's now published and should use the
# compiled code not Babel src code.
cat <<EOF >bin/published.js
module.exports = true
EOF
npm run build