@alexaegis/nuke
Version:
Nuke stuff
91 lines (90 loc) • 3.68 kB
JavaScript
let _alexaegis_common = require("@alexaegis/common");
let _alexaegis_logging = require("@alexaegis/logging");
let _alexaegis_workspace_tools = require("@alexaegis/workspace-tools");
let globby = require("globby");
let node_fs = require("node:fs");
let node_fs_promises = require("node:fs/promises");
let node_path = require("node:path");
//#region src/functions/nuke.function.options.ts
var DEFAULT_NUKE_LIST = [
".cache",
"node_modules",
"dist",
".turbo",
"coverage",
"package-lock.json",
"pnpm-lock.yaml",
"typedoc",
".svelte-kit"
];
var DEFAULT_NUKE_GLOBS = ["./vite.config.ts.timestamp*", "./vitest.config.ts.timestamp*"];
var normalizeNukeOptions = (options) => {
return {
...(0, _alexaegis_workspace_tools.normalizeCollectWorkspacePackagesOptions)(options),
...(0, _alexaegis_common.normalizeDryOption)(options),
...(0, _alexaegis_logging.normalizeLoggerOption)(options),
skipNodeModules: options?.skipNodeModules ?? false,
nukeList: options?.nukeList ?? DEFAULT_NUKE_LIST,
nukeGlobs: options?.nukeGlobs ?? DEFAULT_NUKE_GLOBS,
nukeMoreGlobs: options?.nukeMoreGlobs ?? [],
nukeMore: options?.nukeMore ?? [],
dontNukeIn: options?.dontNukeIn ?? []
};
};
//#endregion
//#region src/functions/nuke.function.ts
/**
* Removes a bunch of stuff from packages for cleaning.
*/
var nuke = async (rawOptions) => {
const options = normalizeNukeOptions(rawOptions);
const allWorkspacePackages = await (0, _alexaegis_workspace_tools.collectWorkspacePackages)(options);
if (allWorkspacePackages.length === 0) throw new Error("not in a workspace!");
const nukeList = [...options.nukeList, ...options.nukeMore];
const nukeGlobs = [...options.nukeGlobs, ...options.nukeMoreGlobs];
const nonSkippedWorkspacePackages = allWorkspacePackages.filter((workspacePackage) => !options.dontNukeIn.some((skip) => typeof skip === "string" ? skip === workspacePackage.packagePath : skip.test(workspacePackage.packagePath)));
const rootPackage = allWorkspacePackages.find((workspacePackage) => workspacePackage.packageKind === "root");
if (!rootPackage) {
options.logger.error("Not inside a workspace!");
return;
}
const packageFlatNukeTargets = nonSkippedWorkspacePackages.flatMap((workspacePackage) => nukeList.map((toNuke) => (0, node_path.join)(workspacePackage.packagePath, toNuke)));
const packageGlobNukeTargets = await Promise.all(nonSkippedWorkspacePackages.map((packageDirectory) => (0, globby.globby)(nukeGlobs, {
cwd: packageDirectory.packagePath,
dot: true,
followSymbolicLinks: false,
expandDirectories: false
}).then((paths) => paths.map((path) => (0, node_path.join)(packageDirectory.packagePath, path)))));
const everyNukeTarget = [...packageFlatNukeTargets, ...packageGlobNukeTargets.flat()].sort();
const dryRm = (0, _alexaegis_common.dry)(options.dry, node_fs_promises.rm);
await Promise.allSettled(everyNukeTarget.filter((nukeTarget) => (0, node_fs.existsSync)(nukeTarget)).map((nukeTarget) => {
options.logger.warn("obliterating: " + (0, node_path.relative)(rootPackage.packagePath, nukeTarget));
return dryRm(nukeTarget, { recursive: true }).catch(() => false);
}));
};
//#endregion
Object.defineProperty(exports, "DEFAULT_NUKE_GLOBS", {
enumerable: true,
get: function() {
return DEFAULT_NUKE_GLOBS;
}
});
Object.defineProperty(exports, "DEFAULT_NUKE_LIST", {
enumerable: true,
get: function() {
return DEFAULT_NUKE_LIST;
}
});
Object.defineProperty(exports, "normalizeNukeOptions", {
enumerable: true,
get: function() {
return normalizeNukeOptions;
}
});
Object.defineProperty(exports, "nuke", {
enumerable: true,
get: function() {
return nuke;
}
});
//# sourceMappingURL=functions-BbQkbvEM.cjs.map