From 24c3749df1fcfde13182f77a34246310ad040025 Mon Sep 17 00:00:00 2001 From: Robin de Mourat Date: Wed, 13 Nov 2019 17:58:05 +0100 Subject: [PATCH] handle preprocessed data --- dist/index.js | 19 +++++++++++++++++++ src/index.js | 26 ++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/dist/index.js b/dist/index.js index 61d23a1..9e2133f 100644 --- a/dist/index.js +++ b/dist/index.js @@ -30,6 +30,7 @@ function generateOutput({ peritextConfig = {}, locale = {}, outputPath, + preprocessedData, tempDirPath = './temp', requestAssetData, onFeedback, @@ -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({ @@ -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); + `} + }) diff --git a/src/index.js b/src/index.js index 9e84a1d..25a4084 100644 --- a/src/index.js +++ b/src/index.js @@ -25,6 +25,7 @@ function generateOutput ( { peritextConfig = {}, locale = {}, outputPath, + preprocessedData, tempDirPath = './temp', requestAssetData, onFeedback, @@ -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' ) { @@ -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); + ` + } + })