diff --git a/.babelrc b/.babelrc index dfb31e1cffff1..ed1dfd7029d02 100644 --- a/.babelrc +++ b/.babelrc @@ -1,3 +1,3 @@ { - "stage": 0, + "presets": ['react', 'es2015', 'stage-0'] } diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000000000..168d650d9e678 --- /dev/null +++ b/CONTRIBUTING.md @@ -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:/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. diff --git a/bin/build.js b/bin/build.js index 936748680beaf..e19ce4aa233e2 100644 --- a/bin/build.js +++ b/bin/build.js @@ -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) diff --git a/bin/develop.js b/bin/develop.js index dd8281756453d..91feb3ad6f247 100644 --- a/bin/develop.js +++ b/bin/develop.js @@ -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 ', 'Set host. Defaults to ' + defaultHost, defaultHost) + .option('-h, --host ', + 'Set host. Defaults to ' + defaultHost, // eslint-disable-line prefer-template + defaultHost + ) .option('-p, --port ', 'Set port. Defaults to 8000', '8000') .parse(process.argv) @@ -34,4 +28,3 @@ program.directory = directory program.relativeDirectory = relativeDirectory develop(program) -/*eslint-enable */ diff --git a/bin/gatsby-build.js b/bin/gatsby-build.js index 241bb8facc6fe..067e8e8cfb027 100755 --- a/bin/gatsby-build.js +++ b/bin/gatsby-build.js @@ -1,4 +1,4 @@ #!/usr/bin/env node -require('babel/register') +require('babel-core/register') require('./build') diff --git a/bin/gatsby-develop.js b/bin/gatsby-develop.js index 9bd972c8b9b60..3744fd1d3bbe7 100755 --- a/bin/gatsby-develop.js +++ b/bin/gatsby-develop.js @@ -1,4 +1,4 @@ #!/usr/bin/env node -require('babel/register') +require('babel-core/register') require('./develop') diff --git a/bin/gatsby-new.js b/bin/gatsby-new.js index 29a7347f84f82..e8ad672a26c84 100755 --- a/bin/gatsby-new.js +++ b/bin/gatsby-new.js @@ -1,4 +1,4 @@ #!/usr/bin/env node -require('babel/register') +require('babel-core/register') require('./new') diff --git a/bin/gatsby.js b/bin/gatsby.js index a0b9b514c11ac..4304dfe5ac55e 100755 --- a/bin/gatsby.js +++ b/bin/gatsby.js @@ -1,4 +1,4 @@ #!/usr/bin/env node -require('babel/register') +require('babel-core/register') require('./index') diff --git a/bin/new.js b/bin/new.js index b01c1151875f7..322d3001cefde 100644 --- a/bin/new.js +++ b/bin/new.js @@ -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) diff --git a/lib/utils/babel-exclude-test.js b/lib/utils/babel-exclude-test.js deleted file mode 100644 index 6448f91a8d61e..0000000000000 --- a/lib/utils/babel-exclude-test.js +++ /dev/null @@ -1,23 +0,0 @@ -import published from '../../bin/published' - -const libDirs = /(node_modules|bower_components)/i -let gatsbyLib = /(gatsby.lib)/i -// If installed globally, look for "dist" directory instead. -if (published) { - gatsbyLib = /(gatsby.dist)/i -} - -export default (absPath) => { - let result = false - if (absPath.match(gatsbyLib)) { - // There is a match, don't exclude this file. - result = false - } else if (absPath.match(libDirs)) { - // There is a match, do exclude this file. - result = true - } else { - result = false - } - - return result -} diff --git a/lib/utils/develop.js b/lib/utils/develop.js index a6c71537b3e35..4e89f9fe04f1b 100644 --- a/lib/utils/develop.js +++ b/lib/utils/develop.js @@ -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) @@ -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) }) @@ -79,8 +72,7 @@ module.exports = (program) => { try { const htmlElement = React.createElement( HTML, { - pages, - config: siteConfig, + body: '', } ) let html = ReactDOMServer.renderToStaticMarkup(htmlElement) diff --git a/lib/utils/static-entry.js b/lib/utils/static-entry.js index 09c9f6fd051ad..7d188e10fd7c7 100644 --- a/lib/utils/static-entry.js +++ b/lib/utils/static-entry.js @@ -29,7 +29,7 @@ module.exports = (locals, callback) => { } const html = `\n ${renderToStaticMarkup( - + )}` callback(null, html) } diff --git a/lib/utils/webpack.config.js b/lib/utils/webpack.config.js index 74d327afaca58..661e57f748ba9 100644 --- a/lib/utils/webpack.config.js +++ b/lib/utils/webpack.config.js @@ -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}"`) @@ -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$/, @@ -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 diff --git a/package.json b/package.json index 39acad04262c8..ccd3fc5ba019d 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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", @@ -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", @@ -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/" } } diff --git a/scripts/build.sh b/scripts/build.sh deleted file mode 100755 index a0d486f275d9b..0000000000000 --- a/scripts/build.sh +++ /dev/null @@ -1,2 +0,0 @@ -node_modules/.bin/babel lib/ --out-dir dist -node_modules/.bin/coffee -co dist/ lib/ diff --git a/scripts/prepublish.sh b/scripts/prepublish.sh index 51281b74194ab..c23db29bf2411 100755 --- a/scripts/prepublish.sh +++ b/scripts/prepublish.sh @@ -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 <bin/published.js -module.exports = true -EOF +npm run build