Would't it be great if we could sync our Sitecore JSS website to our local JSS dev environment?

You are a hardcore Sitecore developer, or a front end wizard and are starting with Sitecore JSS. At first you might think, I don't know anything about front end stuff, or as a front end dev, you don't want to do anything with Sitecore. Then there's two ways to work with JSS (developer workflows) Code First and Sitecore First. And what about the structure? How is data handled? Feeling desperate yet? You can also get into annoying discussions in your company between front end developers and Sitecore developers of what would be the best way to go.

A proven approach

Here at Macaw, we've been utilizing React with SSR (for SEO purposes) that consumes JSON from MVC controllers for a long time now. Front end developers work closely together with the Sitecore devs. All logic is provided through the ASP.NET MVC logic to the front end application which parses all data and transforms it to HTML. This is done server side (SSR) and for client interaction it also will hydrate. JSON data from Sitecore outputted from the controller is pulled into a file allowing the front end devs to use the mock data in their apps. This is not an ideal situation but with the connected mode in JSS they now can use real live data.

With the introduction of Sitecore JSS we also had some discussion which developer workflow should be used. The front end developers wanted to go with the code first approach as the Sitecore developers wanted to start with defining the templates because of inheritance and other reasons: the Sitecore first approach.

In the end, the Sitecore first approach is the only way because we cannot run JSS with Sitecore in disconnected mode all the time. And also because this would make JSS just another static site generator. You can imagine these discussions can be hard. So I had to make an end of that :-)

Umbrella for Sitecore JSS

From JSS it is possible to define a routing structure, define manifests for metadata like templates and components etc., add data for layouts and push them all using the JSS CLI to your Sitecore server. But what about going from Sitecore to your local offline JSS environment? No mechanism allows you to do that. Wouldn't it be cool if you could export your JSS website and pull it in a way that it would create the manifest files, routing and content? And even download images and files from the media library and assign them in your YML files?

Umbrella for Sitecore JSS is a utility that synchronizes items from your Sitecore JSS website to a folder on your computer where you can work directly in your local JSS application even when you're offline. It pulls the current state of your app in Sitecore to your local state.

Why? In Sitecore JSS you can choose between two developer workflow states. I think Sitecore First is the one to go with. If your website is running in the production environment you have to. But, you always start with the Code First approach.

Umbrella for Sitecore JSS consists of two parts, the Umbrella endpoint and the Umbrella NodeJS script. First you need to install the Umbrellea endpoint. You can do this in two ways:

Install the solution - The solution is set up using the Helix templates by Anders Laub and I added Cake build scripts, which are very very cool, to provide clean build and deploy steps for your environment. Check out the releases here.

Use the NuGet feed - I also provided two NuGet packages for Sitecore versions 9.1 and 9.1.1. at the moment of this writing, but I'll keep updating it when other versions arrive.



Umbrella.PanTau

The Umbrella.PanTau project adds an extra JSS endpoint: /sitecore/api/layout/render/umbrella to your Sitecore environment. This endpoint is used by the Umbrella Sync Script to extract data from your Sitecore JSS environment. The output below is an example:

Umbrella Sync Script

The Umbrella Sync Script is a NodeJS script that has to be put into a folder named scripts. It has to be executed from the root of your JSS project folder:

node .\scripts\umbrella.js

At the moment of this writing the Umbrella Sync Script is part of the React TypeScript Starter which is part of the Umbrella project. Soon I'll be writing some more about this awesome great JSS starter.

Use Umbrella for Sitecore JSS in combination with the ultimate React TypeScript Starter for Sitecore JSS

Routing

JSS uses dynamic routing based on the Layout Service (or local route data files in disconnected mode), and uses route/navigation changes to trigger app state changes. When we want to sync we also must have some mechanism in place which holds the routes independently from the Layout Service or the local route data files.

Querying the JSS endpoint only will give you one route. From the client app we don't know the actual routes which are created in Sitecore. This is why, at the moment, we must add extra route information.

To overcome the problem of routing in the case described above you should create a file named routeconfig.json in the root of your JSS client app and add the routes you have:

Usage

node .\scripts\umbrella.js sync

Options

Switch Action -t, --templates Sync all the templates from Sitecore -p, --placeholders Sync all the placeholders from Sitecore -m, --manifests Sync all the component manifests from Sitecore -c, --content Sync all the content from your Sitecore JSS website

API

The Umbrella endpoint will output data that is used by the Umbrella NodeJS script. The Umbrella NodeJS script will export this data to several sections in your local JSS application. Note that templates, renderings, media items are all inside a project folder. Umbrella will only export items from these folders, which means that foundation and feature folders are not processed (at the moment).

Placeholders

Exports all available placeholders from your JSS Sitecore environment to <app root>/sitecore/definitions/placeholders.sitecore.js .

Templates

Exports all available templates from your JSS Sitecore environment to <app root>/sitecore/definitions/templates .

Components

Exports all available components from your JSS Sitecore environment to <app root>/sitecore/definitions/components .

Content and Media

This will export the content of your routes (pages) to your local JSS development environment and saves it in the <app root>/data/routes folder. During the export the script will check for image fields and wil save them to the <app root>/data/media folder .

Input

If you have any suggestions, ideas want to participate find me on Slack!