refactor: 拆分品牌业务类型与页面方案
CI / Static checks (push) Has been cancelled
CI / Production build (push) Has been cancelled
CI / API integration (push) Has been cancelled
CI / Taro builds (acheng-campus-food) (push) Has been cancelled
CI / Taro builds (atelier-solopreneur) (push) Has been cancelled
CI / Taro builds (linjing-editorial) (push) Has been cancelled
CI / Browser regression (push) Has been cancelled
CI / Static checks (push) Has been cancelled
CI / Production build (push) Has been cancelled
CI / API integration (push) Has been cancelled
CI / Taro builds (acheng-campus-food) (push) Has been cancelled
CI / Taro builds (atelier-solopreneur) (push) Has been cancelled
CI / Taro builds (linjing-editorial) (push) Has been cancelled
CI / Browser regression (push) Has been cancelled
This commit is contained in:
1 parent
f02e2cafbb
commit
0d9f4a7d6f
86 files changed
+4111
-1543
No files matched your search
@@ -0,0 +1,60 @@
|
||||
const SEMVER_PATTERN =
|
||||
/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?(?:\+[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$/;
|
||||
const fallbackVersionCollator = new Intl.Collator("en", {
|
||||
numeric: true,
|
||||
sensitivity: "base",
|
||||
});
|
||||
|
||||
type VersionOrderable = {
|
||||
version: string;
|
||||
importedAt?: Date;
|
||||
createdAt?: Date;
|
||||
};
|
||||
|
||||
function comparePrerelease(left: string, right: string) {
|
||||
if (left === right) return 0;
|
||||
if (!left) return 1;
|
||||
if (!right) return -1;
|
||||
const leftParts = left.split(".");
|
||||
const rightParts = right.split(".");
|
||||
for (let index = 0; index < Math.max(leftParts.length, rightParts.length); index += 1) {
|
||||
const leftPart = leftParts[index];
|
||||
const rightPart = rightParts[index];
|
||||
if (leftPart === undefined) return -1;
|
||||
if (rightPart === undefined) return 1;
|
||||
if (leftPart === rightPart) continue;
|
||||
const leftNumeric = /^\d+$/.test(leftPart);
|
||||
const rightNumeric = /^\d+$/.test(rightPart);
|
||||
if (leftNumeric && rightNumeric) return Number(leftPart) - Number(rightPart);
|
||||
if (leftNumeric !== rightNumeric) return leftNumeric ? -1 : 1;
|
||||
return leftPart.localeCompare(rightPart);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
export function compareTemplateVersions(left: string, right: string) {
|
||||
const leftMatch = SEMVER_PATTERN.exec(left);
|
||||
const rightMatch = SEMVER_PATTERN.exec(right);
|
||||
if (!leftMatch || !rightMatch) return fallbackVersionCollator.compare(left, right);
|
||||
for (let index = 1; index <= 3; index += 1) {
|
||||
const difference = Number(leftMatch[index]) - Number(rightMatch[index]);
|
||||
if (difference !== 0) return difference;
|
||||
}
|
||||
return comparePrerelease(leftMatch[4] ?? "", rightMatch[4] ?? "");
|
||||
}
|
||||
|
||||
/** 按 SemVer 从新到旧排序;同版本使用导入和创建时间保证顺序稳定。 */
|
||||
export function compareTemplateVersionOrder(left: VersionOrderable, right: VersionOrderable) {
|
||||
const versionOrder = compareTemplateVersions(right.version, left.version);
|
||||
if (versionOrder !== 0) return versionOrder;
|
||||
const importedOrder = (right.importedAt?.getTime() ?? 0) - (left.importedAt?.getTime() ?? 0);
|
||||
if (importedOrder !== 0) return importedOrder;
|
||||
return (right.createdAt?.getTime() ?? 0) - (left.createdAt?.getTime() ?? 0);
|
||||
}
|
||||
|
||||
export function latestTemplateVersion<T extends VersionOrderable>(versions: readonly T[]) {
|
||||
return versions.reduce<T | undefined>((latest, current) => {
|
||||
if (!latest || compareTemplateVersionOrder(current, latest) < 0) return current;
|
||||
return latest;
|
||||
}, undefined);
|
||||
}
|
||||
Reference in new issue
Block a user