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

Conversation

fabien0102
Copy link
Contributor

@fabien0102 fabien0102 commented Apr 14, 2017

Since I'm working on my starter with typescript (not working for instant, but I progress) I made some refactors and improvements:

  • Use redux for program.extensions
  • Fix some path on windows (I finded new one in the redux dev tool XD)
  • Some refactors like use const {program, config} = store.getState() to improve readability
  • Add a warn for install packages on windows (my mystery with sharp build resolve)

[Update] Finally, we decide to change directory structure to: (#814 (comment))

├── .cache // Stuff gets cached here. Shouldn't be under source control.
├── README.md
├── data // dump images, json, csv, yaml, etc. here.
├── gatsby-config.js
├── gatsby-node.js
├── plugins // Additional site-specific plugins
├── src // Everything related to the frontend goes here.
│   ├── components
│   │   └── header.js
|   ├── css
│         └── prism-coy.css
│   ├── html.js
│   ├── layouts
│   │   └── index.js
│   ├── pages
│   ├── templates
│   │   └── blog-post.js
│   └── utils
│       └── typography.js
├── static // Everything in this directory gets copied directly into public
├── public // Output directory

@gatsbybot
Copy link
Collaborator

gatsbybot commented Apr 14, 2017

Deploy preview ready!

Built with commit 04a8508

https://deploy-preview-802--gatsbyjs.netlify.com

@gatsbybot
Copy link
Collaborator

gatsbybot commented Apr 14, 2017

Deploy preview ready!

Built with commit 04a8508

https://deploy-preview-802--gatsbygram.netlify.com

Copy link
Contributor

@KyleAMathews KyleAMathews left a comment

Choose a reason for hiding this comment

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

Hey! Another great PR. Love refactoring page extensions to use Redux plus the other small fixes.

Let's not allow people to change the rootPath. First webpack/babel sometimes have trouble if they're processing files that are in different file directories. Second it seems to be a pointless option. What benefit is there to being able to change the root directory? A general rule for products is avoid all options unless they're absolutely necessary and I don't see setting rootPath to be absolutely necessary.


## Installing dependencies without troubles.

Even if you love using a pretty terminal as [hyper](https://hyper.is/) with a git bash,
Copy link
Contributor

Choose a reason for hiding this comment

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

no need to mention hyper here... Hyper is great but it's irrelevant to using Gatsby. My preferred "voice" for documentation is a "helpful, focused, and neutral".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok ;) It's noted, I will correct this

@fabien0102
Copy link
Contributor Author

I understand your point with rootPath, personnaly I don't like to my mixed sources files and my build tools (old habits). You can have a look on https://github.com/fabien0102/gatsby-starter to see my files structures (I got the folder templates that I don't want to mix with my sources file), this rootPath just move the html.* and layouts/default.* so I don't really see the issue with webpack/babel… (maybe rootPath it's not the correct name for this option, I try many names, maybe it's will be better with htmlPath and LayoutsPath ?)

So three options:

  1. I remove this rootPath and mixed my sources file
  2. I split rootPath into htmlPath and LayoutsPath
  3. I keep this like this
  4. Another proposition? (I know, I said 3 options)

@@ -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?

</div>
}
```

In typescript:
Copy link
Contributor

Choose a reason for hiding this comment

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

This Typescript example is superfluous. It's 95% identical to the JS one and anyone writing Typescript would know how to translate the JS example to Typescript.

I can see value in maintaining code samples in different languages in the future but if we do, we'd want to put them in a toggleable interface so it's hiding the languages you're not interested in.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No problem, it was just a proposition ;)

@KyleAMathews
Copy link
Contributor

The problem isn't with moving js files into a deeper directory—it's if you move it out of the file tree into a different file tree e.g. the path to html.js from the root is ../src-dir/html.js. That's when Babel/webpack fritz.

I'll think more about the idea of letting people move their files into a deeper directory ala your src directory. That could work fine.

@fabien0102
Copy link
Contributor Author

image
I got a last issue on the build process and I will add some validation on the rootPath option to avoid the case of ../src-dir (typescript really don't like when all my files are on the root…)

@fabien0102
Copy link
Contributor Author

fabien0102 commented Apr 17, 2017

All is working!

My test list:

  • www/ develop
  • www/ build
  • gatsbygram with sources into /src develop
  • gatsbygram with sources into /src build

[Edit] Arf my typescript starter as a last conflict between tsconfig/webpack but it's works for others projects without typescript ^^

@@ -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 ^^

@@ -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.

@fabien0102 fabien0102 changed the title [1.0] Optional rootPath & some refactors [1.0] Change directory structure Apr 18, 2017
@fabien0102 fabien0102 changed the title [1.0] Change directory structure [1.0] [WIP] Change directory structure Apr 18, 2017
@fabien0102 fabien0102 changed the title [1.0] [WIP] Change directory structure [1.0] Change directory structure Apr 18, 2017
@fabien0102 fabien0102 mentioned this pull request Apr 18, 2017
8 tasks
// Then in the special directory of isomorphic modules Gatsby ships with.
root: [directory, path.resolve(__dirname, `..`, `isomorphic`)],
root: [
Copy link
Contributor

Choose a reason for hiding this comment

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

Please revert this. I don't want multiple roots as in practice this is quite confusing. Just src should be a root now.

Copy link
Contributor

Choose a reason for hiding this comment

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

Actually I'll just merge this and then make the change.

@KyleAMathews KyleAMathews merged commit 718e22a into gatsbyjs:1.0 Apr 18, 2017
@KyleAMathews
Copy link
Contributor

And thanks again for all the work here! Really nice PR!

@fabien0102 fabien0102 deleted the 1.0-typescript-support branch April 19, 2017 11:13
mwfrost pushed a commit to mwfrost/gatsby that referenced this pull request Apr 20, 2023
* Add a note on windows installation

* Add missing dependencies into gatsby-plugin-typescript doc

* Make HTMLPath configurable

* Fix dev-cli readme

* Use redux to managed program.extensions

* Slashify all paths

* Fix relativePath and clean no-used var

* Get program.extensions from redux

* Add a rootPath config

* Some refactors

* Run yarn format

* Deal with config.rootPath for default layout

* Fix bad rebase

* Fix documention style

* Add typescript definition for gatsby-link

* Remove superfluous typescript example

* Add vscode config to execute prettier on save

More info: https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode

* Imprive joi validation on rootPath

* Remove useless tsconfig.json

* Remove unused var

* Use program from redux

* Improve rootPath config (default config and regex validator)

* Ensure schema is created even if the project hasn't got any source plugin

Fix gatsbyjs#811

* Find a webpack config that deals with all env \o/

This configuration works with basics configuration and with a custom `rootPath` (even with a typescript stack)

It was tested with build and develop commands

* Move default config into redux

* Take english version to vscode/settings comment

* Add some unit-test for `rootPath`

* Make `src` as default rootPath

* Rename `intermediate-representation` to `cache`

* Add `public` into webpack root entries

* Ignore .cache folders

* Refactor `www` project with the new file directory

* Refactor gatsbygram project with the new file directory
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants