diff --git a/.gitignore b/.gitignore index 0c27466276cbe..6f6a4bb3d9dfd 100644 --- a/.gitignore +++ b/.gitignore @@ -38,4 +38,4 @@ test/**/public .DS_Store public/ node_modules/ -.intermediate-representation/ +.cache/ diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000000000..ab9ba0dfe8a6d --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,6 @@ +// Place your settings in this file to overwrite the default settings +{ + "prettier.semi": false, + "prettier.trailingComma": "es5", + "editor.formatOnSave": true +} \ No newline at end of file diff --git a/docs/docs/gatsby-on-windows.md b/docs/docs/gatsby-on-windows.md index 29c6e3e8cb1a4..59832e4051475 100644 --- a/docs/docs/gatsby-on-windows.md +++ b/docs/docs/gatsby-on-windows.md @@ -16,3 +16,7 @@ powershell console. On installing this package, it downloads and installs the Visual C++ Build Tools 2015, provided free of charge by Microsoft. These tools are required to compile popular native modules. It will also install Python 2.7, configuring your machine and npm appropriately. + +## Installing dependencies without troubles. + +Run `yarn` or `npm i` in **a powershell console** to have a correct build (some issues with sharp and sqlite3 with a bash console) \ No newline at end of file diff --git a/examples/gatsbygram/.gitignore b/examples/gatsbygram/.gitignore index 272c9e484faa8..8f5b35a4a9cbc 100644 --- a/examples/gatsbygram/.gitignore +++ b/examples/gatsbygram/.gitignore @@ -1,3 +1,3 @@ public -.intermediate-representation +.cache node_modules diff --git a/examples/gatsbygram/gatsby-node.js b/examples/gatsbygram/gatsby-node.js index bf01d7d06563e..d9548cf0b6389 100644 --- a/examples/gatsbygram/gatsby-node.js +++ b/examples/gatsbygram/gatsby-node.js @@ -41,7 +41,7 @@ exports.createPages = ({ graphql, actionCreators }) => { } // Create image post pages. - const postTemplate = path.resolve(`templates/post-page.js`) + const postTemplate = path.resolve(`src/templates/post-page.js`) // We want to create a detailed page for each // Instagram post. Since the scrapped Instagram data // already includes an ID field, we just use that for diff --git a/examples/gatsbygram/components/modal.js b/examples/gatsbygram/src/components/modal.js similarity index 100% rename from examples/gatsbygram/components/modal.js rename to examples/gatsbygram/src/components/modal.js diff --git a/examples/gatsbygram/components/post-detail.js b/examples/gatsbygram/src/components/post-detail.js similarity index 100% rename from examples/gatsbygram/components/post-detail.js rename to examples/gatsbygram/src/components/post-detail.js diff --git a/examples/gatsbygram/components/post.js b/examples/gatsbygram/src/components/post.js similarity index 100% rename from examples/gatsbygram/components/post.js rename to examples/gatsbygram/src/components/post.js diff --git a/examples/gatsbygram/html.js b/examples/gatsbygram/src/html.js similarity index 93% rename from examples/gatsbygram/html.js rename to examples/gatsbygram/src/html.js index 5134c92af0cf4..717b326adc20c 100644 --- a/examples/gatsbygram/html.js +++ b/examples/gatsbygram/src/html.js @@ -4,12 +4,12 @@ import DocumentTitle from "react-document-title" //import { prefixLink } from 'gatsby-helpers' import { GoogleFont, TypographyStyle } from "react-typography" import typography from "./utils/typography" -import logo from "!file-loader!./images/logo.png" +import logo from "!file-loader!../static/images/logo.png" let stylesStr if (process.env.NODE_ENV === `production`) { try { - stylesStr = require("!raw-loader!./public/styles.css") + stylesStr = require("!raw-loader!../public/styles.css") } catch (e) { console.log(e) } diff --git a/examples/gatsbygram/layouts/default.js b/examples/gatsbygram/src/layouts/default.js similarity index 100% rename from examples/gatsbygram/layouts/default.js rename to examples/gatsbygram/src/layouts/default.js diff --git a/examples/gatsbygram/pages/about.js b/examples/gatsbygram/src/pages/about.js similarity index 100% rename from examples/gatsbygram/pages/about.js rename to examples/gatsbygram/src/pages/about.js diff --git a/examples/gatsbygram/pages/index.js b/examples/gatsbygram/src/pages/index.js similarity index 100% rename from examples/gatsbygram/pages/index.js rename to examples/gatsbygram/src/pages/index.js diff --git a/examples/gatsbygram/templates/post-page.js b/examples/gatsbygram/src/templates/post-page.js similarity index 100% rename from examples/gatsbygram/templates/post-page.js rename to examples/gatsbygram/src/templates/post-page.js diff --git a/examples/gatsbygram/utils/presets.js b/examples/gatsbygram/src/utils/presets.js similarity index 100% rename from examples/gatsbygram/utils/presets.js rename to examples/gatsbygram/src/utils/presets.js diff --git a/examples/gatsbygram/utils/typography.js b/examples/gatsbygram/src/utils/typography.js similarity index 100% rename from examples/gatsbygram/utils/typography.js rename to examples/gatsbygram/src/utils/typography.js diff --git a/examples/gatsbygram/images/logo.png b/examples/gatsbygram/static/images/logo.png similarity index 100% rename from examples/gatsbygram/images/logo.png rename to examples/gatsbygram/static/images/logo.png diff --git a/packages/gatsby-dev-cli/README.md b/packages/gatsby-dev-cli/README.md index d8d1951e9f21d..5a731efad7f10 100644 --- a/packages/gatsby-dev-cli/README.md +++ b/packages/gatsby-dev-cli/README.md @@ -9,7 +9,7 @@ It's a simple cli tool for have easily a functionnal development environment for Fork gatsby repo and clone it. ```bash -$ npm install -g gatsby-cli-tools@canary +$ npm install -g gatsby-dev-cli@canary $ gatsby-dev --set-path-to-repo /path/to/my/cloned/version/gatsby ``` diff --git a/packages/gatsby-link/README.md b/packages/gatsby-link/README.md index 151102582e994..55c6f4e0b057f 100644 --- a/packages/gatsby-link/README.md +++ b/packages/gatsby-link/README.md @@ -21,8 +21,9 @@ Edge), this component will also preload code chunks on these browsers. ## How to use +In javascript: ```jsx -const Link = require('gatsby-link') +import Link from "gatsby-link" render () {
@@ -31,6 +32,9 @@ render () { activeStyle={{ color: 'red' }} + > + Another page +
} ``` diff --git a/packages/gatsby-link/index.d.ts b/packages/gatsby-link/index.d.ts new file mode 100644 index 0000000000000..ae25bb66da1de --- /dev/null +++ b/packages/gatsby-link/index.d.ts @@ -0,0 +1,7 @@ +import { ClassicComponentClass } from "react"; +import { LinkProps } from "react-router"; + +type GatsbyLink = ClassicComponentClass; +declare const GatsbyLink: GatsbyLink; + +export = GatsbyLink; \ No newline at end of file diff --git a/packages/gatsby-link/package.json b/packages/gatsby-link/package.json index 19080e3508cc9..7e4f4851b444e 100644 --- a/packages/gatsby-link/package.json +++ b/packages/gatsby-link/package.json @@ -3,6 +3,7 @@ "version": "1.0.0-alpha12", "description": "An enhanced Link component for Gatsby sites with support for resource prefetching", "main": "index.js", + "types": "index.d.ts", "scripts": { "build": "babel src --out-dir .", "watch": "babel -w src --out-dir ." @@ -15,5 +16,8 @@ "license": "MIT", "devDependencies": { "babel-cli": "^6.18.0" + }, + "dependencies": { + "@types/react-router": "^2.0.49" } } diff --git a/packages/gatsby-plugin-typescript/README.md b/packages/gatsby-plugin-typescript/README.md index 4097f06ff68c6..00cce0c5e1e9e 100644 --- a/packages/gatsby-plugin-typescript/README.md +++ b/packages/gatsby-plugin-typescript/README.md @@ -2,7 +2,7 @@ Provides drop-in support for TypeScript and TSX. ## Install -`yarn add gatsby-plugin-typescript` +`yarn add gatsby-plugin-typescript ts-loader typescript` ## How to use 1. Include the plugin in your `gatsby-config.js` file. diff --git a/packages/gatsby-plugin-typescript/tsconfig.json b/packages/gatsby-plugin-typescript/tsconfig.json deleted file mode 100644 index ee1eeb25cd004..0000000000000 --- a/packages/gatsby-plugin-typescript/tsconfig.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "compilerOptions": { - "target": "es6", - "module": "commonjs", - "rootDir": "src", - "outDir": "./" - }, - "files": [ - "src/gatsby-node.ts", - "src/index.ts" - ] -} \ No newline at end of file diff --git a/packages/gatsby-source-filesystem/src/gatsby-node.js b/packages/gatsby-source-filesystem/src/gatsby-node.js index 2d5e76455a939..2e5a2a7edcf11 100644 --- a/packages/gatsby-source-filesystem/src/gatsby-node.js +++ b/packages/gatsby-source-filesystem/src/gatsby-node.js @@ -1,14 +1,8 @@ -import Promise from "bluebird" -import mapLimit from "async/mapLimit" - const path = require("path") const md5File = require("md5-file") -const recursive = require("recursive-readdir") const fs = require("fs") const prettyBytes = require("pretty-bytes") -const u = require("unist-builder") const slash = require("slash") -const _ = require("lodash") const chokidar = require("chokidar") function readFile(file, pluginOptions, cb) { @@ -27,7 +21,7 @@ function readFile(file, pluginOptions, cb) { sourceName: pluginOptions.name, children: [], relativePath: slash( - path.posix.relative(pluginOptions.path, slashedFile.absolutePath) + path.relative(pluginOptions.path, slashedFile.absolutePath) ), extension: slashedFile.ext.slice(1).toLowerCase(), size: stats.size, @@ -52,7 +46,6 @@ exports.sourceNodes = ({ actionCreators }, pluginOptions) => { plugin: `source-filesystem --- ${pluginOptions.name}`, ready: false, }) - let testNode const watcher = chokidar.watch(pluginOptions.path, { ignored: [ `**/*.un~`, diff --git a/packages/gatsby/lib/bootstrap/index.js b/packages/gatsby/lib/bootstrap/index.js index 49584002da48d..c52c99b897c4d 100644 --- a/packages/gatsby/lib/bootstrap/index.js +++ b/packages/gatsby/lib/bootstrap/index.js @@ -7,11 +7,8 @@ import _ from "lodash" import slash from "slash" import createPath from "./create-path" import fs from "fs-extra" -import Joi from "joi" -import chalk from "chalk" import apiRunnerNode from "../utils/api-runner-node" import { graphql } from "graphql" -import { layoutComponentChunkName } from "../utils/js-chunk-names" import { store } from "../redux" const { boundActionCreators } = require("../redux/actions") @@ -33,7 +30,6 @@ const preferDefault = m => (m && m.default) || m const mkdirs = Promise.promisify(fs.mkdirs) const copy = Promise.promisify(fs.copy) -const removeDir = Promise.promisify(fs.remove) const glob = Promise.promisify(globCB) // Path creator. @@ -41,8 +37,9 @@ const glob = Promise.promisify(globCB) // algorithm is glob /pages directory for js/jsx/cjsx files *not* // underscored. Then create url w/ our path algorithm *unless* user // takes control of that page component in gatsby-node. -const autoPathCreator = async (program: any) => { - const pagesDirectory = path.posix.join(program.directory, `pages`) +const autoPathCreator = async () => { + const { program } = store.getState() + const pagesDirectory = path.posix.join(program.directory, `/src/pages`) const exts = program.extensions.map(e => `*${e}`).join("|") // The promisified version wasn't working for some reason // so we'll use sync for now. @@ -92,15 +89,13 @@ module.exports = async (program: any) => { console.time(`open and validate gatsby-config.js`) let config = {} try { - config = require(`${program.directory}/gatsby-config`) + config = preferDefault(require(`${program.directory}/gatsby-config`)) } catch (e) { console.log(`Couldn't open your gatsby-config.js file`) console.log(e) process.exit() } - config = preferDefault(config) - store.dispatch({ type: "SET_SITE_CONFIG", payload: config, @@ -115,7 +110,7 @@ module.exports = async (program: any) => { // Also test adding to redux store. const processPlugin = plugin => { if (_.isString(plugin)) { - const resolvedPath = path.dirname(require.resolve(plugin)) + const resolvedPath = slash(path.dirname(require.resolve(plugin))) const packageJSON = JSON.parse( fs.readFileSync(`${resolvedPath}/package.json`, `utf-8`) ) @@ -137,7 +132,7 @@ module.exports = async (program: any) => { } plugin.options.plugins = subplugins - const resolvedPath = path.dirname(require.resolve(plugin.resolve)) + const resolvedPath = slash(path.dirname(require.resolve(plugin.resolve))) const packageJSON = JSON.parse( fs.readFileSync(`${resolvedPath}/package.json`, `utf-8`) ) @@ -158,7 +153,7 @@ module.exports = async (program: any) => { // Add the site's default "plugin" i.e. gatsby-x files in root of site. plugins.push({ - resolve: process.cwd(), + resolve: slash(process.cwd()), name: `defaultSitePlugin`, version: `n/a`, pluginOptions: { @@ -196,14 +191,14 @@ module.exports = async (program: any) => { // Copy our site files to the root of the site. console.time(`copy gatsby files`) - const srcDir = `${__dirname}/../intermediate-representation-dir` - const siteDir = `${program.directory}/.intermediate-representation` + const srcDir = `${__dirname}/../cache-dir` + const siteDir = `${program.directory}/.cache` try { // await removeDir(siteDir) await copy(srcDir, siteDir, { clobber: true }) - await mkdirs(`${program.directory}/.intermediate-representation/json`) + await mkdirs(`${program.directory}/.cache/json`) } catch (e) { - console.log(`Unable to copy site files to .intermediate-representation`) + console.log(`Unable to copy site files to .cache`) console.log(e) } @@ -272,10 +267,13 @@ module.exports = async (program: any) => { } // Collect resolvable extensions and attach to program. - // TODO refactor this to use Redux. const extensions = [`.js`, `.jsx`] const apiResults = await apiRunnerNode("resolvableExtensions") - program.extensions = apiResults.reduce((a, b) => a.concat(b), extensions) + + store.dispatch({ + type: "SET_PROGRAM_EXTENSIONS", + payload: _.flattenDeep([extensions, apiResults]), + }) // Collect pages. await apiRunnerNode(`createPages`, { @@ -285,7 +283,7 @@ module.exports = async (program: any) => { // TODO move this to own source plugin per component type // (js/cjsx/typescript, etc.). Only do after there's themes // so can cement default /pages setup in default core theme. - autoPathCreator(program) + autoPathCreator() // Copy /404/ to /404.html as many static site hosting companies expect // site 404 pages to be named this. diff --git a/packages/gatsby/lib/intermediate-representation-dir/api-runner-browser.js b/packages/gatsby/lib/cache-dir/api-runner-browser.js similarity index 100% rename from packages/gatsby/lib/intermediate-representation-dir/api-runner-browser.js rename to packages/gatsby/lib/cache-dir/api-runner-browser.js diff --git a/packages/gatsby/lib/intermediate-representation-dir/api-runner-ssr.js b/packages/gatsby/lib/cache-dir/api-runner-ssr.js similarity index 100% rename from packages/gatsby/lib/intermediate-representation-dir/api-runner-ssr.js rename to packages/gatsby/lib/cache-dir/api-runner-ssr.js diff --git a/packages/gatsby/lib/intermediate-representation-dir/app.js b/packages/gatsby/lib/cache-dir/app.js similarity index 100% rename from packages/gatsby/lib/intermediate-representation-dir/app.js rename to packages/gatsby/lib/cache-dir/app.js diff --git a/packages/gatsby/lib/intermediate-representation-dir/json/.gitignore b/packages/gatsby/lib/cache-dir/json/.gitignore similarity index 100% rename from packages/gatsby/lib/intermediate-representation-dir/json/.gitignore rename to packages/gatsby/lib/cache-dir/json/.gitignore diff --git a/packages/gatsby/lib/intermediate-representation-dir/json/nothing b/packages/gatsby/lib/cache-dir/json/nothing similarity index 100% rename from packages/gatsby/lib/intermediate-representation-dir/json/nothing rename to packages/gatsby/lib/cache-dir/json/nothing diff --git a/packages/gatsby/lib/intermediate-representation-dir/production-app.js b/packages/gatsby/lib/cache-dir/production-app.js similarity index 100% rename from packages/gatsby/lib/intermediate-representation-dir/production-app.js rename to packages/gatsby/lib/cache-dir/production-app.js diff --git a/packages/gatsby/lib/intermediate-representation-dir/root.js b/packages/gatsby/lib/cache-dir/root.js similarity index 100% rename from packages/gatsby/lib/intermediate-representation-dir/root.js rename to packages/gatsby/lib/cache-dir/root.js diff --git a/packages/gatsby/lib/intermediate-representation-dir/static-entry.js b/packages/gatsby/lib/cache-dir/static-entry.js similarity index 84% rename from packages/gatsby/lib/intermediate-representation-dir/static-entry.js rename to packages/gatsby/lib/cache-dir/static-entry.js index 21e3b2a77f9e9..b9b983133ffc5 100644 --- a/packages/gatsby/lib/intermediate-representation-dir/static-entry.js +++ b/packages/gatsby/lib/cache-dir/static-entry.js @@ -2,15 +2,13 @@ import React from "react" import { renderToString, renderToStaticMarkup } from "react-dom/server" import { match, RouterContext } from "react-router" import Html from "html" -import _ from "lodash" -//import { prefixLink } from '../isomorphic/gatsby-helpers' -import rootRoute from ".intermediate-representation/child-routes.js" -import pages from "public/tmp-pages.json" -//import { pathChunkName } from './js-chunk-names' -import apiRunner from ".intermediate-representation/api-runner-ssr" +import { kebabCase, get, merge } from "lodash" +import rootRoute from "./child-routes" +import apiRunner from "./api-runner-ssr" +import pages from "../public/tmp-pages.json" const pathChunkName = path => { - const name = path === `/` ? `index` : _.kebabCase(path) + const name = path === `/` ? `index` : kebabCase(path) return `path---${name}` } @@ -59,7 +57,7 @@ module.exports = (locals, callback) => { } // Add the chunk-manifest as a head component. - const chunkManifest = require("!raw!public/chunk-manifest.json") + const chunkManifest = require("!raw!../public/chunk-manifest.json") postBodyComponents.unshift(