Gatsby cookiecutter template#85
Conversation
hancush
left a comment
There was a problem hiding this comment.
Thanks for this, @beamalsky!
I'm getting an error when I try to build the cookiecutter:
call-me-hank:templates hannah$ docker-compose run --rm cookiecutter -f new-gatsby-app
app_name [my-new-gatsby-app]:
app_verbose_name [My New Gatsby App's Title]:
description [A longer description of my new app]:
Traceback (most recent call last):
File "/usr/local/bin/cookiecutter", line 10, in <module>
sys.exit(main())
File "/usr/local/lib/python3.7/site-packages/click/core.py", line 764, in __call__
return self.main(*args, **kwargs)
File "/usr/local/lib/python3.7/site-packages/click/core.py", line 717, in main
rv = self.invoke(ctx)
File "/usr/local/lib/python3.7/site-packages/click/core.py", line 956, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/usr/local/lib/python3.7/site-packages/click/core.py", line 555, in invoke
return callback(*args, **kwargs)
File "/usr/local/lib/python3.7/site-packages/cookiecutter/cli.py", line 120, in main
password=os.environ.get('COOKIECUTTER_REPO_PASSWORD')
File "/usr/local/lib/python3.7/site-packages/cookiecutter/main.py", line 94, in cookiecutter
output_dir=output_dir
File "/usr/local/lib/python3.7/site-packages/cookiecutter/generate.py", line 364, in generate_files
generate_file(project_dir, infile, context, env)
File "/usr/local/lib/python3.7/site-packages/cookiecutter/generate.py", line 166, in generate_file
tmpl = env.get_template(infile_fwd_slashes)
File "/usr/local/lib/python3.7/site-packages/jinja2/environment.py", line 830, in get_template
return self._load_template(name, self.make_globals(globals))
File "/usr/local/lib/python3.7/site-packages/jinja2/environment.py", line 804, in _load_template
template = self.loader.load(self, name, globals)
File "/usr/local/lib/python3.7/site-packages/jinja2/loaders.py", line 125, in load
code = environment.compile(source, name, filename)
File "/usr/local/lib/python3.7/site-packages/jinja2/environment.py", line 591, in compile
self.handle_exception(exc_info, source_hint=source_hint)
File "/usr/local/lib/python3.7/site-packages/jinja2/environment.py", line 780, in handle_exception
reraise(exc_type, exc_value, tb)
File "/usr/local/lib/python3.7/site-packages/jinja2/_compat.py", line 37, in reraise
raise value.with_traceback(tb)
File "./src/components/layout.js", line 32, in template
File "/usr/local/lib/python3.7/site-packages/jinja2/environment.py", line 497, in _parse
return Parser(self, source, name, encode_filename(filename)).parse()
File "/usr/local/lib/python3.7/site-packages/jinja2/parser.py", line 901, in parse
result = nodes.Template(self.subparse(), lineno=1)
File "/usr/local/lib/python3.7/site-packages/jinja2/parser.py", line 876, in subparse
self.stream.expect('variable_end')
File "/usr/local/lib/python3.7/site-packages/jinja2/lexer.py", line 384, in expect
self.name, self.filename)
jinja2.exceptions.TemplateSyntaxError: expected token 'end of print statement', got ':'
File "./src/components/layout.js", line 32
margin: `0 auto`,
Re: dependencies, how are you installing them? I had a slightly different mount in Stormwater, but I think the important thing is that it matches the work dir, which yours does.
This is what I run: docker-compose run --rm app add ${PACKAGE}
| ENTRYPOINT [ "yarn" ] | ||
| CMD [ "start" ] | ||
|
|
||
| ENTRYPOINT [ "gatsby" ] |
There was a problem hiding this comment.
Docker only recognizes the last entrypoint in the Dockerfile, so the first entrypoint is not being run. What's your intention with your entry points and commands?
There was a problem hiding this comment.
It's the gatsby build! Thanks for the catch
| @@ -0,0 +1,22 @@ | |||
| The MIT License (MIT) | |||
|
|
|||
| Copyright (c) 2015 gatsbyjs | |||
There was a problem hiding this comment.
| Copyright (c) 2015 gatsbyjs | |
| Copyright (c) 2020 DataMade |
|
|
||
| - **To dive straight into code samples, head [to our documentation](https://www.gatsbyjs.org/docs/).** In particular, check out the _Guides_, _API Reference_, and _Advanced Tutorials_ sections in the sidebar. | ||
|
|
||
| ### 💫 TK: Deploy |
There was a problem hiding this comment.
Could we link to our documentation here?
There was a problem hiding this comment.
Yeah! Do you mean our deployment documentation specifically?
There was a problem hiding this comment.
Nevermind I see! Adding.
|
|
||
| 3. **`.gitignore`**: This file tells git which files it should not track / not maintain a version history for. | ||
|
|
||
| 4. **`.prettierrc`**: This is a configuration file for [Prettier](https://prettier.io/). Prettier is a tool to help keep the formatting of your code consistent. |
There was a problem hiding this comment.
We don't, in favor of ESLint. Good catch again ty!
|
Thanks @hancush! I've added edits based on your comments. After a little investigative work I believe that the Jinja error you noted above was caused by the double brackets of JSX syntax, eg: <header
style={{
background: `#e49fb2`,
marginBottom: `1.45rem`,
}}
/>An unfortunate collision, but I've gotten around it by adding a line in |
hancush
left a comment
There was a problem hiding this comment.
It works! Overall, this looks great to me. I have one outstanding question about style preferences, and then I think this is good to go. Really great idea to start from Gatsby's own template. 🚀
| const Header = ({ siteTitle }) => ( | ||
| <header | ||
| style={{ | ||
| background: `#e49fb2`, |
|
|
||
| const Header = ({ siteTitle }) => ( | ||
| <header | ||
| style={{ |
There was a problem hiding this comment.
Style question: We tend to avoid inline styles when writing HTML. What's our stance on inline styling for components?
There was a problem hiding this comment.
Great question, and one that I'd like to have a stronger stance on! (I suspect going through the course at https://mastergatsby.com/ would supply it)
This section of the Gatsby tutorial gives a good account of the different CSS approaches: global styles, component-scoped styles, and CSS-in-JS (aka inline styles).
I've used all 3 at different times, and the approach that I've liked most has been to have a global style sheet (which this repo doesn't include, but maybe should—here it is on the courts app) and to handle the component-level styling with CSS-in-JSS. The Gatsby docs also recommend using CSS modules, but I've found it cumbersome to have to create a second CSS file to update alongside every component.
I've also used the styled-components package for CSS-in-JS, and I'd originally included it in this template, but I haven't always actually found it necessary. In courts, David started his components with it and I've ended up writing it out.
This is a good overview of the benefits of CSS-in-JSS: https://medium.com/seek-blog/a-unified-styling-language-d0c208de2660
I'm inclined to add a global style sheet to this repo for now, and plan to come back to this question later and flesh out official guidance on DataMade's React CSS practices if I go through that Mastering Gatsby class. I agree that avoiding inline CSS styles in Django projects is still a best practice. What do you think?
There was a problem hiding this comment.
That's a good plan! I agree it'd be nice to have an example of global styles in the template.
| @@ -0,0 +1,16 @@ | |||
| module.exports = { | |||
There was a problem hiding this comment.
Nice! We should deprecate this guidance after we bring this in.
There was a problem hiding this comment.
It'd be nice to bring this testing-guidelines repo into how-to... what do you think about the sequencing of tasks here?
There was a problem hiding this comment.
We decided to leave the external repos (data-analysis-guidelines, data-making-guidelines, testing-guidelines, deploy-a-site before it was deprecated) separate, to preserve any external links to them. (data-making-guidelines, in particular, has a life of its own.) I think that, after this comes in, we should deprecate the JavaScript testing portion of testing guidelines, since it was never really adopted anyway, but leave everything else over there for now.
There was a problem hiding this comment.
Sounds good. I can set up a PR with that deletion.
|
@hancush I've set this up with a global styles sheet! Let me know if this looks good to merge. I'll open a PR now in |
Overview
This PR adds a cookiecutter template for a DataMade-style Gatsby app to
docker/templates. It's based on gatsby-starter-default but includes Bootstrap setup, a Github Action for linting, and is containerized.@jeancochrane or @hancush, I'd love to hear your thoughts on the containerization here. When I'm developing a Gatsby project and add or delete a dependency, I have to stop and rebuild the container. Is there a way I can modify my Dockerfile here so that it live updates
node_modules?Testing
🚀 Quick startguide in your new directory's README to run the site