-
Notifications
You must be signed in to change notification settings - Fork 80
First pass at setting up NextGen front-end project #17
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
First pass at setting up NextGen front-end project #17
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTMSF
|
||
## Running Locally | ||
|
||
1. You need to have the services in the `scratch-platform` monorepo running first. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a note: if we are retaining fall backs to staging for locally running code, then it should be possible to run a minimalist amount of scratch-platform to support local dev, but if that's something we've already deviated from, we'll correct that dev ergonomics later (because a dev will get annoyed by it... and fix it!)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My thinking was the set up is going to involve just:
- Running a command in scratch-platform (which runs all services locally in docker)
make run
- Running a command here to start the front-end
npm run dev
and that's it. If all you need to do to run locally is two commands, I don't feel we need to configure staging usage for dev ergonomics.
We will need to think it through before we open-source the frontend code, though, but I feel like we can think through that at a later stage. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That all reads as reasonable... Only, we've spent more than the last 10 years working this way, i.e. that defaults for all local development will go to staging unless otherwise directed by env vars to local resources... Mainly, my worry is that doing even trivial local dev will end up requiring a machine with > 16GB of RAM. (personally, I advocate for maxing out dev's RAM, but cost is a factor for us...)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My personal preference for a public repository is that if someone outside of Scratch Foundation clones the repo and hits the "GO" button, they get as much non-Scratch-specific functionality as we can reasonably provide. That is, I'd prefer to bias toward self-contained local dev. Another positive of this approach is that it lets us avoid committing any of our real domain names (staging or prod) into the repo.
I also agree with what Colby's saying, though. I think my ideal would be that default behavior goes to localhost
but it's easy to put entries into .env
to use staging for some or all services. I think that's basically the direction this is heading in already, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, everything would be controllable through the .env
file.
We can also have both .env.example
and .env.example.staging
at root-level and devs cloning the repo can pick which one to base their .env
on? Does that seem reasonable in handling both cases? It would mean were committing real domain names, though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup. This looks like an SVG
"module": "ESNext", | ||
"skipLibCheck": true, | ||
|
||
/* Bundler mode */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Potential change: /* Bundler mode activate */ (sorry, not sorry, Wonder Twins joke)
Some notes on your notes :)
I have no objections to moving away from webpack -- actually, I might prefer moving -- as long as we can make everything work.
🎉
100% OK by me. We have some pretty complex state in the editor, but I hope it's not necessary outside the editor.
I'm flexible on styling, and I don't feel the need to stick to what Anyway, the point I'm getting at is: since our TS must use somewhat different rules, I think it's OK if our TS uses very different rules if it reduces our maintenance burden in the long term.
👍 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great so far! I'm excited!
I did have a thought I'd like to discuss, but it's not really part of the code review......
trailingComma: 'all', | ||
|
||
plugins: [ | ||
require.resolve('@trivago/prettier-plugin-sort-imports'), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😎
|
||
## Running Locally | ||
|
||
1. You need to have the services in the `scratch-platform` monorepo running first. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My personal preference for a public repository is that if someone outside of Scratch Foundation clones the repo and hits the "GO" button, they get as much non-Scratch-specific functionality as we can reasonably provide. That is, I'd prefer to bias toward self-contained local dev. Another positive of this approach is that it lets us avoid committing any of our real domain names (staging or prod) into the repo.
I also agree with what Colby's saying, though. I think my ideal would be that default behavior goes to localhost
but it's easy to put entries into .env
to use staging for some or all services. I think that's basically the direction this is heading in already, right?
|
||
Environment variables do not follow the regular convention where they are statically defined in the output JS bundle. Instead, they are served through a `config.js` file that is expected to be available on the root of the (sub)domain where the application is served. A plugin in [vite-config-js-plugin.ts] adds a reference to `/config.js?v=<random-string>` to be loaded before the JS bundle. The random string changes on each build and is there to bust any caches when a new version of the code is deployed. | ||
|
||
The goal is to be able to deploy a build artifact (the JS/asset bundle) to multiple environments instead of having to rebuild for each one (as normally env variables are statically inserted into the bundle). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I REALLY like this. Not only for repeatability between staging & production, but also to ensure that we can locally debug exactly the code that's live.
So... I'm starting to have second thoughts on where this code should live. I'm sorry! Basically, I'd like everything in On the other hand, I really like the idea of a future where So, I can think of two reasonable proposals:
Thoughts? Alternative proposals? |
@cwillisf Those are all excellent points. I was assuming we wanted to have the front-end open-source, but hadn't thought too much about it. It would definitely be better for development if we have both the front-end and backend in the same repository - in terms of releases, version management, CI & synchronized code changes as well. This implies that scratch-web is private, which is why I hadn't brought it up. In terms of @colbygk, @chrisauer, how do you feel about what's being discussed here? I was also thinking that it would be a good idea to have another monorepo with backend+frontend (instead of scratch-platform) for the NextGen work so that we don't have services for both the current Scratch (uploader, sortinghat) and the NextGen in the same place. Would make it cleaner to work with (no READMEs with "if working with current platform do this / if working with NextGen do that") and it would be decoupled in terms of CI as well. |
I think it would be better to not have the "web" aspect of Scratch be open source, and leave the editor fully open source which would make our open source stance more specific, and help us avoid the community lawyering us about having the backend not open source, while all of the frontend is open source. Long term, I think it's on mission to have an open source editor while the web site frontend, is not necessarily something we're using as part of a mission to have external third parties have the ability to lift the entirety of scratch-www. |
Another ingredient that occurred to me while I was thinking about this over the weekend: we've talked about wanting the Scratch community website to be powered by a CMS so that less-technical folks can make updates to the content. That's far enough away that we can't block current work on it, but it's something to keep in mind in terms of long-term direction of travel. In my eyes, having our website open-source is a nice-to-have so that folks can help us out, but the value is mostly to us: other folks won't learn much from our website, and the value of forking it is even lower. With that in mind, I'm OK with making our website private: we're not taking much value away. I also agree with @colbygk that this makes our open-source stance clearer. Combining those two things with the discussion above, I agree with the plan @georgyangelov described. I'd extend it this way:
Does that work for everyone? |
The Scratch engineering team discussed this today, and everyone is on board with the plan I described above. |
Some important notes:
scratch-web-shared
package to host a Scratch component library and any other React utilities (hooks, etc.) that we may requireuseContext
&useReducer
where necessary.views
andcomponents
folders whereviews
are pages andcomponents
are shared React components between those pages.fetch
calls based on the backend services' documentation/config.js
approach we discussed in one of the architecture calls - the idea being that we can build once and reuse those built artifacts for multiple environments (because env vars won't be hardcoded inside). To do that I wrote a Vite plugin to serve config.js on the dev server (getting env vars from.env
) and inject the loading ofconfig.js
into the HTML for the bundle.There will be more PRs with added boilerplate soon :)