Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

[1.0] Change directory structure #802

Merged
merged 35 commits into from
Apr 18, 2017
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
ad3e387
Add a note on windows installation
fabien0102 Apr 12, 2017
9834943
Add missing dependencies into gatsby-plugin-typescript doc
fabien0102 Apr 12, 2017
e3c4245
Make HTMLPath configurable
fabien0102 Apr 13, 2017
1f999dd
Fix dev-cli readme
fabien0102 Apr 13, 2017
f45a455
Use redux to managed program.extensions
fabien0102 Apr 13, 2017
abb0351
Slashify all paths
fabien0102 Apr 14, 2017
3af80ea
Fix relativePath and clean no-used var
fabien0102 Apr 14, 2017
240f5da
Get program.extensions from redux
fabien0102 Apr 14, 2017
72e706f
Add a rootPath config
fabien0102 Apr 14, 2017
d73cda5
Some refactors
fabien0102 Apr 14, 2017
871d31c
Run yarn format
fabien0102 Apr 14, 2017
0c71ab9
Deal with config.rootPath for default layout
fabien0102 Apr 14, 2017
2de4528
Fix bad rebase
fabien0102 Apr 14, 2017
f4b80ed
Fix documention style
fabien0102 Apr 15, 2017
186ed2b
Merge remote-tracking branch 'upstream/1.0' into 1.0-typescript-support
fabien0102 Apr 15, 2017
c8ee94b
Add typescript definition for gatsby-link
fabien0102 Apr 15, 2017
d3c99a3
Remove superfluous typescript example
fabien0102 Apr 15, 2017
5501d78
Add vscode config to execute prettier on save
fabien0102 Apr 15, 2017
55d14b8
Imprive joi validation on rootPath
fabien0102 Apr 15, 2017
e85fe81
Remove useless tsconfig.json
fabien0102 Apr 16, 2017
3d3ce81
Remove unused var
fabien0102 Apr 17, 2017
7c58180
Use program from redux
fabien0102 Apr 17, 2017
d232690
Improve rootPath config (default config and regex validator)
fabien0102 Apr 17, 2017
7d1f719
Ensure schema is created even if the project hasn't got any source pl…
fabien0102 Apr 17, 2017
9886ac0
Find a webpack config that deals with all env \o/
fabien0102 Apr 17, 2017
297100e
Move default config into redux
fabien0102 Apr 17, 2017
3df19af
Take english version to vscode/settings comment
fabien0102 Apr 17, 2017
5c87433
Merge remote-tracking branch 'upstream/1.0' into 1.0-typescript-support
fabien0102 Apr 17, 2017
c913534
Add some unit-test for `rootPath`
fabien0102 Apr 17, 2017
b3dd006
Make `src` as default rootPath
fabien0102 Apr 18, 2017
ad073ef
Rename `intermediate-representation` to `cache`
fabien0102 Apr 18, 2017
e43b022
Add `public` into webpack root entries
fabien0102 Apr 18, 2017
46c6b0f
Ignore .cache folders
fabien0102 Apr 18, 2017
9aad264
Refactor `www` project with the new file directory
fabien0102 Apr 18, 2017
04a8508
Refactor gatsbygram project with the new file directory
fabien0102 Apr 18, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Placez vos paramètres dans ce fichier pour remplacer les paramètres par défaut et les paramètres utilisateur.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's stick with english here :-)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Daim! It's the auto-comment of my editor ^^

{
"prettier.semi": false,
"prettier.trailingComma": "es5",
"editor.formatOnSave": true
}
4 changes: 4 additions & 0 deletions docs/docs/gatsby-on-windows.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there some pages discussing this issue that you can link to?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just my personal experience for instant, but I can search ;)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this is what you need to do to get Hyper setup vercel/hyper#946 (comment)

Perhaps just add this to the instructions instead of this section?


Run `yarn` or `npm i` in **a powershell console** to have a correct build (some issues with sharp and sqlite3 with a bash console)
2 changes: 1 addition & 1 deletion packages/gatsby-dev-cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```

Expand Down
6 changes: 5 additions & 1 deletion packages/gatsby-link/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
<div>
Expand All @@ -31,6 +32,9 @@ render () {
activeStyle={{
color: 'red'
}}
>
Another page
</Link>
</div>
}
```
7 changes: 7 additions & 0 deletions packages/gatsby-link/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { ClassicComponentClass } from "react";
import { LinkProps } from "react-router";

type GatsbyLink = ClassicComponentClass<LinkProps>;
declare const GatsbyLink: GatsbyLink;

export = GatsbyLink;
4 changes: 4 additions & 0 deletions packages/gatsby-link/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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 ."
Expand All @@ -15,5 +16,8 @@
"license": "MIT",
"devDependencies": {
"babel-cli": "^6.18.0"
},
"dependencies": {
"@types/react-router": "^2.0.49"
}
}
2 changes: 1 addition & 1 deletion packages/gatsby-plugin-typescript/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
12 changes: 0 additions & 12 deletions packages/gatsby-plugin-typescript/tsconfig.json

This file was deleted.

