Skip to content
Open
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
14 changes: 11 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@ USAGE:

OPTIONS:
--year <YYYY> Generate wrapped for a specific year (default: current year)
--ytd, -t Allow current-year year-to-date preview before launch
--help, -h Show this help message
--version, -v Show version number

EXAMPLES:
codex-wrapped # Generate current year wrapped
codex-wrapped --year 2025 # Generate 2025 wrapped
codex-wrapped # Generate current year wrapped
codex-wrapped --year 2025 # Generate 2025 wrapped
codex-wrapped --year 2026 --ytd # Year-to-date preview for 2026
`);
}

Expand All @@ -41,6 +43,7 @@ async function main() {
args: process.argv.slice(2),
options: {
year: { type: "string", short: "y" },
ytd: { type: "boolean", short: "t" },
help: { type: "boolean", short: "h" },
version: { type: "boolean", short: "v" },
},
Expand All @@ -62,7 +65,7 @@ async function main() {

const requestedYear = values.year ? parseInt(values.year, 10) : new Date().getFullYear();

const availability = isWrappedAvailable(requestedYear);
const availability = isWrappedAvailable(requestedYear, { allowYTD: Boolean(values.ytd) });
if (!availability.available) {
if (Array.isArray(availability.message)) {
availability.message.forEach((line) => p.log.warn(line));
Expand All @@ -72,6 +75,11 @@ async function main() {
p.cancel();
process.exit(0);
}
if (availability.message && Array.isArray(availability.message)) {
availability.message.forEach((line) => p.log.info(line));
} else if (availability.message) {
p.log.info(availability.message);
}

const dataExists = await checkCodexDataExists();
if (!dataExists) {
Expand Down
15 changes: 13 additions & 2 deletions src/utils/dates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,16 @@ export function getIntensityLevel(count: number, maxCount: number): 0 | 1 | 2 |
return 6;
}

export function isWrappedAvailable(year: number): { available: boolean; message?: string | string[] } {
export function isWrappedAvailable(
year: number,
options: { allowYTD?: boolean } = {}
): { available: boolean; message?: string | string[] } {
const now = new Date();
const currentYear = now.getFullYear();
const currentMonth = now.getMonth() + 1; // 1-12
const currentDay = now.getDate();
const { allowYTD = false } = options;
const decemberLaunchDay = 20;

if (year < currentYear) {
return { available: true };
Expand All @@ -96,7 +101,13 @@ export function isWrappedAvailable(year: number): { available: boolean; message?
};
}

const decemberLaunchDay = 20;
if (allowYTD) {
return {
available: true,
message: `Generating ${year} year-to-date preview. Full wrap unlocks December ${decemberLaunchDay}th.`,
};
}

if (currentMonth < 12 || (currentMonth === 12 && currentDay < decemberLaunchDay)) {
const daysUntil = calculateDaysUntilLaunch(now, decemberLaunchDay);
return {
Expand Down