From 789b526526b234839498cd7a9b77aa9201916ebb Mon Sep 17 00:00:00 2001 From: Sam Carlton Date: Sat, 10 Jul 2021 22:54:05 -0500 Subject: [PATCH] Add getAppVersions eleventy function --- .eleventy.js | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/.eleventy.js b/.eleventy.js index dcdfef8..2d1bbd6 100644 --- a/.eleventy.js +++ b/.eleventy.js @@ -24,7 +24,7 @@ */ -import fs from 'fs' +import fs from 'fs-extra' import replace_css_url from 'replace-css-url' import dotenv from 'dotenv' import { InlineCodeManager } from '@11ty/eleventy-assets' @@ -43,6 +43,8 @@ function getAssetFilePath(componentName) { const inlineAssetCache = new Map() +const appBundles = new Map() + module.exports = function ( eleventyConfig ) { // console.log('eleventyConfig', eleventyConfig) @@ -55,6 +57,22 @@ module.exports = function ( eleventyConfig ) { const cssManager = new InlineCodeManager() const jsManager = new InlineCodeManager() + eleventyConfig.addJavaScriptFunction('getAppVersions', async function ( bundleIdentifier ) { + if (appBundles.size === 0) { + const appBundlesFromJson = await fs.readJson('./static/app-bundles.json') + appBundlesFromJson.forEach(([ jsonAppBundleIdentifier, versions ]) => { + appBundles.set( jsonAppBundleIdentifier, versions ) + }) + } + + if ( appBundles.has( bundleIdentifier ) ) { + return appBundles.get( bundleIdentifier ) + } + + // Bundle not found + return null + }) + eleventyConfig.addJavaScriptFunction('usingComponent', async function ( componentName ) { // console.log('Getting component', componentName)