9 changes: 1 addition & 8 deletions packages/gatsby-source-filesystem/src/gatsby-node.js
Original file line number Diff line number Diff line change
@@ -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) {
Expand All @@ -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,
Expand All @@ -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~`,
Expand Down
39 changes: 23 additions & 16 deletions packages/gatsby/lib/bootstrap/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand All @@ -33,16 +30,20 @@ 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.
// Auto-create pages.
// 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 { config, program } = store.getState()
const pagesDirectory = path.posix.join(
program.directory,
config.rootPath,
`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.
Expand Down Expand Up @@ -90,17 +91,20 @@ module.exports = async (program: any) => {

// Try opening the site's gatsby-config.js file.
console.time(`open and validate gatsby-config.js`)
let config = {}
let config = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's put defaults in Redux so data processing is centralized there.

rootPath: `/`,
}
try {
config = require(`${program.directory}/gatsby-config`)
Object.assign(
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,
Expand All @@ -115,7 +119,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`)
)
Expand All @@ -137,7 +141,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`)
)
Expand All @@ -158,7 +162,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: {
Expand Down Expand Up @@ -272,10 +276,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`, {
Expand All @@ -285,7 +292,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.
Expand Down
8 changes: 8 additions & 0 deletions packages/gatsby/lib/joi-schemas/joi.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
const Joi = require("joi")

export const gatsbyConfigSchema = Joi.object().keys({
rootPath: Joi.string()
.regex(/(^\/$)|(^\/(?!\.{2}).*\/$)/)
.notes([
`should start with "/"`,
`should finish with "/"`,
`should not have ".." pattern`,
`can be "/" (default)`,
]),
siteMetadata: Joi.object(),
linkPrefix: Joi.string(),
mapping: Joi.object(),
Expand Down
26 changes: 13 additions & 13 deletions packages/gatsby/lib/redux/__tests__/nodes.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { actions, boundActions } = require("../actions");
const nodeReducer = require("../reducers/nodes");
const { actions, boundActions } = require("../actions")
const nodeReducer = require("../reducers/nodes")

describe(`Create and update nodes`, () => {
// TODO add these back when we stop directly consoleing errors.
Expand All @@ -23,24 +23,24 @@ describe(`Create and update nodes`, () => {
id: `hi`,
type: `Test`,
pickle: true,
});
expect(action).toMatchSnapshot();
expect(nodeReducer(undefined, action)).toMatchSnapshot();
});
})
expect(action).toMatchSnapshot()
expect(nodeReducer(undefined, action)).toMatchSnapshot()
})

it(`allows updating nodes`, () => {
const action = actions.createNode({
id: `hi`,
type: `Test`,
pickle: true,
});
})
const updateAction = actions.createNode({
id: `hi`,
type: `Test`,
pickle: false,
});
let state = nodeReducer(undefined, action);
state = nodeReducer(state, updateAction);
expect(state["hi"].pickle).toEqual(false);
});
});
})
let state = nodeReducer(undefined, action)
state = nodeReducer(state, updateAction)
expect(state["hi"].pickle).toEqual(false)
})
})
54 changes: 27 additions & 27 deletions packages/gatsby/lib/redux/__tests__/pages.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
const { store, reducer } = require("../index");
const { actions, boundActions } = require("../actions");
const { store, reducer } = require("../index")
const { actions, boundActions } = require("../actions")

describe(`Add pages`, () => {
it(`allows you to add pages`, () => {
const action = actions.upsertPage({
path: `/hi/`,
component: `/whatever/index.js`,
});
const state = reducer({ pages: [] }, action);
expect(action).toMatchSnapshot();
expect(state).toMatchSnapshot();
});
})
const state = reducer({ pages: [] }, action)
expect(action).toMatchSnapshot()
expect(state).toMatchSnapshot()
})

it(`allows you to add pages with context`, () => {
const action = actions.upsertPage({
Expand All @@ -19,42 +19,42 @@ describe(`Add pages`, () => {
context: {
id: 123,
},
});
const state = reducer({ pages: [] }, action);
expect(action).toMatchSnapshot();
expect(state).toMatchSnapshot();
});
})
const state = reducer({ pages: [] }, action)
expect(action).toMatchSnapshot()
expect(state).toMatchSnapshot()
})

it(`allows you to add multiple pages`, () => {
const action = actions.upsertPage({
path: `/hi/`,
component: `/whatever/index.js`,
});
})
const action2 = actions.upsertPage({
path: `/hi/pizza/`,
component: `/whatever/index.js`,
});
let state = reducer({ pages: [] }, action);
state = reducer(state, action2);
expect(state).toMatchSnapshot();
expect(state.pages.length).toEqual(2);
});
})
let state = reducer({ pages: [] }, action)
state = reducer(state, action2)
expect(state).toMatchSnapshot()
expect(state.pages.length).toEqual(2)
})

it(`allows you to update existing pages (based on path)`, () => {
const action = actions.upsertPage({
path: `/hi/`,
component: `/whatever/index.js`,
});
})

// Change the component
const action2 = actions.upsertPage({
path: `/hi/`,
component: `/whatever2/index.js`,
});
})

let state = reducer({ pages: [] }, action);
state = reducer(state, action2);
expect(state).toMatchSnapshot();
expect(state.pages.length).toEqual(1);
});
});
let state = reducer({ pages: [] }, action)
state = reducer(state, action2)
expect(state).toMatchSnapshot()
expect(state.pages.length).toEqual(1)
})
})
Loading