#!/usr/bin/env node

// src/bin/package/copy-assets-cjs.ts
import chalk2 from "chalk";

// src/lib/initCwd.ts
function INIT_CWD() {
  return process.env.INIT_CWD ?? process.cwd();
}

// src/lib/packageName.ts
import { readFileSync } from "fs";
import path from "path";
function packageName() {
  if (process.env.npm_package_name) {
    return process.env.npm_package_name;
  }
  try {
    const pkgPath = path.join(INIT_CWD(), "package.json");
    const pkg = JSON.parse(readFileSync(pkgPath, "utf8"));
    return pkg.name;
  } catch {
    return void 0;
  }
}

// src/actions/package/copy-assets.ts
import path2 from "path/posix";
import chalk from "chalk";
import cpy from "cpy";
var copyTargetAssets = async (target, name, location) => {
  try {
    const values = await cpy(
      ["**/*.jpg", "**/*.png", "**/*.gif", "**/*.svg", "**/*.webp", "**/*.sass", "**/*.scss", "**/*.gif", "**/*.css"],
      `../dist/${target}`,
      {
        cwd: path2.join(location, "src"),
        flat: false
      }
    );
    if (values.length > 0) {
      console.log(chalk.green(`Copying Assets [${target.toUpperCase()}] - ${name} - ${location}`));
    }
    for (const value of values) {
      console.log(`${value.split("/").pop()} => ./dist/${target}`);
    }
    return 0;
  } catch (ex) {
    const error = ex;
    console.log(`Copy Assets Failed: ${name}: ${error.message}`);
    return 1;
  }
};
var packageCopyAssets = async ({ target }) => {
  const pkg = INIT_CWD();
  const pkgName = packageName() ?? "Unknown";
  switch (target) {
    case "esm": {
      return await copyTargetAssets("esm", pkgName, pkg);
    }
    case "cjs": {
      return await copyTargetAssets("cjs", pkgName, pkg);
    }
    default: {
      return await copyTargetAssets("esm", pkgName, pkg) || await copyTargetAssets("cjs", pkgName, pkg);
    }
  }
};

// src/bin/package/copy-assets-cjs.ts
packageCopyAssets({ target: "cjs" }).then((value) => process.exitCode = value).catch((reason) => {
  console.error(chalk2.red(reason));
  process.exitCode = 1;
});
//# sourceMappingURL=copy-assets-cjs.mjs.map