Browse Source

feat(ui-devkit): Export helper function to set brand images

Relates to #391
Michael Bromley 5 years ago
parent
commit
6cde0d8c16

+ 6 - 1
packages/ui-devkit/scaffold/angular.json

@@ -39,7 +39,12 @@
               "src/vendure-ui-config.json",
               "src/theme.min.css",
               "src/assets",
-              "src/i18n-messages"
+              "src/i18n-messages",
+              {
+                "glob": "logo-*.png",
+                "input": "static-assets",
+                "output": "assets"
+              }
             ],
             "styles": [
               "src/global-styles.scss"

+ 45 - 0
packages/ui-devkit/src/compiler/helpers.ts

@@ -0,0 +1,45 @@
+import { BrandingOptions, StaticAssetDefinition, StaticAssetExtension } from './types';
+
+/**
+ * @description
+ * A helper function to simplify the process of setting custom branding images.
+ *
+ * @example
+ * ```TypeScript
+ * compileUiExtensions({
+ *   outputPath: path.join(__dirname, '../admin-ui'),
+ *   extensions: [
+ *     setBranding({
+ *       smallLogoPath: path.join(__dirname, 'images/my-logo-sm.png'),
+ *       largeLogoPath: path.join(__dirname, 'images/my-logo-lg.png'),
+ *       faviconPath: path.join(__dirname, 'images/my-favicon.ico'),
+ *     }),
+ *   ],
+ * });
+ * ```
+ *
+ * @docsCategory UiDevkit
+ * @docsPage helpers
+ */
+export function setBranding(options: BrandingOptions): StaticAssetExtension {
+    const staticAssets: StaticAssetDefinition[] = [];
+    if (options.smallLogoPath) {
+        staticAssets.push({
+            path: options.smallLogoPath,
+            rename: 'logo-75px.png',
+        });
+    }
+    if (options.largeLogoPath) {
+        staticAssets.push({
+            path: options.largeLogoPath,
+            rename: 'logo-300px.png',
+        });
+    }
+    if (options.faviconPath) {
+        staticAssets.push({
+            path: options.faviconPath,
+            rename: 'favicon.ico',
+        });
+    }
+    return { staticAssets };
+}

+ 1 - 0
packages/ui-devkit/src/compiler/index.ts

@@ -1,2 +1,3 @@
 export * from './compile';
+export * from './helpers';
 export * from './types';

+ 6 - 0
packages/ui-devkit/src/compiler/types.ts

@@ -225,3 +225,9 @@ export type Translations = {
         [token: string]: string;
     };
 };
+
+export interface BrandingOptions {
+    smallLogoPath?: string;
+    largeLogoPath?: string;
+    faviconPath?: string;
+}