Просмотр исходного кода

fix(ui-devkit): Correctly handle static asset file paths

Previously, passing a the path of a file rather than a dir in the extension `staticAssets` array resulted in an uncaught error. This change fixes it so individual files as well as directories are correctly copied over to the custom admin-ui project. This makes it possible e.g. to specify your own logo images (as in #309) to overwrite the default logo images.
Michael Bromley 5 лет назад
Родитель
Сommit
27b0adbbb7
1 измененных файлов с 3 добавлено и 10 удалено
  1. 3 10
      packages/ui-devkit/src/compiler/utils.ts

+ 3 - 10
packages/ui-devkit/src/compiler/utils.ts

@@ -1,14 +1,12 @@
 /* tslint:disable:no-console */
-import { LanguageCode } from '@vendure/common/lib/generated-types';
 import chalk from 'chalk';
 import { execSync } from 'child_process';
 import { createHash } from 'crypto';
 import * as fs from 'fs-extra';
-import glob from 'glob';
 import * as path from 'path';
 
 import { STATIC_ASSETS_OUTPUT_DIR } from './constants';
-import { AdminUiExtension, Extension, StaticAssetDefinition, Translations } from './types';
+import { AdminUiExtension, Extension, StaticAssetDefinition } from './types';
 
 export const logger = {
     log: (message: string) => console.log(chalk.green(message)),
@@ -50,14 +48,9 @@ export function copyUiDevkit(outputPath: string) {
  */
 export async function copyStaticAsset(outputPath: string, staticAssetDef: StaticAssetDefinition) {
     const staticAssetPath = getStaticAssetPath(staticAssetDef);
-    const stats = fs.statSync(staticAssetPath);
     let assetOutputPath: string;
-    if (stats.isDirectory()) {
-        const assetDirname = path.basename(staticAssetPath);
-        assetOutputPath = path.join(outputPath, STATIC_ASSETS_OUTPUT_DIR, assetDirname);
-    } else {
-        assetOutputPath = path.join(outputPath, STATIC_ASSETS_OUTPUT_DIR);
-    }
+    const assetBasename = path.basename(staticAssetPath);
+    assetOutputPath = path.join(outputPath, STATIC_ASSETS_OUTPUT_DIR, assetBasename);
     fs.copySync(staticAssetPath, assetOutputPath);
     if (typeof staticAssetDef !== 'string') {
         // The asset is being renamed