Skip to content

Commit 34ccb1f

Browse files
committed
chore: make package selector a bit more user friendly
1 parent 8758586 commit 34ccb1f

File tree

1 file changed

+38
-1
lines changed

1 file changed

+38
-1
lines changed

automation/utils/src/monorepo.ts

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,34 @@ export async function copyMpkFiles(packageNames: string[], dest: string): Promis
4343
export async function selectPackage(): Promise<PackageListing> {
4444
const pkgs = await oraPromise(listPackages(["'*'", "!web-widgets"]), "Loading packages...");
4545

46+
// First, get all display names and find maximum length
47+
const displayData = pkgs.map(pkg => {
48+
const [category, folderName] = extractPathInfo(pkg.path);
49+
const displayName = pkg.name.includes("/") ? pkg.name.split("/").pop()! : pkg.name;
50+
const categoryInfo = `[${category}${displayName !== folderName ? "/" + folderName : ""}]`;
51+
52+
return {
53+
displayName,
54+
categoryInfo,
55+
packageName: pkg.name
56+
};
57+
});
58+
59+
// Find maximum display name length for padding
60+
const maxDisplayNameLength = Math.max(...displayData.map(item => item.displayName.length));
61+
4662
const { packageName } = await prompt<{ packageName: string }>({
4763
type: "autocomplete",
4864
name: "packageName",
4965
message: "Please select package",
50-
choices: pkgs.map(pkg => pkg.name)
66+
choices: displayData.map(item => {
67+
// Pad the display name with spaces to align the category info
68+
const paddedName = item.displayName.padEnd(maxDisplayNameLength + 2, " ");
69+
return {
70+
name: `${paddedName}${item.categoryInfo}`,
71+
value: item.packageName
72+
};
73+
})
5174
});
5275

5376
const pkg = pkgs.find(p => p.name === packageName);
@@ -58,3 +81,17 @@ export async function selectPackage(): Promise<PackageListing> {
5881

5982
return pkg;
6083
}
84+
85+
function extractPathInfo(path: string): [string, string] {
86+
const automationMatch = path.match(/automation\/([^\/]+)/);
87+
if (automationMatch) {
88+
return ["automation", automationMatch[1]];
89+
}
90+
91+
const packagesMatch = path.match(/packages\/([^\/]+)\/([^\/]+)/);
92+
if (packagesMatch) {
93+
return [packagesMatch[1], packagesMatch[2]];
94+
}
95+
96+
throw new Error(`Invalid path format: ${path}`);
97+
}

0 commit comments

Comments
 (0)