Skip to content
Merged

Cross #253

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions src/cross.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
export interface NumericVersion {
readonly major: number;
readonly minor: number;
readonly patch: number;
}

export function parseNumericVersion(value: string): NumericVersion | null {
const match = /^(\d+)\.(\d+)\.(\d+)(?:[-+].*)?$/.exec(value.trim());

if (!match) return null;

const major = Number(match[1]);
const minor = Number(match[2]);
const patch = Number(match[3]);

if (![major, minor, patch].every(Number.isSafeInteger)) return null;

return { major, minor, patch };
}

export function compareVersions(
left: NumericVersion,
right: NumericVersion,
): number {
if (left.major !== right.major) return left.major - right.major;
if (left.minor !== right.minor) return left.minor - right.minor;
return left.patch - right.patch;
}

export function isAtLeast(
actual: NumericVersion,
minimum: NumericVersion,
): boolean {
return compareVersions(actual, minimum) >= 0;
}
24 changes: 24 additions & 0 deletions src/validate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import type {
ProjectGenerationResult,
ProjectGeneratorInput,
ProjectGeneratorServices,
} from './types.js';

export function orchestrateProjectGeneration(
input: ProjectGeneratorInput,
services: ProjectGeneratorServices,
): ProjectGenerationResult {
const validated = services.validate(input);
const destination = services.planDestination(validated);
const template = services.selectTemplate(validated, destination);
const result = services.generate({
input: validated,
destination,
template,
});

services.install?.(result);
services.initializeGit?.(result);

return result;
}