arela
Version:
AI-powered CTO with multi-agent orchestration, code summarization, visual testing (web + mobile) for blazing fast development.
173 lines โข 5.41 kB
JavaScript
/**
* Generate descriptive slice names from file patterns
*/
/**
* Suggest a name for a slice based on its files
*/
export function suggestSliceName(files) {
if (files.length === 0) {
return "feature";
}
// Extract directory names (first component of path)
const dirCounts = new Map();
for (const file of files) {
const parts = file.split("/");
const dir = parts[0];
if (dir && dir !== "." && !dir.startsWith(".")) {
dirCounts.set(dir, (dirCounts.get(dir) || 0) + 1);
}
}
// Get most common directory
let mostCommonDir = "";
let maxCount = 0;
for (const [dir, count] of dirCounts) {
if (count > maxCount) {
maxCount = count;
mostCommonDir = dir;
}
}
// Try common patterns
const commonPatterns = {
auth: "๐ authentication",
user: "๐ค user",
workout: "๐ช workout",
exercise: "๐๏ธ exercise",
nutrition: "๐ฅ nutrition",
meal: "๐ฝ๏ธ meals",
social: "๐ฅ social",
feed: "๐ฐ feed",
friend: "๐ซ friends",
message: "๐ฌ messaging",
chat: "๐ฌ chat",
payment: "๐ณ billing",
billing: "๐ฐ payments",
admin: "โ๏ธ admin",
account: "๐ account",
settings: "โ๏ธ settings",
profile: "๐ค profile",
search: "๐ search",
api: "๐ api",
service: "๐ง service",
util: "๐ ๏ธ utilities",
component: "๐จ components",
layout: "๐ layout",
theme: "๐จ theme",
style: "๐ styling",
test: "๐งช testing",
spec: "๐ specs",
config: "โ๏ธ config",
env: "๐ง environment",
db: "๐พ database",
store: "๐พ storage",
cache: "โก cache",
queue: "๐ฆ queue",
job: "โฐ jobs",
worker: "๐ workers",
hook: "๐ช hooks",
middleware: "๐ middleware",
guard: "๐ก๏ธ guards",
interceptor: "๐ interceptors",
directive: "๐ directives",
filter: "๐งน filters",
pipe: "๐จ pipes",
resolver: "๐ resolvers",
gateway: "๐ช gateway",
controller: "๐ฎ controllers",
handler: "๐ handlers",
listener: "๐ listeners",
event: "๐ข events",
command: "โจ๏ธ commands",
query: "โ queries",
mutation: "โ๏ธ mutations",
subscription: "๐ก subscriptions",
};
// Check for pattern matches in file names
const fileContent = files.join(" ").toLowerCase();
for (const [pattern, name] of Object.entries(commonPatterns)) {
if (fileContent.includes(pattern)) {
return name;
}
}
// Use most common directory if found
if (mostCommonDir && mostCommonDir in commonPatterns) {
return commonPatterns[mostCommonDir];
}
// Fallback to directory name
if (mostCommonDir) {
return formatSliceName(mostCommonDir);
}
return "feature";
}
/**
* Format a slice name from raw input
*/
function formatSliceName(name) {
// Convert snake_case, kebab-case, camelCase to title case
const formatted = name
.replace(/([a-z])([A-Z])/g, "$1 $2") // camelCase
.replace(/[-_]/g, " ") // kebab-case, snake_case
.toLowerCase()
.trim();
return formatted.charAt(0).toUpperCase() + formatted.slice(1);
}
/**
* Get emoji for a feature type
*/
export function getFeatureEmoji(sliceName) {
const emojis = {
"๐ authentication": "๐",
"๐ค user": "๐ค",
"๐ช workout": "๐ช",
"๐๏ธ exercise": "๐๏ธ",
"๐ฅ nutrition": "๐ฅ",
"๐ฝ๏ธ meals": "๐ฝ๏ธ",
"๐ฅ social": "๐ฅ",
"๐ฐ feed": "๐ฐ",
"๐ซ friends": "๐ซ",
"๐ฌ messaging": "๐ฌ",
"๐ฌ chat": "๐ฌ",
"๐ณ billing": "๐ณ",
"๐ฐ payments": "๐ฐ",
"โ๏ธ admin": "โ๏ธ",
"๐ account": "๐",
"โ๏ธ settings": "โ๏ธ",
"๐ค profile": "๐ค",
"๐ search": "๐",
"๐ api": "๐",
"๐ง service": "๐ง",
"๐ ๏ธ utilities": "๐ ๏ธ",
"๐จ components": "๐จ",
"๐ layout": "๐",
"๐จ theme": "๐จ",
"๐ styling": "๐",
"๐งช testing": "๐งช",
"๐ specs": "๐",
"โ๏ธ config": "โ๏ธ",
"๐ง environment": "๐ง",
"๐พ database": "๐พ",
"๐พ storage": "๐พ",
"โก cache": "โก",
"๐ฆ queue": "๐ฆ",
"โฐ jobs": "โฐ",
"๐ workers": "๐",
"๐ช hooks": "๐ช",
"๐ middleware": "๐",
"๐ก๏ธ guards": "๐ก๏ธ",
"๐ interceptors": "๐",
"๐ directives": "๐",
"๐งน filters": "๐งน",
"๐จ pipes": "๐จ",
"๐ resolvers": "๐",
"๐ช gateway": "๐ช",
"๐ฎ controllers": "๐ฎ",
"๐ handlers": "๐",
"๐ listeners": "๐",
"๐ข events": "๐ข",
"โจ๏ธ commands": "โจ๏ธ",
"โ queries": "โ",
"โ๏ธ mutations": "โ๏ธ",
"๐ก subscriptions": "๐ก",
};
return emojis[sliceName] || "โจ";
}
//# sourceMappingURL=slice-namer.js.map