import { resolve } from "path";
import { tmpDir as tmpdir, mkdirp } from "../../internal/util";

export function templatePath(cmd, defaultTemplate) {
  if (cmd.template) {
    return resolve(process.cwd(), cmd.template);
  }

  return defaultTemplate;
}

const defaultOutputDir = resolve(process.cwd(), "./dist");

function outputDir(cmd) {
  if (cmd.output) {
    return resolve(process.cwd(), cmd.output);
  }

  return defaultOutputDir;
}

export async function outputPath(cmd) {
  const outDir = outputDir(cmd);
  const tmpDir = resolve(outDir, "tmp");

  await mkdirp(tmpDir);
  await mkdirp(resolve(outDir, "html"));

  const buildDir = await tmpdir({ dir: tmpDir, prefix: "build-" });

  return [outDir, buildDir];
}

@@ -25,16 +25,50 @@
 %22path%22;%0A
+import %7B isEmpty %7D from %22lodash%22;%0A
 import %7B
@@ -92,16 +92,27 @@
 , mkdirp
+, copyFiles
  %7D from 
@@ -758,12 +758,365 @@
 uildDir%5D;%0A%7D%0A
+%0Aexport async function copyOverrides(overrides, buildDir) %7B%0A  if (!isEmpty(overrides)) %7B%0A    for await (let %5Btarget, source%5D of Object.entries(overrides)) %7B%0A      if (source) %7B%0A        copyOverride(target, source, buildDir);%0A      %7D%0A    %7D%0A  %7D%0A%7D%0A%0Afunction copyOverride(target, source, buildDir) %7B%0A  return copyFiles(source, resolve(buildDir, target));%0A%7D%0A

add copy overrides helper