All files / packages/sds-components/scripts buildAssets.js

0% Statements 0/8
0% Branches 0/2
0% Functions 0/2
0% Lines 0/7

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25                                                 
import * as glob from 'glob';
import path from 'path';
import fs from 'fs-extra';
import { fileURLToPath } from 'url';
 
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
 
const root = path.resolve(__dirname, '../');
const publicDir = path.join(root, 'public/');
 
// Find all image assets and clone to root folder so storybook can load them correctly
const assets = glob.sync(path.resolve(root, 'src/**/*.@(jpeg|jpg|png|webp|svg)'));
 
// Copy images to public directory to make them available to Storybook
if (assets.length > 0) {
  fs.ensureDir(publicDir, (err) => {
    if (err) throw err;
    assets.forEach((asset) => {
      const file = `${path.parse(asset).name}${path.parse(asset).ext}`;
      fs.copySync(asset, path.join(publicDir, file));
    });
  });
}