#!/usr/bin/env node

// src/lib/deleteGlob.ts
import fs from "node:fs";
import { glob } from "glob";
var deleteGlob = (globPath) => {
  const files = glob.sync(globPath);
  for (const file of files) {
    fs.rmSync(file, { recursive: true, force: true });
  }
};

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

// src/lib/packageName.ts
import { readFileSync } from "node:fs";
import path from "node:path";
function packageName() {
  if (process.env.npm_package_name != null && process.env.npm_package_name.length > 0) {
    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/clean-outputs.ts
import path2 from "node:path";
import chalk from "chalk";
var packageCleanOutputs = () => {
  const pkg = INIT_CWD();
  const pkgName = packageName();
  const folders = [path2.join(pkg, "dist"), path2.join(pkg, "build"), path2.join(pkg, "docs")];
  console.log(chalk.green(`Cleaning Outputs [${pkgName}]`));
  for (const folder of folders) {
    deleteGlob(folder);
  }
  return 0;
};

// src/actions/package/clean-typescript.ts
import path3 from "node:path";
import chalk2 from "chalk";
var packageCleanTypescript = () => {
  const pkg = INIT_CWD();
  const pkgName = packageName();
  console.log(chalk2.green(`Cleaning Typescript [${pkgName}]`));
  const files = [path3.join(pkg, "*.tsbuildinfo"), path3.join(pkg, ".tsconfig.*"), path3.join(pkg, ".eslintcache")];
  for (const file of files) {
    deleteGlob(file);
  }
  return 0;
};

// src/actions/package/clean.ts
var packageClean = () => {
  return [packageCleanOutputs(), packageCleanTypescript()].reduce((prev, value) => prev + value, 0);
};

// src/bin/package/clean.ts
try {
  const exitCode = packageClean();
  process.exit(exitCode);
} catch (error) {
  console.error(error);
  process.exit(1);
}
//# sourceMappingURL=clean.mjs.map
