Replies: 32 comments 2 replies
-
Why not |
Beta Was this translation helpful? Give feedback.
-
Sounds great! I wonder how apps that already have custom code will be handled. Sounds like Blitz will need some kind of conflict resolution system.
npm can only install packages in Having this in the CLI also allows us to also generate the boilerplate in our code. |
Beta Was this translation helpful? Give feedback.
-
some of the items in the list seem to be of the same category ( |
Beta Was this translation helpful? Give feedback.
-
Sounds like Gatsby recipes. Does it make sense to standardize on a similar format for this? Eg MDX with custom components for install vs update |
Beta Was this translation helpful? Give feedback.
-
Sounds great! But I'm thinking if we can try another solution to still use Something similar in Rails
Maybe we can still have
|
Beta Was this translation helpful? Give feedback.
-
does this solve the plugins case? |
Beta Was this translation helpful? Give feedback.
-
@remi2j Yes, it'll definitely have some type of nice conflict resolution system.
@amine-benselim Yes, I've just listed them as various examples, not as things someone would all use at once.
@NateRadebaugh Gatsby recipes are only docs right? Blitz installers are code generators, not docs.
@cristianbgp The problem with this approach is that the tailwind npm package would have to package the blitz specific code. And they will never do that in the main package. Unfortunately this is a different landscape than the Rails/Gem one.
@toddgeist no. Installers often won't hook into Blitz at all. Mostly they will install a dependency or two and scaffold a bit of code. Plugins on the other hand will hook into various parts of blitz. An installer could also install a plugin. I'll post another RFC soon for plugins |
Beta Was this translation helpful? Give feedback.
-
Gatsby Recipes install dependencies and write to files. Not sure if they line up exactly with what you have in mind for Blitz Installers, but sounds pretty close! |
Beta Was this translation helpful? Give feedback.
-
Oh wow, yes! Googling “Gatsby Recipes” takes you to a docs section that’s titled “Gatsby recipes” lol Looks like pretty much the same thing as what I’m proposing! Not sure how I feel about MDX for this tho 🤔 Seems limiting and extra complexity for what can be a regular node script. But I could be convinced otherwise :) |
Beta Was this translation helpful? Give feedback.
-
Hi,
Prepends import '../style.css' to app/pages/_app.tsx Tell me what you think and let's build this together via PRs 👍 |
Beta Was this translation helpful? Give feedback.
-
When I saw this RFC Gatsby recipes were the first thing that came to my mind as well. Reading the announcement blog, it seems like the MDX syntax is mainly for readability. The heavy-lifting looks like it's being done by an xState machine to control the flow for running a recipe. |
Beta Was this translation helpful? Give feedback.
-
I think some in the community will really appreciate this and it will definitely save time in many cases but I must say I love the way next has all their examples in their repo and I still think we should give people the option of copying code from an example to apply it (even if the examples were just generated from running the installation scripts) Perhaps I am paranoid around combinations of automation breaking or I really find comfort in understanding how a plugin is actually integrated. |
Beta Was this translation helpful? Give feedback.
-
@ryardley we could only run an installer if the git repo is clean. Then |
Beta Was this translation helpful? Give feedback.
-
Also similar to what https://flex.symfony.com is providing for Symfony Bundles, their options and configuration is documented at https://github.com/symfony/recipes/blob/master/README.rst. They actually hook into the package installation to find matching recipes automatically, not sure if that's something we could also accomplish in a postinstall-hook or something? They also show a note after installation to check (with |
Beta Was this translation helpful? Give feedback.
-
Could you elaborate on the advantages of distributing via Git vs using NPM? Also, as the code to be generated depends on the version of Blitz used, there will be the need for some kind of versioning with the generator scripts. |
Beta Was this translation helpful? Give feedback.
-
@aem nice!! So what would an actual installer look like? |
Beta Was this translation helpful? Give feedback.
-
knew I forgot an example 🤦♂️something like this, assuming import { Installer } from '@blitz/installer'
enum Steps {
addDep,
addPostcssConfig,
addSampleStyles,
import,
}
export default new Installer(
[
{
stepId: Steps.addDep,
stepName: 'Add tailwind dependencies',
explanation: 'Install tailwind and related postcss dependencies',
packages: ['tailwindcss@1', '@fullhuman/postcss-purgecss', 'postcss-preset-env'],
},
{
stepId: Steps.addPostcssConfig,
stepName: 'Add postcss config',
explanation: 'Configure the postcss processor',
templatePath: path.join(__dirname, 'templates', 'postcss-config'),
destinationPath: '.',
},
{
stepId: Steps.addSampleStyles,
stepName: 'Add example style files',
explanation: "We'll add some example styles to get you up and running",
templatePath: path.join(__dirname, 'templates', 'styles'),
destinationPath: './app/styles',
},
{
stepId: Steps.import,
stepName: 'Import styles into app',
explanation:
"Finally we need to import your styles into the app. For our sample files, we'll import them into your app root.",
// any installer field can either be a static property or a function that accepts the
// CLI args and returns the same type as the static property
singleFileSearch(cliArgs: any) {
return cliArgs.appRootPath
},
transform(fileInfo, api) {
// these lines are standard in the codemod - access the jscodeshift API
// and extract the file's source as an AST
const j = api.jscodeshift
const fileRoot = j(fileInfo.source)
// this defines an import statement, the empty array means no import specifiers
// since we're not importing any variables into the namespace
const stylesImport = j.importDeclaration([], j.literal('app/styles/index.css'))
// we can probably supply a generic utility for adding an import to a file,
// installer authors shouldn't need to rewrite this from scratch
addImport(fileRoot, j, stylesImport)
},
},
],
{
packageName: 'tailwind',
packageDescription: 'Installs tailwind CSS and adds necessary setup code to application.',
packageRepo: 'https://github.com/blitz-js/installers',
packageOwner: 'adam@markon.codes',
async validateArgs(args: any) {
if (!args.appRootPath) {
throw new Error(
'[tailwind installer]: please supply --appRootPath. Usually this is app/pages/_app.tsx',
)
}
},
},
) I have the package metadata fields in there so that we can log some useful information to the user - "this installer is provided by {{owner}} and will install {{packageName}}. See more at {{repo}}", etc |
Beta Was this translation helpful? Give feedback.
-
Ok cool — looks promising! Could you update that for tailwind specifically? Would be easier to grok than |
Beta Was this translation helpful? Give feedback.
-
Would |
Beta Was this translation helpful? Give feedback.
-
@aem I’d love to see what that looks like for tailwind too. FYI, the steps for setting it up in a Next.js / Blitz app normally are documented well here: https://github.com/tailwindcss/setup-examples/tree/master/examples/nextjs. |
Beta Was this translation helpful? Give feedback.
-
@aem @merelinguist we already have a Blitz tailwind example at |
Beta Was this translation helpful? Give feedback.
-
Could theoretically be either. I'd guess eventually we'll see some common patterns and want to build out some shared utilities, but initially we'll probably have installer authors write their own. That example was a quick and dirty version, but I should be able to get something more realistic written up that actually uses the jscodeshift API today. |
Beta Was this translation helpful? Give feedback.
-
@flybayer @merelinguist I updated the example to use tailwind, which is much clearer, less contrived, and honestly that code could probably be copy-pasted into the official tailwind installer once the installer internals are built out. I added some comments for things that aren't obvious in the example since it doesn't have typescript types |
Beta Was this translation helpful? Give feedback.
-
But having said that, it does compile! Locally all of the types check properly e2e, including the installer scaffolding from my RFC gist |
Beta Was this translation helpful? Give feedback.
-
@aem awesome!!
|
Beta Was this translation helpful? Give feedback.
-
@flybayer for sure! i think a lot of that stuff will be fleshed out more during implementation, the idea here was just to give an idea of what the API/step framework looks like |
Beta Was this translation helpful? Give feedback.
-
If there's no other significant concerns about the architecture here I'll proceed with this implementation. Should have something installer-esque by the end of the weekend |
Beta Was this translation helpful? Give feedback.
-
@aem sounds glorious! |
Beta Was this translation helpful? Give feedback.
-
Wanted to provide a quick update for everyone based on an exciting meeting we had with the folks over at Gatsby earlier today. Some bullets from my notes:
@flybayer anything I missed? |
Beta Was this translation helpful? Give feedback.
-
whats a good resource to get up to speed on the core ideas behind recipes? |
Beta Was this translation helpful? Give feedback.
-
Problem
There's hundreds of tools and libraries that different people want to integrate with their app.
Next.js solves this problem by having all these integrations as example apps. This works fairly well, but it's still cumbersome to go find the proper example, copy the code, paste the code, try it, go back and copy something you forgot to copy, and finally get it working.
Solution
Add the
blitz install
command that can run any available installer.Examples:
blitz install tailwind
blitz install styled-components
blitz install emotion
blitz install theme-ui
blitz install sentry
blitz install storybook
blitz install auth0
blitz install fauna
The two most common things performed by an installer are:
Implementation
At the most basic level, an installer is a plain Node script. But we'll provide utilities that make it easy to write an installer.
Installer helpers:
installDependencies
andinstallDevDependencies
— will automatically use npm or yarn based on the projectPerhaps we could have a
@blitzjs/installer
package to import the helpers from. It would always be available in a blitz app for the installer to use.Feedback
I'd love to hear all your comments on this. Love it? Hate it? Ideas on making this better?
Beta Was this translation helpful? Give feedback.
All reactions