All files / src/scripts/createProject copyIntegrationTheme.ts

100% Statements 17/17
100% Branches 5/5
100% Functions 6/6
100% Lines 17/17

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 26 27 28 29 30 31 32 33 34 351x 1x 1x 1x 1x   1x 3x 19x 14x 17x       5x     3x 3x 21x 19x   3x   19x                    
import path from 'path';
import { getThemePath, buildFileTargetPath } from '../../utils/helpers';
import fs from 'fs';
import { copyFile } from '@vue-storefront/nuxt-theme/scripts/copyThemeFiles';
import getAllFilesFromDir from '@vue-storefront/nuxt-theme/scripts/getAllFilesFromDir.js';
 
export default async (integration: string, targetPath: string, omitFiles: Array<string> = []): Promise<void> => {
  const copyThemeFiles = (filesDir: string, targetPath: string, chopPhrase: string) => {
    if (fs.statSync(filesDir).isDirectory()) {
      return Promise.all(getAllFilesFromDir(filesDir).map(
        file => copyFile(file, buildFileTargetPath(file, targetPath, chopPhrase))
      ));
    }
 
    return copyFile(filesDir, buildFileTargetPath(filesDir, targetPath, chopPhrase));
  };
 
  const integrationThemePath = getThemePath(`${integration}-theme`);
  const integrationThemeFiles = fs.readdirSync(integrationThemePath)
    .filter(fileName => !omitFiles.includes(fileName))
    .map(directory => path.join(integrationThemePath, directory));
 
  await Promise.all(
    integrationThemeFiles.map(
      absoluteDirectoryPath => copyThemeFiles(
        absoluteDirectoryPath,
        path.isAbsolute(targetPath)
          ? targetPath
          : path.join(__dirname, targetPath),
        integrationThemePath
      )
    )
  );
};