From 7ef2d8cfb59e815d85aa7c79ddabe4f3e12daa3c Mon Sep 17 00:00:00 2001 From: Araphel Date: Sun, 27 Dec 2015 12:12:25 -0700 Subject: [PATCH 1/2] Major Patch: -CoffeeScript has been replaced with ES6 -Babel 5 has been upgraded to 6 along with structural changes necessary -All Dependencies but hapi have been updated to most recent versions -lint has been modified to utilize babel -unnecessary modules have been removed -linting + deployment operational --- .babelrc | 2 +- .eslintrc | 28 ++- .gitignore | 7 +- .jshintrc | 6 + bin/build.coffee | 29 --- bin/build.es6 | 31 +++ bin/cli.js | 3 +- bin/develop.coffee | 26 --- bin/develop.es6 | 26 +++ bin/gatsby-build.js | 5 +- bin/gatsby-develop.js | 5 +- bin/gatsby-new.js | 5 +- bin/index.coffee | 11 - bin/index.es6 | 11 + bin/new.coffee | 29 --- bin/new.es6 | 33 +++ lib/isomorphic/HTML.jsx | 14 +- lib/isomorphic/create-routes.coffee | 107 ---------- lib/isomorphic/create-routes.es6 | 118 +++++++++++ .../{gatsby-helpers.js => gatsby-helpers.es6} | 29 ++- lib/isomorphic/wrappers/html.jsx | 12 +- lib/isomorphic/wrappers/md.jsx | 14 +- lib/loaders/config-loader/index.coffee | 25 --- lib/loaders/config-loader/index.es6 | 27 +++ lib/loaders/config-loader/index.js | 23 --- .../markdown-loader/{index.js => index.es6} | 30 +-- lib/utils/build-production.coffee | 14 -- lib/utils/build-production.es6 | 14 ++ lib/utils/{build.js => build.es6} | 32 +-- lib/utils/{develop.js => develop.es6} | 110 +++++----- ...y-config.js => get-user-gatsby-config.es6} | 10 +- lib/utils/glob-pages.coffee | 78 -------- lib/utils/glob-pages.es6 | 94 +++++++++ .../{init-starter.js => init-starter.es6} | 84 ++++---- lib/utils/{post-build.js => post-build.es6} | 47 ++--- lib/utils/static-entry.jsx | 38 ++-- lib/utils/static-generation.coffee | 24 --- lib/utils/static-generation.es6 | 29 +++ lib/utils/web-entry.jsx | 38 ++-- .../{webpack.config.js => webpack.config.es6} | 188 ++++++++---------- package.json | 86 ++++---- scripts/build.sh | 3 +- 42 files changed, 777 insertions(+), 768 deletions(-) create mode 100644 .jshintrc delete mode 100644 bin/build.coffee create mode 100644 bin/build.es6 delete mode 100644 bin/develop.coffee create mode 100644 bin/develop.es6 delete mode 100644 bin/index.coffee create mode 100644 bin/index.es6 delete mode 100644 bin/new.coffee create mode 100644 bin/new.es6 delete mode 100644 lib/isomorphic/create-routes.coffee create mode 100644 lib/isomorphic/create-routes.es6 rename lib/isomorphic/{gatsby-helpers.js => gatsby-helpers.es6} (66%) delete mode 100644 lib/loaders/config-loader/index.coffee create mode 100644 lib/loaders/config-loader/index.es6 delete mode 100644 lib/loaders/config-loader/index.js rename lib/loaders/markdown-loader/{index.js => index.es6} (63%) delete mode 100644 lib/utils/build-production.coffee create mode 100644 lib/utils/build-production.es6 rename lib/utils/{build.js => build.es6} (55%) rename lib/utils/{develop.js => develop.es6} (64%) rename lib/utils/{get-user-gatsby-config.js => get-user-gatsby-config.es6} (60%) delete mode 100644 lib/utils/glob-pages.coffee create mode 100644 lib/utils/glob-pages.es6 rename lib/utils/{init-starter.js => init-starter.es6} (70%) rename lib/utils/{post-build.js => post-build.es6} (63%) delete mode 100644 lib/utils/static-generation.coffee create mode 100644 lib/utils/static-generation.es6 rename lib/utils/{webpack.config.js => webpack.config.es6} (63%) diff --git a/.babelrc b/.babelrc index b0b9a96ef0ecd..9b7d435ad38f2 100644 --- a/.babelrc +++ b/.babelrc @@ -1,3 +1,3 @@ { - "stage": 0 + "presets": ["es2015", "stage-0", "react"] } diff --git a/.eslintrc b/.eslintrc index e796f38cf78a0..329eec0b29775 100644 --- a/.eslintrc +++ b/.eslintrc @@ -1,15 +1,21 @@ { - "extends": "eslint-config-airbnb", - "rules": { - "indent": [2, 2, {"SwitchCase": 1}], - "no-console": [0], - "func-names": [0], - "semi": [2, "never"], - "no-extra-semi": [2], - "space-before-function-paren": [2, "always"], - "no-else-return": [0], + "ecmaFeatures": { + "jsx": true, + "modules": true + }, + "env": { + "browser": true, + "node": true }, - "globals": { - "__PREFIX_LINKS__": true, + "parser": "babel-eslint", + "rules": { + "quotes": [2, "single"], + "strict": [2, "never"], + "react/jsx-uses-react": 2, + "react/jsx-uses-vars": 2, + "react/react-in-jsx-scope": 2 }, + "plugins": [ + "react" + ] } diff --git a/.gitignore b/.gitignore index c4703bbeb9ed4..9bf2373d66458 100644 --- a/.gitignore +++ b/.gitignore @@ -24,9 +24,12 @@ build/Release # Dependency directory # https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git -node_modules +node_modules/ examples/biz-website/public/ examples/blog/public/ *.un~ -dist +dist/ bin/published.js + +# JetBrains IntelliJ IDEA-based project configuration directory +.idea/ \ No newline at end of file diff --git a/.jshintrc b/.jshintrc new file mode 100644 index 0000000000000..b6b57efddad0f --- /dev/null +++ b/.jshintrc @@ -0,0 +1,6 @@ +{ + "node": true, + "browser": true, + "esnext": true, + "newcap": false +} \ No newline at end of file diff --git a/bin/build.coffee b/bin/build.coffee deleted file mode 100644 index 8da20bef47c15..0000000000000 --- a/bin/build.coffee +++ /dev/null @@ -1,29 +0,0 @@ -program = require 'commander' -path = require 'path' - -packageJson = require '../package.json' - -# Use compiled version of code when installed globally, otherwise use -# babelscript version. -if require './published' - build = require '../dist/utils/build' -else - build = require '../lib/utils/build' - -program - .version(packageJson.version) - .option('--prefix-links', 'Build site with links prefixed (set prefix in your config).') - .parse(process.argv) - -relativeDirectory = program.args[0] -unless relativeDirectory? then relativeDirectory = "." -directory = path.resolve(relativeDirectory) - -program.directory = directory -program.relativeDirectory = relativeDirectory - -build program, (err) -> - if err? - throw err - else - console.log('Done') diff --git a/bin/build.es6 b/bin/build.es6 new file mode 100644 index 0000000000000..44dfe7cab7f7e --- /dev/null +++ b/bin/build.es6 @@ -0,0 +1,31 @@ +import program from 'commander'; +import path from 'path'; + +let packageJson = require('../package.json'); + +// Use compiled version of code when installed globally, otherwise use babel script version. +if ('./published') { + let build = require('../dist/utils/build'); +} else { + let build = require('../lib/utils/build'); +} + +program + .version(packageJson.version) + .option('--prefix-links', 'Build site with links prefixed (set prefix in your config).') + .parse(process.argv); + +let relativeDirectory = program.args[0]; +if (!(typeof relativeDirectory !== "undefined" && relativeDirectory !== null)) { relativeDirectory = "."; } +let directory = path.resolve(relativeDirectory); + +program.directory = directory; +program.relativeDirectory = relativeDirectory; + +build(program, function(err) { + if ((typeof err !== "undefined" && err !== null)) { + throw err; + } else { + return console.log('Done'); + } +}); diff --git a/bin/cli.js b/bin/cli.js index 9645aa5cbe01e..1bed8571c45e0 100755 --- a/bin/cli.js +++ b/bin/cli.js @@ -1,4 +1,3 @@ #!/usr/bin/env node -require('coffee-script/register') -require('./index') +require('./index.es6'); diff --git a/bin/develop.coffee b/bin/develop.coffee deleted file mode 100644 index 5f73160b2eab6..0000000000000 --- a/bin/develop.coffee +++ /dev/null @@ -1,26 +0,0 @@ -program = require 'commander' -path = require 'path' - -packageJson = require '../package.json' - -# Use compiled version of code when installed globally, otherwise use -# babelscript version. -if require './published' - develop = require '../dist/utils/develop' -else - develop = require '../lib/utils/develop' - -program - .version(packageJson.version) - .option('-h, --host ', 'Set host. Defaults to 0.0.0.0', "0.0.0.0") - .option('-p, --port ', 'Set port. Defaults to 8000', "8000") - .parse(process.argv) - -relativeDirectory = program.args[0] -unless relativeDirectory? then relativeDirectory = "." -directory = path.resolve(relativeDirectory) - -program.directory = directory -program.relativeDirectory = relativeDirectory - -develop(program) diff --git a/bin/develop.es6 b/bin/develop.es6 new file mode 100644 index 0000000000000..9b482e01a48ad --- /dev/null +++ b/bin/develop.es6 @@ -0,0 +1,26 @@ +import program from 'commander'; +import path from 'path'; + +import packageJson from '../package.json'; + +// Use compiled version of code when installed globally, otherwise use babel script version. +if ('./published') { + var develop = require('../dist/utils/develop'); +} else { + var develop = require('../lib/utils/develop'); +} + +program + .version(packageJson.version) + .option('-h, --host ', 'Set host. Defaults to 0.0.0.0', "0.0.0.0") + .option('-p, --port ', 'Set port. Defaults to 8000', "8000") + .parse(process.argv); + +var relativeDirectory = program.args[0]; +if (!(typeof relativeDirectory !== "undefined" && relativeDirectory !== null)) { relativeDirectory = "."; } +var directory = path.resolve(relativeDirectory); + +program.directory = directory; +program.relativeDirectory = relativeDirectory; + +develop(program); diff --git a/bin/gatsby-build.js b/bin/gatsby-build.js index b02baf0f62397..f4fdc9cff7de2 100755 --- a/bin/gatsby-build.js +++ b/bin/gatsby-build.js @@ -1,5 +1,4 @@ #!/usr/bin/env node -require('babel/register') -require('coffee-script/register') -require('./build') +require('babel-register'); +require('./build'); diff --git a/bin/gatsby-develop.js b/bin/gatsby-develop.js index d5c0fb1083635..58cf8996f2bb5 100755 --- a/bin/gatsby-develop.js +++ b/bin/gatsby-develop.js @@ -1,5 +1,4 @@ #!/usr/bin/env node -require('babel/register') -require('coffee-script/register') -require('./develop') +require('babel-register'); +require('./develop'); diff --git a/bin/gatsby-new.js b/bin/gatsby-new.js index ce8a5a72395d9..5f9dc5f0a0bf9 100755 --- a/bin/gatsby-new.js +++ b/bin/gatsby-new.js @@ -1,5 +1,4 @@ #!/usr/bin/env node -require('coffee-script/register') -require('babel/register') -require('./new') +require('babel-register'); +require('./new'); diff --git a/bin/index.coffee b/bin/index.coffee deleted file mode 100644 index f093722c4080b..0000000000000 --- a/bin/index.coffee +++ /dev/null @@ -1,11 +0,0 @@ -program = require 'commander' -path = require 'path' - -packageJson = require '../package.json' - -program - .version(packageJson.version) - .command('develop [directory]', 'Start hot-reloading development server') - .command('build [directory]', 'Do a production build of site') - .command('new [rootPath] [starter]', 'Create new Gatsby project in path [.].') - .parse(process.argv) diff --git a/bin/index.es6 b/bin/index.es6 new file mode 100644 index 0000000000000..1585ef8be0b07 --- /dev/null +++ b/bin/index.es6 @@ -0,0 +1,11 @@ +var program = require('commander'); +var path = require('path'); + +var packageJson = require('../package.json'); + +program + .version(packageJson.version) + .command('develop [directory]', 'Start hot-reloading development server') + .command('build [directory]', 'Do a production build of site') + .command('new [rootPath] [starter]', 'Create new Gatsby project in path [.].') + .parse(process.argv); diff --git a/bin/new.coffee b/bin/new.coffee deleted file mode 100644 index 3457a462293b3..0000000000000 --- a/bin/new.coffee +++ /dev/null @@ -1,29 +0,0 @@ -program = require 'commander' -loggy = require 'loggy' - -packageJson = require '../package.json' - -# Use compiled version of code when installed globally, otherwise use -# babelscript version. -if require './published' - initStarter = require '../dist/utils/init-starter' -else - initStarter = require '../lib/utils/init-starter' - -program - .version(packageJson.version) - .parse(process.argv) - -if program.args.length is 1 - rootPath = program.args[0] - starter = "gh:gatsbyjs/gatsby-starter-default" -else - rootPath = program.args[0] - starter = program.args[1] - -initStarter starter, { - rootPath: rootPath - logger: loggy -}, (error) -> - if error - loggy.error error diff --git a/bin/new.es6 b/bin/new.es6 new file mode 100644 index 0000000000000..10589fb0c89eb --- /dev/null +++ b/bin/new.es6 @@ -0,0 +1,33 @@ +var program = require('commander'); +var loggy = require('loggy'); + +var packageJson = require('../package.json'); + +// Use compiled version of code when installed globally, otherwise use babelscript version. +if (require('./published')) { +var initStarter = require('../dist/utils/init-starter'); +} else { + initStarter = require('../lib/utils/init-starter'); +} + +program + .version(packageJson.version) + .parse(process.argv); + +if (program.args.length === 1) { + var rootPath = program.args[0]; + var starter = "gh:gatsbyjs/gatsby-starter-default"; +} else { + rootPath = program.args[0]; + starter = program.args[1]; +} + +initStarter( starter, { + rootPath: rootPath, + logger: loggy + }, function(error) { + if (error) { + return loggy.error(error); + } + } +); diff --git a/lib/isomorphic/HTML.jsx b/lib/isomorphic/HTML.jsx index 5be685137a105..bc021dc9e187f 100644 --- a/lib/isomorphic/HTML.jsx +++ b/lib/isomorphic/HTML.jsx @@ -1,19 +1,19 @@ -import React, {PropTypes} from 'react' -import Typography from 'typography' +import React, {PropTypes} from 'react'; +import Typography from 'typography'; -const TypographyStyle = new Typography().TypographyStyle +const TypographyStyle = new Typography().TypographyStyle; module.exports = React.createClass({ propTypes: { title: PropTypes.string, body: PropTypes.string, - favicon: PropTypes.string, + favicon: PropTypes.string }, getDefaultProps: function () { return { title: 'Default title', - body: '', + body: '' } }, @@ -37,5 +37,5 @@ module.exports = React.createClass({ ) - }, -}) + } +}); diff --git a/lib/isomorphic/create-routes.coffee b/lib/isomorphic/create-routes.coffee deleted file mode 100644 index d6d22713ba0bb..0000000000000 --- a/lib/isomorphic/create-routes.coffee +++ /dev/null @@ -1,107 +0,0 @@ -Router = require 'react-router' -filter = require 'lodash/collection/filter' -sortBy = require 'lodash/collection/sortBy' -last = require 'lodash/array/last' -includes = require 'underscore.string/include' -{ config } = require 'config' -{ link } = require './gatsby-helpers' - -module.exports = (pages, pagesReq) -> - templates = {} - templates.root = Router.createRoute({ - name: 'root-template' - path: link("/") - handler: pagesReq './_template' - }) - - # Arrange pages in data structure according to their position - # on the file system. Then use this to create routes. - # - # Algorithm - # 1. Find all templates. - # 2. Create routes for each template russian-doll style. - # 3. For each index file paired with a template, create a default route - # 4. Create normal routes for each remaining file under the appropriate - # template - templateFiles = filter pages, (page) -> - page.file.name is "_template" and - page.file.dirname isnt "." - - for templateFile in templateFiles - # Find the parent template of this template. - parentTemplates = filter(templateFiles, (template) -> - includes(templateFile.requirePath, template.file.dirname) - ) - parentTemplates = sortBy(parentTemplates, (template) -> - template?.file.dirname.length) - parentTemplateFile = last(parentTemplates) - parentRoute = templates[parentTemplateFile?.file.dirname] - - unless parentRoute - parentRoute = templates.root - - templates[templateFile.file.dirname] = Router.createRoute({ - name: templateFile.file.dirname + "-template" - path: link(templateFile.templatePath) - parentRoute: parentRoute - handler: pagesReq "./" + templateFile.requirePath - }) - - # Remove files that start with an underscore as this indicates - # the file shouldn't be turned into a page. - filteredPages = filter pages, (page) -> page.file.name.slice(0,1) isnt '_' - - markdownWrapper = require 'wrappers/md' - htmlWrapper = require 'wrappers/html' - - for page in filteredPages - # TODO add ways to load data for other file types. - # Should be able to install a gatsby-toml plugin to add support - # for TOML. Perhaps everything other than JSX and Markdown should be plugins. - # Or even they are plugins but they have built-in "blessed" plugins. - switch page.file.ext - when "md" - handler = markdownWrapper - page.data = pagesReq "./" + page.requirePath - when "html" - handler = htmlWrapper - when "jsx" - handler = pagesReq "./" + page.requirePath - page.data = if pagesReq("./" + page.requirePath).metadata - pagesReq("./" + page.requirePath).metadata() - when "cjsx" - handler = pagesReq "./" + page.requirePath - page.data = if pagesReq("./" + page.requirePath).metadata - pagesReq("./" + page.requirePath).metadata() - else - handler = pagesReq "./" + page.requirePath - - # Determine parent template for page. - parentRoutes = filter(templateFiles, (templateFile) -> - includes(page.requirePath, templateFile.file.dirname) - ) - parentRoutes = sortBy(parentRoutes, (route) -> route?.file.dirname.length) - parentTemplateFile = last(parentRoutes) - parentRoute = templates[parentTemplateFile?.file.dirname] - - unless parentRoute - parentRoute = templates.root - - # If page is an index page *and* in the same directory as a template, - # it is the default route (for that template). - if includes(page.path, "/index") and - parentRoute.file.dirname is parentTemplateFile.file.dirname - Router.createDefaultRoute({ - name: page.path - parentRoute: parentRoute - handler: handler - }) - else - Router.createRoute({ - name: page.path - path: link(page.path) - parentRoute: parentRoute - handler: handler - }) - - return templates.root diff --git a/lib/isomorphic/create-routes.es6 b/lib/isomorphic/create-routes.es6 new file mode 100644 index 0000000000000..7973f79889ab8 --- /dev/null +++ b/lib/isomorphic/create-routes.es6 @@ -0,0 +1,118 @@ +var Router = require('react-router'); +var filter = require('lodash/collection/filter'); +var sortBy = require('lodash/collection/sortBy'); +var last = require('lodash/array/last'); +var includes = require('underscore.string/include'); +var { config } = require('config'); +var { link } = require('./gatsby-helpers'); + +module.exports = function (pages, pagesReq) { + var templates = {}; + templates.root = Router.createRoute({ + name: 'root-template', + path: link("/"), + handler: pagesReq('./_template') + }); + + // Arrange pages in data structure according to their position + // on the file system. Then use this to create routes. + // + // Algorithm + // 1. Find all templates. + // 2. Create routes for each template russian-doll style. + // 3. For each index file paired with a template, create a default route + // 4. Create normal routes for each remaining file under the appropriate template + var templateFiles = filter(pages, function (page) { + return page.file.name === "_template" && page.file.dirname !== "."; + }); + + for (var i = 0, templateFile; i < templateFiles.length; i++) { + //Find the parent template of this template. + templateFile = templateFiles[i]; + var parentTemplates = filter(templateFiles, function (template) { + return includes(templateFile.requirePath, template.file.dirname); + } + ); + parentTemplates = sortBy(parentTemplates, function (template) { + return ((typeof template !== "undefined" && template !== null) ? template.file : undefined).dirname.length; + }); + var parentTemplateFile = last(parentTemplates); + var parentRoute = templates[((typeof parentTemplateFile !== "undefined" && parentTemplateFile !== null) ? parentTemplateFile.file : undefined).dirname]; + + if (!parentRoute) { + parentRoute = templates.root; + } + + templates[templateFile.file.dirname] = Router.createRoute({ + name: templateFile.file.dirname + "-template", + path: link(templateFile.templatePath), + parentRoute: parentRoute, + handler: pagesReq("./" + templateFile.requirePath) + }); + } + // Remove files that start with an underscore as this indicates the file shouldn't be turned into a page. + var filteredPages = filter(pages, function (page) { + return page.file.name.slice(0, 1) !== '_'; + }); + + var markdownWrapper = require('wrappers/md'); + var htmlWrapper = require('wrappers/html'); + + for (var j = 0, page; j < filteredPages.length; j++) { + // TODO add ways to load data for other file types. + // Should be able to install a gatsby-toml plugin to add support for TOML. + // Perhaps everything other than JSX and Markdown should be plugins. + // Or even they are plugins but they have built-in "blessed" plugins. + page = filteredPages[j]; + switch (page.file.ext) { + case "md": + var handler = markdownWrapper; + page.data = pagesReq("./" + page.requirePath); + break; + case "html": + handler = htmlWrapper; + break; + case "jsx": + handler = pagesReq("./" + page.requirePath); + page.data = (() => { + if (pagesReq("./" + page.requirePath).metadata) { + return pagesReq("./" + page.requirePath).metadata(); + } + })(); + break; + default: + handler = pagesReq("./" + page.requirePath); + } + // Determine parent template for page. + var parentRoutes = filter(templateFiles, function (templateFile) { + return includes(page.requirePath, templateFile.file.dirname); + } + ); + parentRoutes = sortBy(parentRoutes, function (route) { + return ((typeof route !== "undefined" && route !== null) ? route.file : undefined).dirname.length; + }); + parentTemplateFile = last(parentRoutes); + parentRoute = templates[((typeof parentTemplateFile !== "undefined" && parentTemplateFile !== null) ? parentTemplateFile.file : undefined).dirname]; + + if (!parentRoute) { + parentRoute = templates.root; + } + // If page is an index page *and* in the same directory as a template, it is the default route (for that template). + if (includes(page.path, "/index") && parentRoute.file.dirname === parentTemplateFile.file.dirname) { + Router.createDefaultRoute({ + name: page.path, + parentRoute: parentRoute, + handler: handler + }); + } else { + Router.createRoute({ + name: page.path, + path: link(page.path), + parentRoute: parentRoute, + handler: handler + }); + } + } + + return templates.root; +}; diff --git a/lib/isomorphic/gatsby-helpers.js b/lib/isomorphic/gatsby-helpers.es6 similarity index 66% rename from lib/isomorphic/gatsby-helpers.js rename to lib/isomorphic/gatsby-helpers.es6 index f89a7b19519e5..47e988b105aa7 100644 --- a/lib/isomorphic/gatsby-helpers.js +++ b/lib/isomorphic/gatsby-helpers.es6 @@ -1,7 +1,7 @@ -import { pages, config } from 'config' -import filter from 'lodash/collection/filter' -import first from 'lodash/array/first' -import includes from 'underscore.string/include' +import { pages, config } from 'config'; +import filter from 'lodash/collection/filter'; +import first from 'lodash/array/first'; +import includes from 'underscore.string/include'; // Prefix links for Github Pages. // TODO make this generic for all prefixing? @@ -11,17 +11,16 @@ const link = exports.link = function (_link) { } else { return _link } -} +}; // Get the child pages for a given template. exports.templateChildrenPages = function (filename, state) { - // Pop off the file name to leave the relative directory - // path to this template. - const split = filename.split('/') - split.pop() - let result = '/' + split.join('/') + // Pop off the file name to leave the relative directory path to this template. + const split = filename.split('/'); + split.pop(); + let result = '/' + split.join('/'); - result = link(result) + result = link(result); const childrenRoutes = first( filter( @@ -29,13 +28,13 @@ exports.templateChildrenPages = function (filename, state) { return includes(route.path, result) } ) - ).childRoutes + ).childRoutes; const childrenPaths = childrenRoutes.map(function (path) { return path.path - }) + }); - let childPages + let childPages; if (childrenPaths) { childPages = filter(pages, function (page) { return childrenPaths.indexOf(link(page.path)) >= 0 @@ -45,4 +44,4 @@ exports.templateChildrenPages = function (filename, state) { } return childPages -} +}; diff --git a/lib/isomorphic/wrappers/html.jsx b/lib/isomorphic/wrappers/html.jsx index e368359ac61ef..dc920507ac1c3 100644 --- a/lib/isomorphic/wrappers/html.jsx +++ b/lib/isomorphic/wrappers/html.jsx @@ -1,16 +1,16 @@ -import React, {PropTypes} from 'react' +import React, {PropTypes} from 'react'; module.exports = React.createClass({ propTypes: { page: PropTypes.shape({ - data: PropTypes.string, - }), + data: PropTypes.string + }) }, render: function () { - const html = this.props.page.data + const html = this.props.page.data; return (
) - }, -}) + } +}); diff --git a/lib/isomorphic/wrappers/md.jsx b/lib/isomorphic/wrappers/md.jsx index beecd53f73578..2356061047f39 100644 --- a/lib/isomorphic/wrappers/md.jsx +++ b/lib/isomorphic/wrappers/md.jsx @@ -1,21 +1,21 @@ -import React, {PropTypes} from 'react' +import React, {PropTypes} from 'react'; module.exports = React.createClass({ propTypes: { page: PropTypes.shape({ data: PropTypes.shape({ - body: PropTypes.string.isRequired, - }), - }), + body: PropTypes.string.isRequired + }) + }) }, render: function () { - const post = this.props.page.data + const post = this.props.page.data; return (

{post.title}

) - }, -}) + } +}); diff --git a/lib/loaders/config-loader/index.coffee b/lib/loaders/config-loader/index.coffee deleted file mode 100644 index 3b5207b84bf6e..0000000000000 --- a/lib/loaders/config-loader/index.coffee +++ /dev/null @@ -1,25 +0,0 @@ -toml = require('toml') -loaderUtils = require('loader-utils') -Router = require 'react-router' -path = require 'path' - -globPages = require '../../utils/glob-pages' - -module.exports = (source) -> - @cacheable() - callback = @async() - - value = {} - - directory = loaderUtils.parseQuery(@query).directory - - # TODO support YAML + JSON + CSON as well here. - config = toml.parse(source) - value.config = config - value.relativePath = path.relative('.', directory) - - # Load pages. - globPages directory, (err, pagesData) => - value.pages = pagesData - @value = [value] - callback null, 'module.exports = ' + JSON.stringify(value, undefined, "\t") diff --git a/lib/loaders/config-loader/index.es6 b/lib/loaders/config-loader/index.es6 new file mode 100644 index 0000000000000..251c2342d15fb --- /dev/null +++ b/lib/loaders/config-loader/index.es6 @@ -0,0 +1,27 @@ +import toml from 'toml'; +import loaderUtils from 'loader-utils'; +import Router from 'react-router'; +import path from 'path'; + +var globPages = require('../../utils/glob-pages'); + +module.exports = function(source) { + this.cacheable(); + var callback = this.async(); + + var value = {}; + + var directory = loaderUtils.parseQuery(this.query).directory; + + // TODO support YAML + JSON + CSON as well here. + var config = toml.parse(source); + value.config = config; + value.relativePath = path.relative('.', directory); + + // Load pages. + return globPages(directory, (err, pagesData) => { + value.pages = pagesData; + this.value = [value]; + return callback(null, 'module.exports = ' + JSON.stringify(value, undefined, "\t")); + }); +}; diff --git a/lib/loaders/config-loader/index.js b/lib/loaders/config-loader/index.js deleted file mode 100644 index cf06d29fcb433..0000000000000 --- a/lib/loaders/config-loader/index.js +++ /dev/null @@ -1,23 +0,0 @@ -const toml = require('toml') -const loaderUtils = require('loader-utils') -const path = require('path') -const globPages = require('../../utils/glob-pages') - -module.exports = function (source) { - this.cacheable() - const callback = this.async() - const directory = loaderUtils.parseQuery(this.query).directory - const config = toml.parse(source) - - let value - value = {} - value.config = config - value.relativePath = path.relative('.', directory) - return globPages(directory, (function (_this) { - return function (err, pagesData) { - value.pages = pagesData - _this.value = [value] - return callback(null, 'module.exports = ' + JSON.stringify(value, void 0, '\t')) - } - })(this)) -} diff --git a/lib/loaders/markdown-loader/index.js b/lib/loaders/markdown-loader/index.es6 similarity index 63% rename from lib/loaders/markdown-loader/index.js rename to lib/loaders/markdown-loader/index.es6 index 233aa8a990f92..1478d571a3f39 100644 --- a/lib/loaders/markdown-loader/index.js +++ b/lib/loaders/markdown-loader/index.es6 @@ -1,7 +1,7 @@ -import frontMatter from 'front-matter' -import markdownIt from 'markdown-it' -import hljs from 'highlight.js' -import _ from 'underscore' +import frontMatter from 'front-matter'; +import markdownIt from 'markdown-it'; +import hljs from 'highlight'; +import _ from 'underscore'; const highlight = (str, lang) => { if ((lang !== null) && hljs.getLanguage(lang)) { @@ -17,23 +17,23 @@ const highlight = (str, lang) => { console.error(_error) } return '' -} +}; const md = markdownIt({ html: true, linkify: true, typographer: true, - highlight: highlight, -}) + highlight: highlight +}); module.exports = function (content) { - let body - this.cacheable() - const meta = frontMatter(content) - body = md.render(meta.body) + let body; + this.cacheable(); + const meta = frontMatter(content); + body = md.render(meta.body); const result = _.extend({}, meta.attributes, { - body: body, - }) - this.value = result + body: body + }); + this.value = result; return 'module.exports = ' + JSON.stringify(result) -} +}; diff --git a/lib/utils/build-production.coffee b/lib/utils/build-production.coffee deleted file mode 100644 index fa8c9b6b174d7..0000000000000 --- a/lib/utils/build-production.coffee +++ /dev/null @@ -1,14 +0,0 @@ -webpack = require 'webpack' -webpackConfig = require './webpack.config' -getUserGatsbyConfig = require './get-user-gatsby-config' - -module.exports = (program, callback) -> - {relativeDirectory, directory} = program - - #### Build production js. - compilerConfig = webpackConfig(program, directory, 'production') - config = getUserGatsbyConfig(compilerConfig, 'production') - - webpack(config.resolve()).run (err, stats) -> - callback err, stats - diff --git a/lib/utils/build-production.es6 b/lib/utils/build-production.es6 new file mode 100644 index 0000000000000..27849f744c791 --- /dev/null +++ b/lib/utils/build-production.es6 @@ -0,0 +1,14 @@ +import webpack from 'webpack'; +import webpackConfig from './webpack.config'; +import getUserGatsbyConfig from './get-user-gatsby-config'; + +module.exports = function(program, callback) { + var {relativeDirectory, directory} = program; + + var compilerConfig = webpackConfig(program, directory, 'production'); + var config = getUserGatsbyConfig(compilerConfig, 'production'); + + return webpack(config.resolve()).run(function(err, stats) { + return callback(err, stats); + }); +}; \ No newline at end of file diff --git a/lib/utils/build.js b/lib/utils/build.es6 similarity index 55% rename from lib/utils/build.js rename to lib/utils/build.es6 index 0d69572d58531..f1d1fdd46de59 100644 --- a/lib/utils/build.js +++ b/lib/utils/build.es6 @@ -1,41 +1,41 @@ -import generateStaticPages from './static-generation' -import buildProductionBundle from './build-production' -import postBuild from './post-build' -import globPages from './glob-pages' +import generateStaticPages from './static-generation'; +import buildProductionBundle from './build-production'; +import postBuild from './post-build'; +import globPages from './glob-pages'; module.exports = (program, callback) => { - const directory = program.directory - let customPostBuild + const directory = program.directory; + let customPostBuild; try { customPostBuild = require(directory + '/post-build') } catch (e) { - // Do nothiing. + // Do nothing. } - console.log('Generating static html pages') + console.log('Generating static html pages'); return generateStaticPages(program, (err) => { if (err) { - console.log('failed at generating static html pages') + console.log('failed at generating static html pages'); return callback(err) } - console.log('Compiling production bundle.js') + console.log('Compiling production bundle.js'); return buildProductionBundle(program, (e) => { if (e) { - console.log('failed to compile bundle.js') + console.log('failed to compile bundle.js'); return callback(e) } - console.log('Copying assets') + console.log('Copying assets'); return postBuild(program, (error) => { if (error) { - console.log('failed to copy assets') + console.log('failed to copy assets'); return callback(error) } if ( (typeof customPostBuild !== 'undefined' && customPostBuild !== null) ) { - console.log('Performing custom post-build steps') + console.log('Performing custom post-build steps'); return globPages(directory, (globError, pages) => { return customPostBuild(pages, (customPostBuildError) => { if (customPostBuildError) { - console.log('customPostBuild function failed') + console.log('customPostBuild function failed'); callback(customPostBuildError) } return callback(null) @@ -45,4 +45,4 @@ module.exports = (program, callback) => { }) }) }) -} +}; diff --git a/lib/utils/develop.js b/lib/utils/develop.es6 similarity index 64% rename from lib/utils/develop.js rename to lib/utils/develop.es6 index 774b675e8a8df..a265eba57a688 100644 --- a/lib/utils/develop.js +++ b/lib/utils/develop.es6 @@ -1,56 +1,56 @@ -require('node-cjsx').transform() -import Hapi from 'hapi' -import Boom from 'boom' -import React from 'react' -import ReactDOMServer from 'react-dom/server' -import WebpackDevServer from 'webpack-dev-server' -import webpack from 'webpack' -import Negotiator from 'negotiator' -import parsePath from 'parse-filepath' -import _ from 'underscore' -import webpackRequire from 'webpack-require' -import fs from 'fs' -import getUserGatsbyConfig from './get-user-gatsby-config' -import globPages from './glob-pages' -import webpackConfig from './webpack.config' -const debug = require('debug')('gatsby:application') +import Hapi from 'hapi'; +import Boom from 'boom'; +import React from 'react'; +import ReactDOMServer from 'react-dom/server'; +import WebpackDevServer from 'webpack-dev-server'; +import webpack from 'webpack'; +import Negotiator from 'negotiator'; +import parsePath from 'parse-filepath'; +import _ from 'underscore'; +import webpackRequire from 'webpack-require'; +import fs from 'fs'; +import getUserGatsbyConfig from './get-user-gatsby-config'; +import globPages from './glob-pages'; +import webpackConfig from './webpack.config'; + +const debug = require('debug')('gatsby:application'); module.exports = (program) => { - const directory = program.directory + const directory = program.directory; // Load pages for the site. return globPages(directory, (err, pages) => { // Generate random port for webpack to listen on. // Perhaps should check if port is open. - const webpackPort = Math.round(Math.random() * 1000 + 1000) + const webpackPort = Math.round(Math.random() * 1000 + 1000); - const compilerConfig = webpackConfig(program, directory, 'develop', webpackPort) - const config = getUserGatsbyConfig(compilerConfig, 'develop') + const compilerConfig = webpackConfig(program, directory, 'develop', webpackPort); + const config = getUserGatsbyConfig(compilerConfig, 'develop'); - const compiler = webpack(config.resolve()) + const compiler = webpack(config.resolve()); - let HTMLPath + let HTMLPath; if (fs.existsSync(directory + '/html.cjsx') || fs.existsSync(directory + '/html.jsx')) { - debug('using project\'s html wrapper') + debug('using project\'s html wrapper'); HTMLPath = directory + '/html' } else { - debug('using gatsby default html wrapper') + debug('using gatsby default html wrapper'); HTMLPath = __dirname + '/../isomorphic/html' } - const htmlCompilerConfig = webpackConfig(program, directory, 'production', webpackPort) - const htmlConfig = getUserGatsbyConfig(htmlCompilerConfig, 'production') + const htmlCompilerConfig = webpackConfig(program, directory, 'production', webpackPort); + const htmlConfig = getUserGatsbyConfig(htmlCompilerConfig, 'production'); 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.jsx'); error.forEach((e) => { console.log(e) - }) + }); process.exit() } - const HTML = factory() - debug('configuring server') + const HTML = factory(); + debug('configuring server'); const webpackDevServer = new WebpackDevServer(compiler, { hot: true, @@ -58,20 +58,20 @@ module.exports = (program) => { noInfo: true, host: program.host, stats: { - colors: true, - }, - }) + colors: true + } + }); // Start webpack-dev-server webpackDevServer.listen(webpackPort, program.host, () => { - }) + }); // Setup and start Hapi to serve html + static files. - const server = new Hapi.Server() + const server = new Hapi.Server(); server.connection({ host: program.host, - port: program.port, - }) + port: program.port + }); server.route({ method: 'GET', @@ -80,10 +80,10 @@ module.exports = (program) => { proxy: { uri: 'http://localhost:' + webpackPort + '/bundle.js', passThrough: true, - xforward: true, - }, - }, - }) + xforward: true + } + } + }); server.route({ method: 'GET', @@ -93,11 +93,11 @@ module.exports = (program) => { return reply(Boom.notFound()) } - let html = ReactDOMServer.renderToStaticMarkup(React.createElement(HTML)) - html = '\n' + html + let html = ReactDOMServer.renderToStaticMarkup(React.createElement(HTML)); + html = '\n' + html; return reply(html) - }, - }) + } + }); server.route({ method: 'GET', @@ -106,23 +106,23 @@ module.exports = (program) => { directory: { path: directory + '/pages', listing: false, - index: false, - }, - }, - }) + index: false + } + } + }); server.ext('onRequest', (request, reply) => { - const negotiator = new Negotiator(request.raw.req) + const negotiator = new Negotiator(request.raw.req); if (negotiator.mediaType() === 'text/html') { - request.setUrl('/html' + request.path) + request.setUrl('/html' + request.path); reply.continue() } else { // Rewrite path to match disk path. - const parsed = parsePath(request.path) + const parsed = parsePath(request.path); const page = _.find(pages, (p) => { return p.path === (parsed.dirname + '/') - }) + }); if (page) { request.setUrl('/' + parsePath(page.requirePath).dirname + '/' + parsed.basename) @@ -130,7 +130,7 @@ module.exports = (program) => { return reply.continue() } - }) + }); return server.start((e) => { if (e) { @@ -140,4 +140,4 @@ module.exports = (program) => { }) }) }) -} +}; diff --git a/lib/utils/get-user-gatsby-config.js b/lib/utils/get-user-gatsby-config.es6 similarity index 60% rename from lib/utils/get-user-gatsby-config.js rename to lib/utils/get-user-gatsby-config.es6 index 64d9e1068b1e4..8e2c9d5658dff 100644 --- a/lib/utils/get-user-gatsby-config.js +++ b/lib/utils/get-user-gatsby-config.es6 @@ -1,11 +1,11 @@ -import path from 'path' -import fs from 'fs' +import path from 'path'; +import fs from 'fs'; module.exports = (config, env) => { - const gatsbyConfig = path.resolve(process.cwd(), './gatsby.config.js') + const gatsbyConfig = path.resolve(process.cwd(), './gatsby.config.js'); if (fs.existsSync(gatsbyConfig)) { - return require(gatsbyConfig)(config, env) + return require(gatsbyConfig)(config, env); } return config -} +}; diff --git a/lib/utils/glob-pages.coffee b/lib/utils/glob-pages.coffee deleted file mode 100644 index ad74ac9c6c707..0000000000000 --- a/lib/utils/glob-pages.coffee +++ /dev/null @@ -1,78 +0,0 @@ -glob = require('glob') -path = require 'path' -parsePath = require 'parse-filepath' -fs = require 'fs' -frontMatter = require 'front-matter' -_ = require 'underscore' -toml = require('toml') -debug = require('debug')('gatsby:glob') - -module.exports = (directory, callback) -> - # Read in site config. - try - siteConfig = toml.parse(fs.readFileSync(directory + "/config.toml")) - - pagesData = [] - - app = require directory + "/app" - - # Make this easy to add to through the config? - # Or just keep adding extensions...? - glob directory + '/pages/**/?(*.coffee|*.cjsx|*.jsx|*.js|*.md|*.html)', null, (err, pages) => - if err then return callback(err) - - for page in pages - pageData = {} - pageData.file = {} - - pageData.file = parsed = parsePath(path.relative(directory + "/pages", page)) - - pageData.file.ext = ext = parsed.extname.slice(1) - - # Determine require path - relativePath = path.relative(directory, page) - pageData.requirePath = path.relative(directory + "/pages", page) - - # Load data for each file type. - if ext is "md" - rawData = frontMatter(fs.readFileSync(page, 'utf-8')) - data = _.extend {}, rawData.attributes - pageData.data = data - else if ext is "html" - pageData.data = fs.readFileSync(page, 'utf-8') - else - data = {} - - # Determine path for page (unless it's a file that starts with an - # underscore as these don't become pages). - unless parsed.name.slice(0,1) is "_" - if data.path - # Path was hardcoded. - pageData.path = data.path - else if app.rewritePath - pageData.path = app.rewritePath(parsed, pageData) - - # If none of the above options set a path. - unless pageData.path? - # If this is an index page or template, it's path is /foo/bar/ - if parsed.name is "index" or parsed.name is "template" - if parsed.dirname is "." - pageData.path = "/" - else - pageData.path = "/" + parsed.dirname + "/" - # Else if not an index, create a path like /foo/bar/ - # and rely upon static-site-generator-webpack-plugin to add index.html - else - if parsed.dirname is "." - pageData.path = "/" + parsed.name + "/" - else - pageData.path = "/" + parsed.dirname + "/" + parsed.name + "/" - - # Set the "template path" - else if parsed.name is "_template" - pageData.templatePath = "/" + parsed.dirname + "/" - - pagesData.push pageData - - debug('globbed', pagesData.length, 'pages'); - callback(null, pagesData) diff --git a/lib/utils/glob-pages.es6 b/lib/utils/glob-pages.es6 new file mode 100644 index 0000000000000..841aba7166ae1 --- /dev/null +++ b/lib/utils/glob-pages.es6 @@ -0,0 +1,94 @@ +import glob from 'glob'; +import path from 'path'; +import parsePath from 'parse-filepath'; +import fs from 'fs'; +import frontMatter from 'front-matter'; +import _ from 'underscore'; +import toml from 'toml'; + +var debug = require('debug')('gatsby:glob'); + +module.exports = function(directory, callback) { + // Read in site config. + try { + var siteConfig = toml.parse(fs.readFileSync(directory + "/config.toml")); + } catch (error) { + } + + var pagesData = []; + + var app = require(directory + "/app"); + + // Make this easy to add to through the config? + // Or just keep adding extensions...? + return glob(directory + '/pages/**/?(*.coffee|*.cjsx|*.jsx|*.js|*.md|*.html)', null, (err, pages) => { + if (err) { return callback(err); } + + for (var i = 0, page; i < pages.length; i++) { + page = pages[i]; + var parsed; + var ext; + var pageData = {}; + pageData.file = {}; + + pageData.file = parsed = parsePath(path.relative(directory + "/pages", page)); + + pageData.file.ext = ext = parsed.extname.slice(1); + + // Determine require path + var relativePath = path.relative(directory, page); + pageData.requirePath = path.relative(directory + "/pages", page); + + // Load data for each file type. + if (ext === "md") { + var rawData = frontMatter(fs.readFileSync(page, 'utf-8')); + var data = _.extend({}, rawData.attributes); + pageData.data = data; + } else if (ext === "html") { + pageData.data = fs.readFileSync(page, 'utf-8'); + } else { + data = {}; + } + + // Determine path for page (unless it's a file that starts with an + // underscore as these don't become pages). + if (!(parsed.name.slice(0,1) === "_")) { + if (data.path) { + // Path was hardcoded. + pageData.path = data.path; + } else if (app.rewritePath) { + pageData.path = app.rewritePath(parsed, pageData); + } + + // If none of the above options set a path. + if (!(pageData.path != null)) { + // If this is an index page or template, it's path is /foo/bar/ + if (parsed.name === "index" || parsed.name === "template") { + if (parsed.dirname === ".") { + pageData.path = "/"; + } else { + pageData.path = "/" + parsed.dirname + "/"; + } + // Else if not an index, create a path like /foo/bar/ + // and rely upon static-site-generator-webpack-plugin to add index.html + } else { + if (parsed.dirname === ".") { + pageData.path = "/" + parsed.name + "/"; + } else { + pageData.path = "/" + parsed.dirname + "/" + parsed.name + "/"; + } + } + } + + // Set the "template path" + } else if (parsed.name === "_template") { + pageData.templatePath = "/" + parsed.dirname + "/"; + } + + pagesData.push(pageData); + } + + return debug('globbed', pagesData.length, 'pages'), + callback(null, pagesData); + }); +}; diff --git a/lib/utils/init-starter.js b/lib/utils/init-starter.es6 similarity index 70% rename from lib/utils/init-starter.js rename to lib/utils/init-starter.es6 index d419c2d04189e..cb04cee76f69e 100644 --- a/lib/utils/init-starter.js +++ b/lib/utils/init-starter.es6 @@ -1,14 +1,14 @@ -const exec = require('child_process').exec -import fs from 'fs' -import mkdirp from 'mkdirp' -import sysPath from 'path' -import rimraf from 'rimraf' -import ncp from 'ncp' +const exec = require('child_process').exec; +import fs from 'fs'; +import mkdirp from 'mkdirp'; +import sysPath from 'path'; +import rimraf from 'rimraf'; +import ncp from 'ncp'; -let logger = console +let logger = console; // Shortcut for backwards-compat fs.exists. -const fsexists = fs.exists || sysPath.exists +const fsexists = fs.exists || sysPath.exists; // Executes `npm install` and `bower install` in rootPath. // @@ -17,30 +17,30 @@ const fsexists = fs.exists || sysPath.exists // // Returns nothing. const install = (rootPath, callback) => { - const prevDir = process.cwd() - logger.log('Installing packages...') - process.chdir(rootPath) + const prevDir = process.cwd(); + logger.log('Installing packages...'); + process.chdir(rootPath); fsexists('bower.json', (exists) => { - let installCmd = 'npm install' - if (exists) installCmd += ' & bower install' + let installCmd = 'npm install'; + if (exists) installCmd += ' & bower install'; exec(installCmd, (error, stdout, stderr) => { - let log - process.chdir(prevDir) - if (stdout) console.log(stdout.toString()) + let log; + process.chdir(prevDir); + if (stdout) console.log(stdout.toString()); if (error !== null) { - log = stderr.toString() - const bowerNotFound = /bower\: command not found/.test(log) + log = stderr.toString(); + const bowerNotFound = /bower\: command not found/.test(log); const msg = bowerNotFound ? 'You need to install Bower and then install starter dependencies: `npm install -g bower && bower install`. Error text: ' + log : log return callback(new Error(msg)) } callback(null, stdout) }) }) -} +}; const ignored = (path) => { return !(/^\.(git|hg)$/.test(sysPath.basename(path))) -} +}; // Copy starter from file system. // @@ -52,26 +52,26 @@ const ignored = (path) => { const copy = (starterPath, rootPath, callback) => { const copyDirectory = () => { ncp(starterPath, rootPath, {filter: ignored, stopOnErr: true}, (error) => { - if (error !== null) return callback(new Error(error)) - logger.log('Created starter directory layout') + if (error !== null) return callback(new Error(error)); + logger.log('Created starter directory layout'); install(rootPath, callback) }) - } + }; // Chmod with 755. mkdirp(rootPath, 0x1ed, (error) => { - if (error !== null) return callback(new Error(error)) + if (error !== null) return callback(new Error(error)); fsexists(starterPath, (exists) => { if (!exists) { - const chmodError = 'starter ' + starterPath + " doesn't exist" + const chmodError = 'starter ' + starterPath + " doesn't exist"; return callback(new Error(chmodError)) } - logger.log('Copying local starter to ' + rootPath + '...') + logger.log('Copying local starter to ' + rootPath + '...'); copyDirectory() }) }) -} +}; // Clones starter from URI. // @@ -81,22 +81,22 @@ const copy = (starterPath, rootPath, callback) => { // // Returns nothing. const clone = (address, rootPath, callback) => { - const gitHubRe = /(gh|github)\:(?:\/\/)?/ + const gitHubRe = /(gh|github)\:(?:\/\/)?/; const url = gitHubRe.test(address) ? - ('git://github.com/' + address.replace(gitHubRe, '') + '.git') : address - logger.log('Cloning git repo ' + url + ' to ' + rootPath + '...') - const cmd = 'git clone ' + url + ' ' + rootPath + ('git://github.com/' + address.replace(gitHubRe, '') + '.git') : address; + logger.log('Cloning git repo ' + url + ' to ' + rootPath + '...'); + const cmd = 'git clone ' + url + ' ' + rootPath; exec(cmd, (error, stdout, stderr) => { if (error !== null) { return callback(new Error('Git clone error: ' + stderr.toString())) } - logger.log('Created starter directory layout') + logger.log('Created starter directory layout'); rimraf(sysPath.join(rootPath, '.git'), (rimRafError) => { - if (error !== null) return callback(new Error(rimRafError)) + if (error !== null) return callback(new Error(rimRafError)), install(rootPath, callback) }) }) -} +}; // Main function that clones or copies the starter. // @@ -106,19 +106,19 @@ const clone = (address, rootPath, callback) => { // // Returns nothing. const initStarter = (starter, options = {}, callback) => { - const cwd = process.cwd() - const rootPath = options.rootPath || cwd - if (options.logger) logger = options.logger + const cwd = process.cwd(); + const rootPath = options.rootPath || cwd; + if (options.logger) logger = options.logger; - const uriRe = /(?:https?|git(hub)?|gh)(?::\/\/|@)?/ + const uriRe = /(?:https?|git(hub)?|gh)(?::\/\/|@)?/; fsexists(sysPath.join(rootPath, 'package.json'), (exists) => { if (exists) { return callback(new Error('Directory ' + rootPath + ' is already an npm project')) } - const isGitUri = starter && uriRe.test(starter) - const get = isGitUri ? clone : copy + const isGitUri = starter && uriRe.test(starter); + const get = isGitUri ? clone : copy; get(starter, rootPath, callback) }) -} +}; -module.exports = initStarter +module.exports = initStarter; diff --git a/lib/utils/post-build.js b/lib/utils/post-build.es6 similarity index 63% rename from lib/utils/post-build.js rename to lib/utils/post-build.es6 index f0bc8ea753a45..d0b07a35b0184 100644 --- a/lib/utils/post-build.js +++ b/lib/utils/post-build.es6 @@ -1,33 +1,34 @@ -import path from 'path' -import glob from 'glob' -import fs from 'fs-extra' -import async from 'async' -import parsePath from 'parse-filepath' -import _ from 'underscore' -const debug = require('debug')('gatsby:post-build') +import path from 'path'; +import glob from 'glob'; +import fs from 'fs-extra'; +import async from 'async'; +import parsePath from 'parse-filepath'; +import _ from 'underscore'; -import globPages from './glob-pages' +const debug = require('debug')('gatsby:post-build'); + +import globPages from './glob-pages'; module.exports = (program, cb) => { - const directory = program.directory + const directory = program.directory; return globPages(directory, (err, pages) => { - debug('copying files') + debug('copying files'); // Async callback to copy each file. const copy = function copyFile (file, callback) { // Map file to path generated for that directory. // e.g. if file is in directory 2015-06-16-my-sweet-blog-post that got // rewritten to my-sweet-blog-post, we find that path rewrite so // our asset gets copied to the right directory. - const parsed = parsePath(file) - const relativePath = path.relative(directory + '/pages', file) - let oldDirectory = parsePath(relativePath).dirname - let newPath = '' + const parsed = parsePath(file); + const relativePath = path.relative(directory + '/pages', file); + let oldDirectory = parsePath(relativePath).dirname; + let newPath = ''; // Wouldn't rewrite basePath if (oldDirectory === '.') { - oldDirectory = '/' - newPath = '/' + parsed.basename + oldDirectory = '/'; + newPath = '/' + parsed.basename; } if (!(oldDirectory === '/')) { @@ -36,24 +37,24 @@ module.exports = (program, cb) => { if (p.file.name.slice(0, 1) !== '_') { return parsePath(p.requirePath).dirname === oldDirectory } - }) + }); if (page) { newPath = parsePath(page.path).dirname + parsed.basename } else { - // We couldn't find a page associated with this file. Probably - // the file is in a directory of static files. In any case, - // we'll leave the file directory alone. + // We couldn't find a page associated with this file. + // Probably the file is in a directory of static files. + // In any case, we'll leave the file directory alone. newPath = relativePath } } - newPath = directory + '/public/' + newPath + newPath = directory + '/public/' + newPath; return fs.copy(file, newPath, (error) => { return callback(error) } ) - } + }; // Copy static assets to public folder. return glob(directory + '/pages/**/?(*.jpg|*.png|*.pdf|*.gif|*.ico|*.svg)', null, (e, files) => { @@ -62,4 +63,4 @@ module.exports = (program, cb) => { }) }) }) -} +}; diff --git a/lib/utils/static-entry.jsx b/lib/utils/static-entry.jsx index 7513085ed6e5c..cda40d8f6c46b 100644 --- a/lib/utils/static-entry.jsx +++ b/lib/utils/static-entry.jsx @@ -2,7 +2,7 @@ import ServerReactRootIndex from 'react/lib/ServerReactRootIndex' ServerReactRootIndex.createReactRootIndex = () => { return 'gatsby' -} +}; import React from 'react' import ReactDOMServer from 'react-dom/server' @@ -14,39 +14,39 @@ import HTML from 'html' import app from 'app' import values from 'config' import helpers from '../isomorphic/gatsby-helpers' -const link = helpers.link -let pages = values.pages -const config = values.config -let routes = {} -let linkPrefix = config.linkPrefix +const link = helpers.link; +let pages = values.pages; +const config = values.config; +let routes = {}; +let linkPrefix = config.linkPrefix; if (!__PREFIX_LINKS__ || !linkPrefix) { linkPrefix = '' } app.loadContext((pagesReq) => { - routes = createRoutes(pages, pagesReq) + routes = createRoutes(pages, pagesReq); // Remove templates files. pages = filter(pages, (page) => { return page.path !== null }) -}) +}); module.exports = (locals, callback) => { return Router.run([routes], link(locals.path), (Handler, state) => { - let body - let childPages - let childrenPaths - let html - let page + let body; + let childPages; + let childrenPaths; + let html; + let page; page = find(pages, (p) => { return linkPrefix + p.path === state.path - }) + }); // Pull out direct children of the template for this path. childrenPaths = state.routes[state.routes.length - 2].childRoutes.map((route) => { return route.path - }) + }); if (childrenPaths) { childPages = filter(pages, (p) => { return childrenPaths.indexOf(linkPrefix + p.path) >= 0 @@ -55,8 +55,8 @@ module.exports = (locals, callback) => { childPages = [] } - body = '' - html = '' + body = ''; + html = ''; try { body = ReactDOMServer.renderToString( { page={page} childPages={childPages} state={state} /> - ) + ); html = '\n' + ReactDOMServer.renderToStaticMarkup( ) @@ -75,4 +75,4 @@ module.exports = (locals, callback) => { return callback(null, html) }) -} +}; diff --git a/lib/utils/static-generation.coffee b/lib/utils/static-generation.coffee deleted file mode 100644 index d04ca3c592053..0000000000000 --- a/lib/utils/static-generation.coffee +++ /dev/null @@ -1,24 +0,0 @@ -require('node-cjsx').transform() -webpack = require 'webpack' -globPages = require './glob-pages' -webpackConfig = require './webpack.config' -getUserGatsbyConfig = require './get-user-gatsby-config' -debug = require('debug')('gatsby:static') - -module.exports = (program, callback) -> - {relativeDirectory, directory} = program - - globPages directory, (err, pages) -> - debug('generating static site') - routes = pages.filter((page) -> page.path?).map((page) -> page.path) - - #### Static site generation. - compilerConfig = webpackConfig(program, directory, 'static', null, routes) - config = getUserGatsbyConfig(compilerConfig, 'static') - - webpack(config.resolve()).run (err, stats) -> - if err - return callback(err, stats) - if stats.hasErrors() - return callback('Error: ' + stats.toJson().errors, stats) - callback(null, stats) diff --git a/lib/utils/static-generation.es6 b/lib/utils/static-generation.es6 new file mode 100644 index 0000000000000..d2bef1c973f56 --- /dev/null +++ b/lib/utils/static-generation.es6 @@ -0,0 +1,29 @@ +require('node-cjsx').transform(); +import webpack from 'webpack'; +import globPages from './glob-pages'; +import webpackConfig from './webpack.config'; +import getUserGatsbyConfig from './get-user-gatsby-config'; + +var debug = require('debug')('gatsby:static'); + +module.exports = function(program, callback) { + var {relativeDirectory, directory} = program; + + return globPages(directory, function(err, pages) { + debug('generating static site'); + var routes = pages.filter(function(page) { return (page.path != null); }).map(function(page) { return page.path; }); + + var compilerConfig = webpackConfig(program, directory, 'static', null, routes); + var config = getUserGatsbyConfig(compilerConfig, 'static'); + + return webpack(config.resolve()).run(function(err, stats) { + if (err) { + return callback(err, stats); + } + if (stats.hasErrors()) { + return callback('Error: ' + stats.toJson().errors, stats); + } + return callback(null, stats); + }); + }); +}; diff --git a/lib/utils/web-entry.jsx b/lib/utils/web-entry.jsx index ba1f93617b4d8..7b27ac1ad8d85 100644 --- a/lib/utils/web-entry.jsx +++ b/lib/utils/web-entry.jsx @@ -1,13 +1,13 @@ -import React from 'react' -import ReactDOM from 'react-dom' -import Router from 'react-router' -import find from 'lodash/collection/find' -import filter from 'lodash/collection/filter' -import createRoutes from 'create-routes' -import app from 'app' +import React from 'react'; +import ReactDOM from 'react-dom'; +import Router from 'react-router'; +import find from 'lodash/collection/find'; +import filter from 'lodash/collection/filter'; +import createRoutes from 'create-routes'; +import app from 'app'; function loadConfig (cb) { - const stuff = require('config') + const stuff = require('config'); if (module.hot) { module.hot.accept(stuff.id, function hotAccept () { return cb() @@ -18,31 +18,31 @@ function loadConfig (cb) { loadConfig(function loadConfigFunc () { return app.loadContext(function loadContextFunc (pagesReq) { - let router - const ref = require('config') - let pages = ref.pages - const config = ref.config - let linkPrefix = config.linkPrefix + let router; + const ref = require('config'); + let pages = ref.pages; + const config = ref.config; + let linkPrefix = config.linkPrefix; if (!__PREFIX_LINKS__ || !linkPrefix) { linkPrefix = '' } - const routes = createRoutes(pages, pagesReq) + const routes = createRoutes(pages, pagesReq); // Remove templates files. pages = filter(pages, (page) => { return page.path !== null - }) + }); // Route already exists meaning we're hot-reloading. if (router) { router.replaceRoutes([app]) } else { router = Router.run([routes], Router.HistoryLocation, (Handler, state) => { - let page + let page; page = find(pages, (p) => { - const path = linkPrefix + p.path + const path = linkPrefix + p.path; return path === state.path || path === state.pathname - }) + }); // Let app know the route is changing. if (app.onRouteChange) { @@ -58,4 +58,4 @@ loadConfig(function loadConfigFunc () { }) } }) -}) +}); diff --git a/lib/utils/webpack.config.js b/lib/utils/webpack.config.es6 similarity index 63% rename from lib/utils/webpack.config.js rename to lib/utils/webpack.config.es6 index 011b0605197c1..de7d3b6dfdcc4 100644 --- a/lib/utils/webpack.config.js +++ b/lib/utils/webpack.config.es6 @@ -1,17 +1,15 @@ -import webpack from 'webpack' -import StaticSiteGeneratorPlugin from 'static-site-generator-webpack-plugin' -import Config from 'webpack-configurator' -import published from '../../bin/published' +import webpack from 'webpack'; +import StaticSiteGeneratorPlugin from 'static-site-generator-webpack-plugin'; +import Config from 'webpack-configurator'; +import published from '../../bin/published'; -let gatsbyLib = /(gatsby.lib)/i +let gatsbyLib = /(gatsby.lib)/i; // If installed globally, look for "dist" directory instead. -if (published) { - gatsbyLib = /(gatsby.dist)/i -} +if (published) (gatsbyLib = /(gatsby.dist)/i); -const libDirs = /(node_modules|bower_components)/i +const libDirs = /(node_modules|bower_components)/i; const babelExcludeTest = (absPath) => { - let result = false + let result = false; if (absPath.match(gatsbyLib)) { // There is a match, don't exclude this file. result = false @@ -23,7 +21,7 @@ const babelExcludeTest = (absPath) => { } return result -} +}; module.exports = (program, directory, stage, webpackPort = 1500, routes = []) => { function output () { @@ -32,19 +30,19 @@ module.exports = (program, directory, stage, webpackPort = 1500, routes = []) => return { path: directory, filename: 'bundle.js', - publicPath: `http://${program.host}:${webpackPort}/`, - } + publicPath: `http://${program.host}:${webpackPort}/` + }; case 'production': return { filename: 'bundle.js', - path: directory + '/public', - } + path: directory + '/public' + }; case 'static': return { path: directory + '/public', filename: 'bundle.js', - libraryTarget: 'umd', - } + libraryTarget: 'umd' + }; default: throw new Error('The state requested ' + stage + " doesn't exist.") } @@ -56,16 +54,16 @@ module.exports = (program, directory, stage, webpackPort = 1500, routes = []) => return [ require.resolve('webpack-dev-server/client') + `?${program.host}:${webpackPort}`, require.resolve('webpack/hot/only-dev-server'), - `${__dirname}/web-entry`, - ] + `${__dirname}/web-entry` + ]; case 'production': return [ - `${__dirname}/web-entry`, - ] + `${__dirname}/web-entry` + ]; case 'static': return [ - `${__dirname}/static-entry`, - ] + `${__dirname}/static-entry` + ]; default: throw new Error('The state requested ' + stage + " doesn't exist.") } @@ -78,33 +76,33 @@ module.exports = (program, directory, stage, webpackPort = 1500, routes = []) => new webpack.HotModuleReplacementPlugin(), new webpack.DefinePlugin({ 'process.env': { - NODE_ENV: JSON.stringify(process.env.NODE_ENV ? process.env.NODE_ENV : 'development'), + NODE_ENV: JSON.stringify(process.env.NODE_ENV ? process.env.NODE_ENV : 'development') }, - __PREFIX_LINKS__: program.prefixLinks, - }), - ] + __PREFIX_LINKS__: program.prefixLinks + }) + ]; case 'production': return [ new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/), new webpack.DefinePlugin({ 'process.env': { - NODE_ENV: JSON.stringify(process.env.NODE_ENV ? process.env.NODE_ENV : 'production'), + NODE_ENV: JSON.stringify(process.env.NODE_ENV ? process.env.NODE_ENV : 'production') }, - __PREFIX_LINKS__: program.prefixLinks, + __PREFIX_LINKS__: program.prefixLinks }), new webpack.optimize.DedupePlugin(), - new webpack.optimize.UglifyJsPlugin(), - ] + new webpack.optimize.UglifyJsPlugin() + ]; case 'static': return [ new StaticSiteGeneratorPlugin('bundle.js', routes), new webpack.DefinePlugin({ 'process.env': { - NODE_ENV: JSON.stringify(process.env.NODE_ENV ? process.env.NODE_ENV : 'production'), + NODE_ENV: JSON.stringify(process.env.NODE_ENV ? process.env.NODE_ENV : 'production') }, - __PREFIX_LINKS__: program.prefixLinks, - }), - ] + __PREFIX_LINKS__: program.prefixLinks + }) + ]; default: throw new Error('The state requested ' + stage + " doesn't exist.") } @@ -112,13 +110,13 @@ module.exports = (program, directory, stage, webpackPort = 1500, routes = []) => function resolve () { return { - extensions: ['', '.js', '.jsx', '.cjsx', '.coffee', '.json', '.less', '.toml', '.yaml'], + extensions: ['', '.js', '.jsx', '.json', '.less', '.toml', '.yaml'], modulesDirectories: [ directory, `${__dirname}/../isomorphic`, `${directory}/node_modules`, - 'node_modules', - ], + 'node_modules' + ] } } @@ -126,130 +124,114 @@ module.exports = (program, directory, stage, webpackPort = 1500, routes = []) => switch (stage) { case 'develop': case 'static': - return 'eval' + return 'eval'; case 'production': - return 'source-map' + return 'source-map'; default: } } function module (config) { // common config for every env - config.loader('cjsx', { - test: /\.cjsx$/, - loaders: ['coffee', 'cjsx'], - }) config.loader('js', { test: /\.jsx?$/, exclude: babelExcludeTest, - loaders: ['babel'], - }) - config.loader('coffee', { - test: /\.coffee$/, - loader: 'coffee', - }) + loaders: ['babel'] + }); config.loader('md', { test: /\.md$/, - loader: 'markdown', - }) + loader: 'markdown' + }); config.loader('html', { test: /\.html$/, - loader: 'raw', - }) + loader: 'raw' + }); config.loader('json', { test: /\.json$/, - loaders: ['json'], - }) + loaders: ['json'] + }); config.loader('toml', { test: /^((?!config).)*\.toml$/, - loaders: ['toml'], - }) + loaders: ['toml'] + }); // Match everything except config.toml config.loader('png', { test: /\.png$/, - loader: 'null', - }) + loader: 'null' + }); config.loader('jpg', { test: /\.jpg$/, - loader: 'null', - }) + loader: 'null' + }); config.loader('svg', { test: /\.svg$/, - loader: 'null', - }) + loader: 'null' + }); config.loader('ico', { test: /\.ico$/, - loader: 'null', - }) + loader: 'null' + }); config.loader('pdf', { test: /\.pdf$/, - loader: 'null', - }) + loader: 'null' + }); config.loader('txt', { test: /\.txt$/, - loader: 'null', - }) + loader: 'null' + }); config.loader('config', { test: /config\.[toml|yaml|json]/, loader: 'config', query: { - directory: directory, - }, - }) + directory: directory + } + }); switch (stage) { case 'develop': config.loader('css', { test: /\.css$/, - loaders: ['style', 'css'], - }) + loaders: ['style', 'css'] + }); config.loader('less', { test: /\.less/, - loaders: ['style', 'css', 'less'], - }) + loaders: ['style', 'css', 'less'] + }); config.loader('js', {}, (cfg) => { - cfg.loaders.unshift('react-hot') + cfg.loaders.unshift('react-hot', 'babel'); return cfg - }) - config.loader('cjsx', {}, (cfg) => { - cfg.loaders.unshift('react-hot') - return cfg - }) - return config + }); + return config; case 'static': - config.loader('css', { - test: /\.css$/, - loaders: ['css'], - }) config.loader('less', { test: /\.less/, - loaders: ['css', 'less'], - }) - return config + loaders: ['css', 'less'] + }); + return config; case 'production': config.loader('css', { test: /\.css$/, - loaders: ['style', 'css'], - }) + loaders: ['style', 'css'] + }); config.loader('less', { test: /\.less/, - loaders: ['style', 'css', 'less'], - }) + loaders: ['style', 'css', 'less'] + }); - return config + return config; default: } } - const config = new Config() + const config = new Config(); config.merge({ context: directory + '/pages', node: { - __filename: true, + __filename: true }, entry: entry(), debug: true, @@ -259,12 +241,12 @@ module.exports = (program, directory, stage, webpackPort = 1500, routes = []) => modulesDirectories: [ `${directory}/node_modules`, `${__dirname}/../../node_modules`, - `${__dirname}/../loaders`, - ], + `${__dirname}/../loaders` + ] }, plugins: plugins(), - resolve: resolve(), - }) + resolve: resolve() + }); return module(config) -} +}; diff --git a/package.json b/package.json index d997644280b3b..65f2a802d45ac 100644 --- a/package.json +++ b/package.json @@ -10,56 +10,52 @@ "url": "https://github.com/gatsby-group/gatsby/issues" }, "dependencies": { - "async": "^1.2.1", - "babel": "^5.8.29", - "babel-core": "^5.5.8", - "babel-loader": "^5.1.4", - "boom": "^2.7.2", - "cjsx-loader": "^2.0.1", - "coffee-loader": "^0.7.2", - "coffee-script": "^1.9.3", - "commander": "^2.8.1", - "css-loader": "^0.22.0", + "async": "^1.5.0", + "babel-loader": "^6.2.0", + "babel-register": "^6.3.13", + "boom": "^3.1.1", + "commander": "^2.9.0", + "css-loader": "^0.23.1", "debug": "^2.2.0", - "front-matter": "^1.0.0", - "fs-extra": "^0.19.0", - "glob": "^5.0.7", + "front-matter": "^2.0.1", + "fs-extra": "^0.26.3", + "glob": "^6.0.2", "hapi": "^8.5.1", - "highlight.js": "^8.6.0", - "json-loader": "^0.5.2", - "less": "^2.5.1", - "less-loader": "^2.2.0", - "loader-utils": "^0.2.8", - "lodash": "^3.9.3", - "loggy": "^0.2.0", - "markdown-it": "^5.0.0", + "highlight.js": "^9.0.0", + "history": "^1.17.0", + "json-loader": "^0.5.4", + "less": "^2.5.3", + "less-loader": "^2.2.2", + "loader-utils": "^0.2.12", + "lodash": "^3.10.1", + "loggy": "^0.2.2", + "markdown-it": "^5.0.2", "mkdirp": "^0.5.1", - "moment": "^2.10.3", + "moment": "^2.10.6", "ncp": "^2.0.0", - "negotiator": "^0.5.3", - "node-cjsx": "^1.0.0", - "node-libs-browser": "^0.5.2", + "negotiator": "^0.6.0", + "node-libs-browser": "^0.5.3", "null-loader": "^0.1.1", "object-assign": "^4.0.1", - "parse-filepath": "^0.5.0", + "parse-filepath": "^0.6.3", "raw-loader": "^0.5.1", - "react": "^0.14.2", + "react": "^0.14.3", "react-document-title": "^2.0.1", - "react-dom": "^0.14.2", - "react-hot-loader": "^1.2.7", - "react-router": "^0.13.5", - "rimraf": "^2.4.2", - "static-site-generator-webpack-plugin": "^1.0.0", + "react-dom": "^0.14.3", + "react-hot-loader": "^1.3.0", + "react-router": "^1.0.3", + "rimraf": "^2.5.0", + "static-site-generator-webpack-plugin": "^2.0.1", "style-loader": "^0.13.0", - "toml": "^2.2.2", + "toml": "^2.3.0", "toml-loader": "^1.0.0", "typography": "^0.6.2", "underscore": "^1.8.3", - "underscore.string": "^3.1.1", - "webpack": "^1.12.8", - "webpack-configurator": "^0.3.0", - "webpack-dev-server": "1.12.1", - "webpack-require": "0.0.15" + "underscore.string": "^3.2.2", + "webpack": "^1.12.9", + "webpack-configurator": "^0.3.1", + "webpack-dev-server": "1.14.0", + "webpack-require": "0.0.16" }, "homepage": "https://github.com/gatsby-group/gatsby#readme", "keywords": [ @@ -79,13 +75,17 @@ }, "scripts": { "test": "npm run lint", + "start": "./scripts/prepublish.sh && npm list", "lint": "./node_modules/.bin/eslint --ext .js,.jsx --ignore-pattern dist ." }, "devDependencies": { - "babel": "^5.8.34", - "babel-eslint": "^4.1.6", - "eslint": "^1.10.2", - "eslint-config-airbnb": "^1.0.2", - "eslint-plugin-react": "^3.11.2" + "babel-core": "^6.3.26", + "babel-eslint": "^5.0.0-beta6", + "babel-preset-es2015": "^6.3.13", + "babel-preset-react": "^6.3.13", + "babel-preset-stage-0": "^6.3.13", + "eslint": "^1.10.3", + "eslint-config-airbnb": "^2.1.1", + "eslint-plugin-react": "^3.13.1" } } diff --git a/scripts/build.sh b/scripts/build.sh index a0d486f275d9b..1964149582b7e 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -1,2 +1 @@ -node_modules/.bin/babel lib/ --out-dir dist -node_modules/.bin/coffee -co dist/ lib/ +babel lib/ --out-dir dist/ --presets es2015,stage-0,react From b594bb4e8efa4a8ac78fe513af71ce8365f735c3 Mon Sep 17 00:00:00 2001 From: Araphel Date: Mon, 28 Dec 2015 10:54:49 -0700 Subject: [PATCH 2/2] -.eslintrc restored + modified with no-loop-func disabled [ glob-pages will need to be rewritten for this to be on] -all jsx/es6 extension are now js -general cleanup as per lint requrement -react-router has been rolled back to it's previous version -lint with 3 warnings --- .eslintrc | 14 +- bin/build.es6 | 31 --- bin/build.js | 27 +++ bin/cli.js | 2 +- bin/develop.es6 | 26 --- bin/develop.js | 22 +++ bin/gatsby-build.js | 4 +- bin/gatsby-develop.js | 4 +- bin/gatsby-new.js | 4 +- bin/index.es6 | 11 -- bin/index.js | 10 + bin/new.es6 | 33 ---- bin/new.js | 23 +++ lib/isomorphic/{HTML.jsx => HTML.js} | 26 +-- lib/isomorphic/create-routes.es6 | 118 ------------ lib/isomorphic/create-routes.js | 111 +++++++++++ .../{gatsby-helpers.es6 => gatsby-helpers.js} | 28 +-- lib/isomorphic/wrappers/html.js | 18 ++ lib/isomorphic/wrappers/html.jsx | 16 -- lib/isomorphic/wrappers/md.js | 23 +++ lib/isomorphic/wrappers/md.jsx | 21 --- lib/loaders/config-loader/index.es6 | 27 --- lib/loaders/config-loader/index.js | 26 +++ .../markdown-loader/{index.es6 => index.js} | 36 ++-- lib/utils/build-production.es6 | 14 -- lib/utils/build-production.js | 16 ++ lib/utils/{build.es6 => build.js} | 34 ++-- lib/utils/{develop.es6 => develop.js} | 112 +++++------ ...y-config.es6 => get-user-gatsby-config.js} | 12 +- lib/utils/glob-pages.es6 | 94 ---------- lib/utils/glob-pages.js | 96 ++++++++++ .../{init-starter.es6 => init-starter.js} | 88 ++++----- lib/utils/{post-build.es6 => post-build.js} | 42 +++-- .../{static-entry.jsx => static-entry.js} | 45 ++--- lib/utils/static-generation.es6 | 29 --- lib/utils/static-generation.js | 29 +++ lib/utils/{web-entry.jsx => web-entry.js} | 43 +++-- .../{webpack.config.es6 => webpack.config.js} | 176 +++++++++--------- package.json | 3 +- 39 files changed, 755 insertions(+), 739 deletions(-) delete mode 100644 bin/build.es6 create mode 100644 bin/build.js delete mode 100644 bin/develop.es6 create mode 100644 bin/develop.js delete mode 100644 bin/index.es6 create mode 100644 bin/index.js delete mode 100644 bin/new.es6 create mode 100644 bin/new.js rename lib/isomorphic/{HTML.jsx => HTML.js} (66%) delete mode 100644 lib/isomorphic/create-routes.es6 create mode 100644 lib/isomorphic/create-routes.js rename lib/isomorphic/{gatsby-helpers.es6 => gatsby-helpers.js} (73%) create mode 100644 lib/isomorphic/wrappers/html.js delete mode 100644 lib/isomorphic/wrappers/html.jsx create mode 100644 lib/isomorphic/wrappers/md.js delete mode 100644 lib/isomorphic/wrappers/md.jsx delete mode 100644 lib/loaders/config-loader/index.es6 create mode 100644 lib/loaders/config-loader/index.js rename lib/loaders/markdown-loader/{index.es6 => index.js} (57%) delete mode 100644 lib/utils/build-production.es6 create mode 100644 lib/utils/build-production.js rename lib/utils/{build.es6 => build.js} (50%) rename lib/utils/{develop.es6 => develop.js} (64%) rename lib/utils/{get-user-gatsby-config.es6 => get-user-gatsby-config.js} (58%) delete mode 100644 lib/utils/glob-pages.es6 create mode 100644 lib/utils/glob-pages.js rename lib/utils/{init-starter.es6 => init-starter.js} (65%) rename lib/utils/{post-build.es6 => post-build.js} (72%) rename lib/utils/{static-entry.jsx => static-entry.js} (81%) delete mode 100644 lib/utils/static-generation.es6 create mode 100644 lib/utils/static-generation.js rename lib/utils/{web-entry.jsx => web-entry.js} (59%) rename lib/utils/{webpack.config.es6 => webpack.config.js} (65%) diff --git a/.eslintrc b/.eslintrc index 329eec0b29775..7855f0cd88922 100644 --- a/.eslintrc +++ b/.eslintrc @@ -8,12 +8,24 @@ "node": true }, "parser": "babel-eslint", + "extends": "eslint-config-airbnb", "rules": { + "no-loop-func": 0, "quotes": [2, "single"], "strict": [2, "never"], "react/jsx-uses-react": 2, "react/jsx-uses-vars": 2, - "react/react-in-jsx-scope": 2 + "react/react-in-jsx-scope": 2, + "indent": [2, 2, {"SwitchCase": 1}], + "no-console": [0], + "func-names": [0], + "semi": [2, "never"], + "no-extra-semi": [2], + "space-before-function-paren": [2, "always"], + "no-else-return": [0] + }, + "globals": { + "__PREFIX_LINKS__": true }, "plugins": [ "react" diff --git a/bin/build.es6 b/bin/build.es6 deleted file mode 100644 index 44dfe7cab7f7e..0000000000000 --- a/bin/build.es6 +++ /dev/null @@ -1,31 +0,0 @@ -import program from 'commander'; -import path from 'path'; - -let packageJson = require('../package.json'); - -// Use compiled version of code when installed globally, otherwise use babel script version. -if ('./published') { - let build = require('../dist/utils/build'); -} else { - let build = require('../lib/utils/build'); -} - -program - .version(packageJson.version) - .option('--prefix-links', 'Build site with links prefixed (set prefix in your config).') - .parse(process.argv); - -let relativeDirectory = program.args[0]; -if (!(typeof relativeDirectory !== "undefined" && relativeDirectory !== null)) { relativeDirectory = "."; } -let directory = path.resolve(relativeDirectory); - -program.directory = directory; -program.relativeDirectory = relativeDirectory; - -build(program, function(err) { - if ((typeof err !== "undefined" && err !== null)) { - throw err; - } else { - return console.log('Done'); - } -}); diff --git a/bin/build.js b/bin/build.js new file mode 100644 index 0000000000000..9f5f1090b91cd --- /dev/null +++ b/bin/build.js @@ -0,0 +1,27 @@ +import program from 'commander' +import path from 'path' + +const packageJson = require('../package.json') + +// Use compiled version of code when installed globally, otherwise use babel script version. +const build = require(('./published.js') ? ('../dist/utils/build') : ('../lib/utils/build')) + +program + .version(packageJson.version) + .option('--prefix-links', 'Build site with links prefixed (set prefix in your config).') + .parse(process.argv) + +let relativeDirectory = program.args[0] +if (!(typeof relativeDirectory !== 'undefined' && relativeDirectory !== null)) { relativeDirectory = '.' } +const directory = path.resolve(relativeDirectory) + +program.directory = directory +program.relativeDirectory = relativeDirectory + +build(program, function (err) { + if ((typeof err !== 'undefined' && err !== null)) { + throw err + } else { + return console.log('Done') + } +}) diff --git a/bin/cli.js b/bin/cli.js index 1bed8571c45e0..3b5c2086a3b00 100755 --- a/bin/cli.js +++ b/bin/cli.js @@ -1,3 +1,3 @@ #!/usr/bin/env node -require('./index.es6'); +require('./index') diff --git a/bin/develop.es6 b/bin/develop.es6 deleted file mode 100644 index 9b482e01a48ad..0000000000000 --- a/bin/develop.es6 +++ /dev/null @@ -1,26 +0,0 @@ -import program from 'commander'; -import path from 'path'; - -import packageJson from '../package.json'; - -// Use compiled version of code when installed globally, otherwise use babel script version. -if ('./published') { - var develop = require('../dist/utils/develop'); -} else { - var develop = require('../lib/utils/develop'); -} - -program - .version(packageJson.version) - .option('-h, --host ', 'Set host. Defaults to 0.0.0.0', "0.0.0.0") - .option('-p, --port ', 'Set port. Defaults to 8000', "8000") - .parse(process.argv); - -var relativeDirectory = program.args[0]; -if (!(typeof relativeDirectory !== "undefined" && relativeDirectory !== null)) { relativeDirectory = "."; } -var directory = path.resolve(relativeDirectory); - -program.directory = directory; -program.relativeDirectory = relativeDirectory; - -develop(program); diff --git a/bin/develop.js b/bin/develop.js new file mode 100644 index 0000000000000..beb43c2b2879e --- /dev/null +++ b/bin/develop.js @@ -0,0 +1,22 @@ +import program from 'commander' +import path from 'path' + +import packageJson from '../package.json' + +// Use compiled version of code when installed globally, otherwise use babel script version. +const develop = require(('./published.js') ? ('../dist/utils/develop') : ('../lib/utils/develop')) + +program + .version(packageJson.version) + .option('-h, --host ', 'Set host. Defaults to 0.0.0.0', '0.0.0.0') + .option('-p, --port ', 'Set port. Defaults to 8000', '8000') + .parse(process.argv) + +let relativeDirectory = program.args[0] +if (!(typeof relativeDirectory !== 'undefined' && relativeDirectory !== null)) { relativeDirectory = '.' } +const directory = path.resolve(relativeDirectory) + +program.directory = directory +program.relativeDirectory = relativeDirectory + +develop(program) diff --git a/bin/gatsby-build.js b/bin/gatsby-build.js index f4fdc9cff7de2..5d55cc92b2192 100755 --- a/bin/gatsby-build.js +++ b/bin/gatsby-build.js @@ -1,4 +1,4 @@ #!/usr/bin/env node -require('babel-register'); -require('./build'); +require('babel-register') +require('./build') diff --git a/bin/gatsby-develop.js b/bin/gatsby-develop.js index 58cf8996f2bb5..cc5273c9430c7 100755 --- a/bin/gatsby-develop.js +++ b/bin/gatsby-develop.js @@ -1,4 +1,4 @@ #!/usr/bin/env node -require('babel-register'); -require('./develop'); +require('babel-register') +require('./develop') diff --git a/bin/gatsby-new.js b/bin/gatsby-new.js index 5f9dc5f0a0bf9..d93efe2ab44ff 100755 --- a/bin/gatsby-new.js +++ b/bin/gatsby-new.js @@ -1,4 +1,4 @@ #!/usr/bin/env node -require('babel-register'); -require('./new'); +require('babel-register') +require('./new') diff --git a/bin/index.es6 b/bin/index.es6 deleted file mode 100644 index 1585ef8be0b07..0000000000000 --- a/bin/index.es6 +++ /dev/null @@ -1,11 +0,0 @@ -var program = require('commander'); -var path = require('path'); - -var packageJson = require('../package.json'); - -program - .version(packageJson.version) - .command('develop [directory]', 'Start hot-reloading development server') - .command('build [directory]', 'Do a production build of site') - .command('new [rootPath] [starter]', 'Create new Gatsby project in path [.].') - .parse(process.argv); diff --git a/bin/index.js b/bin/index.js new file mode 100644 index 0000000000000..e0f3d4110d937 --- /dev/null +++ b/bin/index.js @@ -0,0 +1,10 @@ +const program = require('commander') + +const packageJson = require('../package.json') + +program + .version(packageJson.version) + .command('develop [directory]', 'Start hot-reloading development server') + .command('build [directory]', 'Do a production build of site') + .command('new [rootPath] [starter]', 'Create new Gatsby project in path [.].') + .parse(process.argv) diff --git a/bin/new.es6 b/bin/new.es6 deleted file mode 100644 index 10589fb0c89eb..0000000000000 --- a/bin/new.es6 +++ /dev/null @@ -1,33 +0,0 @@ -var program = require('commander'); -var loggy = require('loggy'); - -var packageJson = require('../package.json'); - -// Use compiled version of code when installed globally, otherwise use babelscript version. -if (require('./published')) { -var initStarter = require('../dist/utils/init-starter'); -} else { - initStarter = require('../lib/utils/init-starter'); -} - -program - .version(packageJson.version) - .parse(process.argv); - -if (program.args.length === 1) { - var rootPath = program.args[0]; - var starter = "gh:gatsbyjs/gatsby-starter-default"; -} else { - rootPath = program.args[0]; - starter = program.args[1]; -} - -initStarter( starter, { - rootPath: rootPath, - logger: loggy - }, function(error) { - if (error) { - return loggy.error(error); - } - } -); diff --git a/bin/new.js b/bin/new.js new file mode 100644 index 0000000000000..f9b1dffdd119b --- /dev/null +++ b/bin/new.js @@ -0,0 +1,23 @@ +const program = require('commander') +const loggy = require('loggy') + +const packageJson = require('../package.json') + +// Use compiled version of code when installed globally, otherwise use babelscript version. +const initStarter = require(('./published.js') ? ('../dist/utils/init-starter') : ('../lib/utils/init-starter')) + +program + .version(packageJson.version) + .parse(process.argv) + +const rootPath = program.args[0] +const starter = ((program.args.length === 1) ? ('gh:gatsbyjs/gatsby-starter-default') : (program.args[1])) + +initStarter(starter, { + rootPath, + logger: loggy, +}, function (error) { + if (error) { + return loggy.error(error) + } +}) diff --git a/lib/isomorphic/HTML.jsx b/lib/isomorphic/HTML.js similarity index 66% rename from lib/isomorphic/HTML.jsx rename to lib/isomorphic/HTML.js index bc021dc9e187f..64fe551945a3d 100644 --- a/lib/isomorphic/HTML.jsx +++ b/lib/isomorphic/HTML.js @@ -1,23 +1,25 @@ -import React, {PropTypes} from 'react'; -import Typography from 'typography'; +'use strict' -const TypographyStyle = new Typography().TypographyStyle; +import React, { PropTypes } from 'react' +import Typography from 'typography' + +const TypographyStyle = new Typography().TypographyStyle module.exports = React.createClass({ propTypes: { title: PropTypes.string, body: PropTypes.string, - favicon: PropTypes.string + favicon: PropTypes.string, }, - getDefaultProps: function () { + getDefaultProps () { return { title: 'Default title', - body: '' + body: '', } }, - render: function () { + render () { return ( @@ -27,15 +29,15 @@ module.exports = React.createClass({ {this.props.title} - + -