Skip to content

Commit

Permalink
handle preprocessed data
Browse files Browse the repository at this point in the history
  • Loading branch information
robindemourat committed Nov 13, 2019
1 parent 091c744 commit 24c3749
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
19 changes: 19 additions & 0 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ function generateOutput({
peritextConfig = {},
locale = {},
outputPath,
preprocessedData,
tempDirPath = './temp',
requestAssetData,
onFeedback,
Expand Down Expand Up @@ -151,6 +152,10 @@ function generateOutput({
});

return (0, _fsExtra.writeFile)(`${jobTempFolderPath}/production.json`, JSON.stringify(finalAssets), 'utf8');
}).then(() => {
if (preprocessedData) {
return (0, _fsExtra.writeFile)(`${jobTempFolderPath}/preprocessedData.json`, JSON.stringify(preprocessedData), 'utf8');
} else return Promise.resolve();
}).then(() => {
if (typeof onFeedback === 'function') {
onFeedback({
Expand Down Expand Up @@ -250,11 +255,25 @@ function generateOutput({
*/
loadJSON(urlPrefix + 'production.json', function(prod) {
window.__production = JSON.parse(prod);
${// loading preprocessed data if available
preprocessedData ? `
loadJSON(urlPrefix + 'preprocessedData.json', function(preprocessedData) {
window.__preprocessedData = JSON.parse(preprocessedData)
/**
* Dynamically loading the html bundle
*/
var bundleURL = urlPrefix + 'bundle.js';
loadJS(bundleURL, document.body);
});
` : `
/**
* Dynamically loading the html bundle
*/
var bundleURL = urlPrefix + 'bundle.js';
loadJS(bundleURL, document.body);
`}
})
Expand Down
26 changes: 26 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ function generateOutput ( {
peritextConfig = {},
locale = {},
outputPath,
preprocessedData,
tempDirPath = './temp',
requestAssetData,
onFeedback,
Expand Down Expand Up @@ -154,6 +155,12 @@ function generateOutput ( {

return writeFile( `${jobTempFolderPath}/production.json`, JSON.stringify( finalAssets ), 'utf8' );
} )
.then( () => {
if ( preprocessedData ) {
return writeFile( `${jobTempFolderPath}/preprocessedData.json`, JSON.stringify( preprocessedData ), 'utf8' );
}
else return Promise.resolve();
} )

.then( () => {
if ( typeof onFeedback === 'function' ) {
Expand Down Expand Up @@ -246,11 +253,30 @@ function generateOutput ( {
*/
loadJSON(urlPrefix + 'production.json', function(prod) {
window.__production = JSON.parse(prod);
${
// loading preprocessed data if available
preprocessedData ?
`
loadJSON(urlPrefix + 'preprocessedData.json', function(preprocessedData) {
window.__preprocessedData = JSON.parse(preprocessedData)
/**
* Dynamically loading the html bundle
*/
var bundleURL = urlPrefix + 'bundle.js';
loadJS(bundleURL, document.body);
});
`
:
`
/**
* Dynamically loading the html bundle
*/
var bundleURL = urlPrefix + 'bundle.js';
loadJS(bundleURL, document.body);
`
}
})
Expand Down

0 comments on commit 24c3749

Please sign in to comment.