From f51b0bd9006813a1dfd06e98329716eabed1f7e9 Mon Sep 17 00:00:00 2001 From: Jason Slavin Date: Wed, 26 Jun 2024 13:31:12 -0700 Subject: [PATCH] Modifying libs based on discussion, fixing imports --- blocks/comparison/comparison.js | 4 ++-- blocks/faas-decode/faas-decode.js | 4 ++-- blocks/redirects-formatter/redirects-formatter.js | 6 +++--- blocks/stats/stats.js | 6 +++--- blocks/tree-view/tree-view.js | 4 ++-- blocks/workfront-login/workfront-login.js | 6 +++--- scripts/scripts.js | 14 ++++++-------- templates/featured-story/featured-story.js | 4 ++-- 8 files changed, 23 insertions(+), 25 deletions(-) diff --git a/blocks/comparison/comparison.js b/blocks/comparison/comparison.js index 09ffa0b..78e220c 100644 --- a/blocks/comparison/comparison.js +++ b/blocks/comparison/comparison.js @@ -1,10 +1,10 @@ -import { getLibs } from '../../scripts/utils.js'; +import { LIBS } from '../../scripts/scripts.js'; /** * @param {Element} el */ const init = async (el) => { - const { createTag } = await import(`${getLibs()}/utils/utils.js`); + const { createTag } = await import(`${LIBS}/utils/utils.js`); const rows = Array.from(el.querySelectorAll(':scope > div')); const headers = Array.from(rows.shift().children); const headersRow = createTag('tr'); diff --git a/blocks/faas-decode/faas-decode.js b/blocks/faas-decode/faas-decode.js index f6976dc..0224600 100644 --- a/blocks/faas-decode/faas-decode.js +++ b/blocks/faas-decode/faas-decode.js @@ -1,7 +1,7 @@ -import { getLibs } from '../../scripts/utils.js'; +import { LIBS } from '../../scripts/scripts.js'; export default async function init(el) { - const { createTag, parseEncodedConfig } = await import(`${getLibs()}/utils/utils.js`); + const { createTag, parseEncodedConfig } = await import(`${LIBS}/utils/utils.js`); const url = el.querySelector('a')?.href; const resp = await fetch(url); diff --git a/blocks/redirects-formatter/redirects-formatter.js b/blocks/redirects-formatter/redirects-formatter.js index 700da63..f03288d 100644 --- a/blocks/redirects-formatter/redirects-formatter.js +++ b/blocks/redirects-formatter/redirects-formatter.js @@ -1,4 +1,4 @@ -import { getLibs } from '../../scripts/utils.js'; +import { LIBS } from '../../scripts/scripts.js'; export const SELECT_ALL_REGIONS = 'Select All Regions'; export const DESELECT_ALL_REGIONS = 'De-select All Regions'; @@ -12,7 +12,7 @@ const INSTRUCTIONS_TEXT = 'Select the locales you require by checking the checkb + ' press "Copy to clipboard" or select them with the cursor manually.'; async function createLocaleCheckboxes(prefixGroup) { - const { createTag } = await import(`${getLibs()}/utils/utils.js`); + const { createTag } = await import(`${LIBS}/utils/utils.js`); return Object.keys(prefixGroup).map((key) => { const { prefix } = prefixGroup[key]; @@ -87,7 +87,7 @@ export function stringifyListForExcel(urls) { } export default async function init(el) { - const { createTag } = await import(`${getLibs()}/utils/utils.js`); + const { createTag } = await import(`${LIBS}/utils/utils.js`); const xlPath = './locale-config.json'; const resp = await fetch(xlPath); if (!resp.ok) return; diff --git a/blocks/stats/stats.js b/blocks/stats/stats.js index 68055eb..84af4aa 100644 --- a/blocks/stats/stats.js +++ b/blocks/stats/stats.js @@ -1,4 +1,4 @@ -import { getLibs } from '../../scripts/utils.js'; +import { LIBS } from '../../scripts/scripts.js'; async function decorateRow(row, module) { const { decorateLinkAnalytics } = module; @@ -14,8 +14,8 @@ async function decorateRow(row, module) { } export default async function init(el) { - const { createTag } = await import(`${getLibs()}/utils/utils.js`); - const module = await import(`${getLibs()}/martech/attributes.js`); + const { createTag } = await import(`${LIBS}/utils/utils.js`); + const module = await import(`${LIBS}/martech/attributes.js`); module.decorateBlockAnalytics(el); const firstRow = el.querySelector(':scope > div'); diff --git a/blocks/tree-view/tree-view.js b/blocks/tree-view/tree-view.js index 771ac00..385cdb9 100644 --- a/blocks/tree-view/tree-view.js +++ b/blocks/tree-view/tree-view.js @@ -1,4 +1,4 @@ -import { getLibs } from '../../scripts/utils.js'; +import { LIBS } from '../../scripts/scripts.js'; const BACOM_HOSTS = ['localhost', '--bacom--adobecom.hlx.page', '--bacom--adobecom.hlx.live', 'business.adobe.com']; @@ -110,7 +110,7 @@ const init = async (el) => { if (!topList) return; - const { createTag } = await import(`${getLibs()}/utils/utils.js`); + const { createTag } = await import(`${LIBS}/utils/utils.js`); const subLists = topList.querySelectorAll('ul'); const isAccordion = subLists.length > 0; const links = el.querySelectorAll('a'); diff --git a/blocks/workfront-login/workfront-login.js b/blocks/workfront-login/workfront-login.js index 6c6d0c1..1b7ceda 100644 --- a/blocks/workfront-login/workfront-login.js +++ b/blocks/workfront-login/workfront-login.js @@ -1,4 +1,4 @@ -import { getLibs } from '../../scripts/utils.js'; +import { LIBS } from '../../scripts/scripts.js'; export async function createProofForm(createTag, replaceKey, config) { const form = createTag('form', { action: 'https://app.proofhq.com/login', method: 'post' }); @@ -105,8 +105,8 @@ export async function createSubdomainForm(createTag, replaceKey, config) { /* c8 ignore next 14 */ export default async function init(el) { - const { createTag, getConfig } = await import(`${getLibs()}/utils/utils.js`); - const { replaceKey } = await import(`${getLibs()}/features/placeholders.js`); + const { createTag, getConfig } = await import(`${LIBS}/utils/utils.js`); + const { replaceKey } = await import(`${LIBS}/features/placeholders.js`); const config = getConfig(); const isProof = el.classList.contains('proof'); diff --git a/scripts/scripts.js b/scripts/scripts.js index cb3f645..c30b7e3 100644 --- a/scripts/scripts.js +++ b/scripts/scripts.js @@ -1,4 +1,3 @@ -const LIBS = '/libs'; const STYLES = ['/styles/styles.css']; const CONFIG = { imsClientId: 'bacom', @@ -155,18 +154,17 @@ const loadStyle = (path) => { eagerLoad(marquee.querySelector('img')); }()); -const setLibs = () => { +// eslint-disable-next-line import/prefer-default-export +export const LIBS = (() => { const { hostname, search } = window.location; if (!(hostname.includes('.hlx.') || hostname.includes('local'))) return LIBS; const branch = new URLSearchParams(search).get('milolibs') || 'main'; if (branch === 'local') return 'http://localhost:6456/libs'; return branch.includes('--') ? `https://${branch}.hlx.live/libs` : `https://${branch}--milo--adobecom.hlx.live/libs`; -}; - -const miloLibs = setLibs(); +})(); (function loadStyles() { - const paths = [`${miloLibs}/styles/styles.css`]; + const paths = [`${LIBS}/styles/styles.css`]; if (STYLES) { paths.push(...(Array.isArray(STYLES) ? STYLES : [STYLES])); } @@ -174,7 +172,7 @@ const miloLibs = setLibs(); }()); (async function loadPage() { - const { loadArea, loadLana, setConfig, createTag, getMetadata } = await import(`${miloLibs}/utils/utils.js`); + const { loadArea, loadLana, setConfig, createTag, getMetadata } = await import(`${LIBS}/utils/utils.js`); if (getMetadata('template') === '404') window.SAMPLE_PAGEVIEWS_AT_RATE = 'high'; const metaCta = document.querySelector('meta[name="chat-cta"]'); if (metaCta && !document.querySelector('.chat-cta')) { @@ -185,7 +183,7 @@ const miloLibs = setLibs(); if (lastSection) lastSection.insertAdjacentElement('beforeend', chatDiv); } } - setConfig({ ...CONFIG, miloLibs }); + setConfig({ ...CONFIG, miloLibs: LIBS }); loadLana({ clientId: 'bacom', tags: 'info' }); await loadArea(); diff --git a/templates/featured-story/featured-story.js b/templates/featured-story/featured-story.js index 5a6c596..6e463d0 100644 --- a/templates/featured-story/featured-story.js +++ b/templates/featured-story/featured-story.js @@ -2,9 +2,9 @@ Templates - featured story */ -import { getLibs } from '../../scripts/utils.js'; +import { LIBS } from '../../scripts/scripts.js'; -const { createTag } = await import(`${getLibs()}/utils/utils.js`); +const { createTag } = await import(`${LIBS}/utils/utils.js`); function init() { const i = 1;