@lark-project/cli
Version:
飞书项目插件开发工具
40 lines (39 loc) • 1.44 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.selectDomains = void 0;
/**
* Pick the domain to suggest for `lpm create`, applying the three-tier rule:
* - 0 domains → suggested = null
* - exactly 1 → that domain (uniqueness wins, even with no timestamp)
* - >=2, some timed → newest lastUsedAt
* - >=2, none timed → suggested = null (caller asks the user to pick)
*/
function selectDomains(store) {
const entries = Object.entries(store).map(([domain, profile]) => ({
domain,
lastUsedAt: profile === null || profile === void 0 ? void 0 : profile.lastUsedAt,
}));
entries.sort((a, b) => {
const at = a.lastUsedAt;
const bt = b.lastUsedAt;
if (at !== undefined && bt !== undefined)
return bt - at;
if (at !== undefined)
return -1;
if (bt !== undefined)
return 1;
return a.domain < b.domain ? -1 : a.domain > b.domain ? 1 : 0;
});
let suggested = null;
if (entries.length === 1) {
suggested = entries[0].domain;
}
else if (entries.length >= 2) {
const timed = entries.filter(e => e.lastUsedAt !== undefined);
if (timed.length > 0) {
suggested = timed[0].domain; // entries already sorted newest-first
}
}
return { domains: entries, suggested };
}
exports.selectDomains = selectDomains;