UNPKG

@teambit/workspace

Version:
47 lines (44 loc) 1.58 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.PRIORITY_MED = exports.PRIORITY_LOW = exports.PRIORITY_HIGH = void 0; exports.getRootNamespace = getRootNamespace; exports.namespacePriority = namespacePriority; exports.sortItemsByNamespace = sortItemsByNamespace; exports.sortNamespacesAdvanced = sortNamespacesAdvanced; const PRIORITY_HIGH = exports.PRIORITY_HIGH = ['ui', 'pages']; const PRIORITY_MED = exports.PRIORITY_MED = ['design']; const PRIORITY_LOW = exports.PRIORITY_LOW = ['entities', 'provider', 'hooks', 'icons']; function getRootNamespace(ns) { if (!ns) return ''; return ns.split('/')[0]; } function namespacePriority(ns) { const root = getRootNamespace(ns); // internal namespaces (starting with _) go last if (root.startsWith('_')) return 4; if (PRIORITY_HIGH.includes(root)) return 0; if (PRIORITY_MED.includes(root)) return 1; if (PRIORITY_LOW.includes(root)) return 3; return 2; } function sortNamespacesAdvanced(list) { return [...list].sort((a, b) => { const pa = namespacePriority(a); const pb = namespacePriority(b); if (pa !== pb) return pa - pb; return a.localeCompare(b); }); } function sortItemsByNamespace(items) { return [...items].sort((a, b) => { const na = a.component.id.namespace || '/'; const nb = b.component.id.namespace || '/'; const pa = namespacePriority(na); const pb = namespacePriority(nb); if (pa !== pb) return pa - pb; return a.component.id.name.localeCompare(b.component.id.name); }); } //# sourceMappingURL=namespace-sort.js.map