Last active
January 20, 2020 19:35
-
-
Save aweber1/2512b331c5ddb424090ee0f1d701f779 to your computer and use it in GitHub Desktop.
Sitecore JSS manifesterator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// would be part of a new `sitecore-jss-manifest` module | |
export default (routeData, specData) => { | |
// convert route data and spec data to Sitecore stuff. | |
// write `sitecore-import.json` to disk | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// would be part of a new `sitecore-jss-manifest` module | |
export default () => { | |
const routeData = getRouteDataFromWhereverItLivesOrHoweverYouWantThx(); | |
return routeData; | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// would be part of a new `sitecore-jss-manifest` module | |
export default (specFileNames = []) => { | |
const specData = specFileNames.map((fileName) => { | |
const spec = require(fileName).default; // dynamic file load | |
return spec(); | |
}); | |
return specData; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// would be part of a new `sitecore-jss-manifest` module, the 'entry point' | |
import generateManifest from './generateManifest'; | |
import generateRouteData from './generateRouteData'; | |
import generateSpecData from './generateSpecData'; | |
const routeData = generateRouteData(); | |
// get specFileNames from cli, params, search, whatever... | |
const specFileNames = '//*[@templatekey = "SPEC"]'; // Sitecore descendants FTW :) | |
const specData = generateSpecData(specFileNames); | |
generateManifest(routeData, specData); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// React component | |
import React from 'react'; | |
import PropTypes from 'prop-types'; | |
import { Placeholder } from '@sitecore/sitecore-jss-react'; | |
const Welcome = (props) => | |
(<div> | |
Welcome to Sitecore! | |
<Placeholder name="page-header" /> | |
<Placeholder name="page-content" /> | |
</div>); | |
Welcome.propTypes = { | |
title: PropTypes.string, | |
text: PropTypes.string | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// manifest spec file | |
import Welcome from './Welcome'; | |
export default (manifestConfig) => { | |
const propTypes = Welcome.propTypes; | |
Object.keys(propTypes).forEach(key => { | |
const propTypeValue = propTypes[key]; | |
// do something fancy here to translate propTypes into field definitions, if you can. | |
}); | |
// do more fancy stuff here to generate metadata (e.g. static analysis) | |
return { | |
componentName: 'Welcome', | |
fields: [ | |
{ name: 'title', displayName: 'Title', type: 'string', editable: true }, | |
{ name: 'text', displayName: 'Text', type: 'richText', editable: false } | |
], | |
placeholders: ['page-header', 'page-content'] | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment