Skip to content

Commit

Permalink
feat(framework): Support custom dynamic asset paths (#2305)
Browse files Browse the repository at this point in the history
  • Loading branch information
vladitasev authored Oct 7, 2020
1 parent efe8b40 commit ff245fa
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 16 deletions.
2 changes: 2 additions & 0 deletions packages/base/src/AssetRegistry.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { registerI18nBundle } from "./asset-registries/i18n.js";
import { registerCldr, _registerMappingFunction as registerCldrMappingFunction } from "./asset-registries/LocaleData.js";
import { registerThemeProperties } from "./asset-registries/Themes.js";
import { registerAssetPathMappingFunction } from "./util/EffectiveAssetPath.js";

export {
registerCldr,
registerCldrMappingFunction,
registerThemeProperties,
registerI18nBundle,
registerAssetPathMappingFunction,
};
2 changes: 1 addition & 1 deletion packages/base/src/asset-registries/Icons.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { registerIcon, registerCollectionPromise } from "../SVGIconRegistry.js";
import { fetchJsonOnce } from "../util/FetchHelper.js";
import getEffectiveAssetPath from "../util/getEffectiveAssetPath.js";
import { getEffectiveAssetPath } from "../util/EffectiveAssetPath.js";

const registerIconBundle = async (collectionName, bundleData) => {
let resolveFn;
Expand Down
2 changes: 1 addition & 1 deletion packages/base/src/asset-registries/LocaleData.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { fetchJsonOnce } from "../util/FetchHelper.js";
import { getFeature } from "../FeaturesRegistry.js";
import { DEFAULT_LOCALE, SUPPORTED_LOCALES } from "../generated/AssetParameters.js";
import getEffectiveAssetPath from "../util/getEffectiveAssetPath.js";
import { getEffectiveAssetPath } from "../util/EffectiveAssetPath.js";

const resources = new Map();
const cldrData = {};
Expand Down
2 changes: 1 addition & 1 deletion packages/base/src/asset-registries/Themes.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { fetchJsonOnce, fetchTextOnce } from "../util/FetchHelper.js";
import { DEFAULT_THEME } from "../generated/AssetParameters.js";
import getFileExtension from "../util/getFileExtension.js";
import getEffectiveAssetPath from "../util/getEffectiveAssetPath.js";
import { getEffectiveAssetPath } from "../util/EffectiveAssetPath.js";

const themeURLs = new Map();
const themeStyles = new Map();
Expand Down
2 changes: 1 addition & 1 deletion packages/base/src/asset-registries/i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { fetchTextOnce } from "../util/FetchHelper.js";
import normalizeLocale from "../locale/normalizeLocale.js";
import nextFallbackLocale from "../locale/nextFallbackLocale.js";
import { DEFAULT_LANGUAGE } from "../generated/AssetParameters.js";
import getEffectiveAssetPath from "../util/getEffectiveAssetPath.js";
import { getEffectiveAssetPath } from "../util/EffectiveAssetPath.js";
import { getUseDefaultLanguage } from "../config/Language.js";

const bundleData = new Map();
Expand Down
27 changes: 27 additions & 0 deletions packages/base/src/util/EffectiveAssetPath.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { getAssetsPath } from "../config/AssetsPath.js";

let assetPathMappingFn = assetName => assetName;

const getEffectiveAssetPath = assetName => {
if (typeof assetName !== "string") {
return assetName;
}

assetName = assetPathMappingFn(assetName);

const assetsPathPrefix = getAssetsPath();
if (assetsPathPrefix) {
return `${assetsPathPrefix}${assetName}`;
}

return assetName;
};

const registerAssetPathMappingFunction = mappingFn => {
assetPathMappingFn = mappingFn;
};

export {
getEffectiveAssetPath,
registerAssetPathMappingFunction,
};
12 changes: 0 additions & 12 deletions packages/base/src/util/getEffectiveAssetPath.js

This file was deleted.

0 comments on commit ff245fa

Please sign in to comment.