RFC: Add support of the `pull` command in the Prismic CLI
See original GitHub issueSummary
We want to add a way to synchronize your components between Prismic and your project. It would be a CLI command that will scan all your slices on Prismic side and all your slicemachine components on the other side to help you create the missing ones and update the others if needed.
Motivation
The goal of Slicemachine is to have a more code-centric approach and avoid all these steps of simply synchronizing your setup on Prismic and your project. The CLI is supposed to be here to resolve this connection and automate things for you.
Here we face the case where you add Components from the Writing Room that is connected to all of our Slicemachine Libraries. You can even imagine that these slices that already exists in your project might have been updated since then. So here, it’s just a quick way to resolve these cases seamlessly.
Scenario
Let’s say that you just setup your project for SliceMachine with the following command:
> prismic sm --setup
It created 3 slices:
- CallToAction
- Banner
- HighlightItems
At some point, you decide to change the models of CallToAction
and Banner
and to add a new slice called HelloWorld
from the writing room.
You can use the following command to update your project accordingly:
> prismic sm --sync
These slices were added to your project:
- HelloWorld
Conflicts on the custom type `page`.
All these components already exists but their model diverge.
Select the components you'd like to update:
[ ] CallToAction
[x] Banner
We successfully updated the model of:
- Banner
Please update your implementation accordingly.
implementation
- Create a new command
--sync
for slicemachine that will be recognize by the CLI. - Gather all the models of the slices coming from the different libraries listed in
sm.json
- Fetch all the slices coming from your custom types through the CustomTypes API (see
create-slice
as an example) - Make a diff between these to identify:
- Existing slices already up to date
- Existing slices that have conflicts because of updates on the Writing room
- Missing slices that should be added to the project
- Create the Missing Slices
- Create an interactive way with
inquirer
(Already the dependency used for Prompts) to resolve conflicts and update or not the models in the code.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:25 (12 by maintainers)
Top GitHub Comments
First implementation: https://github.com/prismicio/prismic-cli/pull/48
Took me a bit of time to understand the sync described here but if I’m right current behavior of
prismic sm --sync
looks more like a pull than a true sync to me (which would have been applying last diffs on both sides) That’s why I find it a bit misleading put that way, probably 🤔In my opinion, it’ll be clearer to make it like
prismic sm --pull
or similar so we’ll be able to work on it from that point, and then we’ll be able to work on a counterpartprismic sm --push
if needed? Both resulting to some sort of an interactive prompt allowing people to choose which contents to override and whatnot with the pull/push command (like on the example described in the given scenario).As for slices used through dependencies perhaps it’ll be simpler to introduce a third command like
prismic sm --push-deps
(not sure at all about that name), to just push/update their models to Prismic with an interactive prompt again to be sure we’re not overriding anything not wanted. If we get through this path though this means that the previous pull/push commands will only care about project-level slices (not the ones from dependencies), hope that makes sense~With all of that in mind, I think it raises few questions like how we’re sure we’re doing the matching correctly between Prismic slices and their models (not sure how that’s done currently), also as @hypervillain pointed out what about knowing which customs types a model belongs to?