Skip to content

Commit

Permalink
fix(ui-devkit): Correctly handle static asset file paths
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
michaelbromley committed Apr 22, 2020
1 parent 0ba66cb commit 27b0adb
Showing 1 changed file with 3 additions and 10 deletions.
13 changes: 3 additions & 10 deletions packages/ui-devkit/src/compiler/utils.ts
Original file line number Diff line number Diff line change
@@ -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)),
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 27b0adb

Please sign in to comment.