All files / infrastructure/scripts/src/dev/domain projects.ts

100% Statements 24/24
100% Branches 4/4
100% Functions 13/13
100% Lines 21/21

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45    2x   2x   2x                     2x 20x   2x 18x 18x     2x 11x 17x 16x 9x   20x   2x   2x 8x 40x     2x 5x 11x    
import { titleCase } from "../../shared/domain/layout.ts";
 
export const SCOPE = "@joinery/";
 
const SELF = "@joinery/scripts";
 
const ROOT_ORDER = ["apps", "infrastructure", "packages"];
 
export interface Runnable {
    root: string;
    name: string;
}
 
export type DevProject = Runnable & {
    label: string;
};
 
export const labelFor = (name: string): string =>
    name.replace(SCOPE, "").split("-").map(titleCase).join(" ");
 
const rank = (root: string): number => {
    const position = ROOT_ORDER.indexOf(root);
    return position === -1 ? ROOT_ORDER.length : position;
};
 
export const toProjects = (runnables: Runnable[]): DevProject[] =>
    runnables
        .filter(({ name }) => name !== SELF)
        .map((runnable) => ({ ...runnable, label: labelFor(runnable.name) }))
        .sort((a, b) => rank(a.root) - rank(b.root) || a.label.localeCompare(b.label));
 
const spellings = ({ name, label }: DevProject): string[] => [name, name.replace(SCOPE, ""), label];
 
export const rowFor = (project: DevProject): string => `${project.label} ยท ${project.root}`;
 
export const findProject = (projects: DevProject[], query: string): DevProject | undefined =>
    projects.find((project) =>
        spellings(project).some((spelling) => spelling.toLowerCase() === query.toLowerCase()),
    );
 
export const matches = (project: DevProject, search: string): boolean =>
    [...spellings(project), project.root].some((spelling) =>
        spelling.toLowerCase().includes(search.toLowerCase()),
    );