Using the Sitecore JSS Manifest for Content Import
A novel use of the JSS import process
For JSS, this approach is useful for Front-end developers who don't need to learn all the ins-and-outs of Sitecore in order to deploy a fully functional Sitecore site. But recently I was looking for a means to import some test content for another project, and realized its potential as a more general import tool as well.
Normally a content import (especially a one-time import) is something I would use Sitecore PowerShell Extensions to accomplish. I still love SPE but for my purposes, the JSS Import had some advantages:
- I could define the templates, in addition to the content items. There's currently no SPE commadlet for creating templates. (Though this may change based on some Slack discussions since then!)
- The amount of code required to generate an item is much less.
- By enabling the JSS full wipe mode, I could easily clean all imported templates and content on every incremental run of the import, as I added more fields, data, types, etc.
This approach does have some drawbacks:
- The import currently expects to run in the context of a JSS app, so a JSS app needs to be configured and a JSS app item will be generated as the parent of the imported content.
- The import process may create some unnecessary items, e.g. a root for the JSS app dictionary.
- The JSS manifest does not have the full capabilities of the Sitecore data model. For example interlinking between items is difficult or impossible (at the time of writing).
- The packaging and installation process does have some overhead. Installation via Ship became an issue for me due to the size of the Update Package. Once I scaled the amount of data coming in, I started getting HTTP timeouts from Ship, and had to install via the Update Installation Wizard.
It still worked great for my test data purposes, and I could see other one-time imports benefiting as well. And it's always interesting to find new, novel uses for a tool you helped create.
How It's Done
Start with the JSS Quick Start to get one of the basic sample apps up and running. You'll need to follow the steps to get the JSS server and infrastructure components up and running. Then, if you like, strip it down. Get rid of all the react/angular code, existing *.sitecore.js manifest definitions, etc. Then create manifest definition files for your templates and your content. See my examples below. Enable full wipe mode if you want a clean import each time. Then use the JSS CLI to generate the manifest, create the update package, and install it.
jss deploy package --includeContent --noFiles
The includeContent flag is important to ensure your content items are imported. The noFiles flag is used to exclude any JSS code files from the package (we aren't deploying a JSS app, so we don't need them). If you just want to generate the update package, so you can install it via another means, you can just execute
jss package --includeContent --noFiles
So again, this is a experimental/novel use of JSS, not a typical use case we had in mind when creating the manifest and import. But is it helpful/interesting to you? Have feedback? Let us know in #jss on the Sitecore Community Slack! -Nick