@supernovaio/cli
Version:
Supernova.io Command Line Interface
78 lines (76 loc) • 3.08 kB
JavaScript
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="deccd1c0-a8a9-5a49-8b89-ac98df010ee2")}catch(e){}}();
import { createHash } from "node:crypto";
import fs from "node:fs";
import { globSync } from "glob";
import path from "node:path";
const ignoredDirectories = [
"**/.git/**",
"**/.next/**",
"**/.supernova/**",
"**/build/**",
"**/coverage/**",
"**/dist/**",
"**/node_modules/**",
"**/out/**",
];
export function normalizeExcludePath(excludePath) {
return excludePath.trim().replaceAll("\\", "/").replace(/^\.?\//, "").replace(/\/+$/, "");
}
function isExcluded(relativePath, excludePaths) {
return excludePaths.some(excludePath => relativePath === excludePath || relativePath.startsWith(`${excludePath}/`));
}
function nestedPackageDirs(projectRoot) {
if (!fs.existsSync(path.join(projectRoot, "package.json"))) {
return [];
}
return globSync("**/package.json", {
cwd: projectRoot,
dot: false,
ignore: ignoredDirectories,
nodir: true,
})
.map(packageJsonPath => normalizeExcludePath(path.dirname(packageJsonPath)))
.filter(packageDir => packageDir !== ".");
}
export async function collectFiles(input) {
const explicitExcludePaths = (input.excludePaths ?? [])
.map(excludePath => normalizeExcludePath(excludePath))
.filter(path => path.length > 0);
const packageExcludePaths = input.excludeNestedPackages ? nestedPackageDirs(input.projectRoot) : [];
const excludePaths = [...new Set([...explicitExcludePaths, ...packageExcludePaths])];
const files = globSync(input.pattern, {
absolute: true,
cwd: input.projectRoot,
dot: false,
ignore: ignoredDirectories,
nodir: true,
});
const filtered = excludePaths.length > 0
? files.filter(file => !isExcluded(toRelative(input.projectRoot, file), excludePaths))
: files;
return filtered.sort((a, b) => a.localeCompare(b));
}
export function componentKeyFrom(exportName, componentPath, existing) {
const normalized = exportName
.replaceAll(/([a-z0-9])([A-Z])/g, "$1-$2")
.replaceAll(/[^a-zA-Z0-9]+/g, "-")
.replaceAll(/-{2,}/g, "-")
.replaceAll(/^-|-$/g, "")
.toLowerCase();
if (!existing.has(normalized)) {
existing.add(normalized);
return normalized;
}
const suffix = createHash("sha1").update(componentPath).digest("hex").slice(0, 6);
const key = `${normalized}-${suffix}`;
existing.add(key);
return key;
}
export function toRelative(projectRoot, absolutePath) {
return path.relative(projectRoot, absolutePath).split(path.sep).join("/");
}
export function uniqueSorted(values) {
return [...new Set(values)].sort((a, b) => a.localeCompare(b));
}
//# sourceMappingURL=helpers.js.map
//# debugId=deccd1c0-a8a9-5a49-8b89-ac98df010ee2